|
| 1 | +# if-plugin-template |
| 2 | + |
| 3 | +`if-plugin-template` is an environmental impact calculator template which exposes an API for [IF](https://github.com/Green-Software-Foundation/if) to retrieve energy and embodied carbon estimates. |
| 4 | + |
| 5 | +## Implementation |
| 6 | + |
| 7 | +Here can be implementation details of the plugin. For example which API is used, transformations and etc. |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +To run the `<YOUR-CUSTOM-PLUGIN>`, an instance of `PluginInterface` must be created. Then, the plugin's `execute()` method can be called, passing required arguments to it. |
| 12 | + |
| 13 | +This is how you could run the model in Typescript: |
| 14 | + |
| 15 | +```typescript |
| 16 | +async function runPlugin() { |
| 17 | + const newModel = await new MyCustomPlugin().configure(params); |
| 18 | + const usage = await newModel.calculate([ |
| 19 | + { |
| 20 | + timestamp: '2021-01-01T00:00:00Z', |
| 21 | + duration: '15s', |
| 22 | + 'cpu-util': 34, |
| 23 | + }, |
| 24 | + { |
| 25 | + timestamp: '2021-01-01T00:00:15Z', |
| 26 | + duration: '15s', |
| 27 | + 'cpu-util': 12, |
| 28 | + }, |
| 29 | + ]); |
| 30 | + |
| 31 | + console.log(usage); |
| 32 | +} |
| 33 | + |
| 34 | +runPlugin(); |
| 35 | +``` |
| 36 | + |
| 37 | +## Testing model integration |
| 38 | + |
| 39 | +### Using local links |
| 40 | + |
| 41 | +For using locally developed model in `IF Framework` please follow these steps: |
| 42 | + |
| 43 | +1. On the root level of a locally developed model run `npm link`, which will create global package. It uses `package.json` file's `name` field as a package name. Additionally name can be checked by running `npm ls -g --depth=0 --link=true`. |
| 44 | +2. Use the linked model in impl by specifying `name`, `method`, `path` in initialize models section. |
| 45 | + |
| 46 | +```yaml |
| 47 | +name: plugin-demo-link |
| 48 | +description: loads plugin |
| 49 | +tags: null |
| 50 | +initialize: |
| 51 | + plugins: |
| 52 | + my-custom-plugin: |
| 53 | + method: MyCustomPlugin |
| 54 | + path: "<name-field-from-package.json>" |
| 55 | + global-config: |
| 56 | + ... |
| 57 | +... |
| 58 | +``` |
| 59 | + |
| 60 | +### Using directly from Github |
| 61 | + |
| 62 | +You can simply push your model to the public Github repository and pass the path to it in your impl. |
| 63 | +For example, for a model saved in `github.com/my-repo/my-model` you can do the following: |
| 64 | + |
| 65 | +npm install your model: |
| 66 | + |
| 67 | +``` |
| 68 | +npm install -g https://github.com/my-repo/my-model |
| 69 | +``` |
| 70 | + |
| 71 | +Then, in your `impl`, provide the path in the model instantiation. You also need to specify which class the model instantiates. In this case you are using the `PluginInterface`, so you can specify `OutputModel`. |
| 72 | + |
| 73 | +```yaml |
| 74 | +name: plugin-demo-git |
| 75 | +description: loads plugin |
| 76 | +tags: null |
| 77 | +initialize: |
| 78 | + plugins: |
| 79 | + my-custom-plugin: |
| 80 | + method: MyCustomPlugin |
| 81 | + path: https://github.com/my-repo/my-model |
| 82 | + global-config: |
| 83 | + ... |
| 84 | +... |
| 85 | +``` |
| 86 | + |
| 87 | +Now, when you run the `manifest` using the IF CLI, it will load the model automatically. Run using: |
| 88 | + |
| 89 | +```sh |
| 90 | +ie --manifest <path-to-your-impl> --output <path-to-save-output> |
| 91 | +``` |
0 commit comments