@grnsft/if 0.3.3-beta.0 → 0.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.commitlintrc.js +0 -1
- package/.env +5 -0
- package/.lintstagedrc.js +6 -0
- package/README.md +12 -8
- package/Refactor-migration-guide.md +6 -6
- package/coverage/clover.xml +1590 -0
- package/coverage/coverage-final.json +50 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/builtins/coefficient/index.html +116 -0
- package/coverage/lcov-report/builtins/coefficient/index.ts.html +295 -0
- package/coverage/lcov-report/builtins/csv-lookup/index.html +116 -0
- package/coverage/lcov-report/builtins/csv-lookup/index.ts.html +832 -0
- package/coverage/lcov-report/builtins/divide/index.html +116 -0
- package/coverage/lcov-report/builtins/divide/index.ts.html +361 -0
- package/coverage/lcov-report/builtins/exponent/index.html +116 -0
- package/coverage/lcov-report/builtins/exponent/index.ts.html +355 -0
- package/coverage/lcov-report/builtins/export-csv-raw.ts.html +553 -0
- package/coverage/lcov-report/builtins/export-csv.ts.html +433 -0
- package/coverage/lcov-report/builtins/export-log.ts.html +145 -0
- package/coverage/lcov-report/builtins/export-yaml.ts.html +184 -0
- package/coverage/lcov-report/builtins/group-by.ts.html +364 -0
- package/coverage/lcov-report/builtins/index.html +206 -0
- package/coverage/lcov-report/builtins/index.ts.html +130 -0
- package/coverage/lcov-report/builtins/interpolation/index.html +131 -0
- package/coverage/lcov-report/builtins/interpolation/index.ts.html +670 -0
- package/coverage/lcov-report/builtins/interpolation/types.ts.html +100 -0
- package/coverage/lcov-report/builtins/mock-observations/helpers/common-generator.ts.html +181 -0
- package/coverage/lcov-report/builtins/mock-observations/helpers/index.html +131 -0
- package/coverage/lcov-report/builtins/mock-observations/helpers/rand-int-generator.ts.html +295 -0
- package/coverage/lcov-report/builtins/mock-observations/index.html +116 -0
- package/coverage/lcov-report/builtins/mock-observations/index.ts.html +613 -0
- package/coverage/lcov-report/builtins/multiply/index.html +116 -0
- package/coverage/lcov-report/builtins/multiply/index.ts.html +337 -0
- package/coverage/lcov-report/builtins/regex/index.html +116 -0
- package/coverage/lcov-report/builtins/regex/index.ts.html +379 -0
- package/coverage/lcov-report/builtins/sci/config.ts.html +205 -0
- package/coverage/lcov-report/builtins/sci/index.html +116 -0
- package/coverage/lcov-report/builtins/sci/index.ts.html +331 -0
- package/coverage/lcov-report/builtins/sci-embodied/index.html +116 -0
- package/coverage/lcov-report/builtins/sci-embodied/index.ts.html +481 -0
- package/coverage/lcov-report/builtins/shell/index.html +116 -0
- package/coverage/lcov-report/builtins/shell/index.ts.html +283 -0
- package/coverage/lcov-report/builtins/subtract/index.html +116 -0
- package/coverage/lcov-report/builtins/subtract/index.ts.html +373 -0
- package/coverage/lcov-report/builtins/sum/index.html +116 -0
- package/coverage/lcov-report/builtins/sum/index.ts.html +340 -0
- package/coverage/lcov-report/builtins/time-sync.ts.html +1459 -0
- package/coverage/lcov-report/config/config.ts.html +334 -0
- package/coverage/lcov-report/config/index.html +161 -0
- package/coverage/lcov-report/config/index.ts.html +94 -0
- package/coverage/lcov-report/config/params.ts.html +697 -0
- package/coverage/lcov-report/config/strings.ts.html +415 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +386 -0
- package/coverage/lcov-report/lib/aggregate.ts.html +331 -0
- package/coverage/lcov-report/lib/compare.ts.html +283 -0
- package/coverage/lcov-report/lib/compute.ts.html +391 -0
- package/coverage/lcov-report/lib/environment.ts.html +343 -0
- package/coverage/lcov-report/lib/exhaust.ts.html +283 -0
- package/coverage/lcov-report/lib/index.html +221 -0
- package/coverage/lcov-report/lib/initialize.ts.html +388 -0
- package/coverage/lcov-report/lib/load.ts.html +268 -0
- package/coverage/lcov-report/lib/parameterize.ts.html +283 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/types/aggregation.ts.html +94 -0
- package/coverage/lcov-report/types/index.html +146 -0
- package/coverage/lcov-report/types/interface.ts.html +181 -0
- package/coverage/lcov-report/types/parameters.ts.html +106 -0
- package/coverage/lcov-report/util/aggregation-helper.ts.html +286 -0
- package/coverage/lcov-report/util/args.ts.html +508 -0
- package/coverage/lcov-report/util/errors.ts.html +232 -0
- package/coverage/lcov-report/util/helpers.ts.html +613 -0
- package/coverage/lcov-report/util/index.html +266 -0
- package/coverage/lcov-report/util/json.ts.html +115 -0
- package/coverage/lcov-report/util/log-memoize.ts.html +145 -0
- package/coverage/lcov-report/util/logger.ts.html +151 -0
- package/coverage/lcov-report/util/os-checker.ts.html +421 -0
- package/coverage/lcov-report/util/plugin-storage.ts.html +199 -0
- package/coverage/lcov-report/util/validations.ts.html +526 -0
- package/coverage/lcov-report/util/yaml.ts.html +193 -0
- package/coverage/lcov.info +2811 -0
- package/github-processes.md +16 -42
- package/manifests/bugs/aggregation-error-wrong-metric.yml +6 -6
- package/manifests/bugs/azure-importer-ignoring-defaults.yml +3 -3
- package/manifests/bugs/azure-importer-incorrect-calculation.yml +2 -2
- package/manifests/bugs/mock-observations-failure-duration-is-zero.yml +34 -0
- package/manifests/bugs/pipeline-error-uninitialized-plugin.yml +1 -1
- package/manifests/bugs/pipeline-ordering-error.yml +6 -6
- package/manifests/bugs/sci-embodied-missing-resources-total.yml +23 -0
- package/manifests/examples/generics.yml +3 -3
- package/manifests/examples/instance-metadata.yml +36 -0
- package/manifests/examples/mock-cpu-util-to-carbon.yml +3 -3
- package/manifests/examples/nesting.yml +37 -10
- package/manifests/examples/pipeline-teads-sci.yml +17 -9
- package/manifests/examples/pipeline-with-aggregate.yml +24 -9
- package/manifests/examples/pipeline-with-mocks.yml +26 -9
- package/manifests/examples/sci.yml +131 -0
- package/manifests/examples/teads-curve.yml +78 -0
- package/manifests/features/aggregate-failure-inalid-metrics.yml +43 -0
- package/manifests/features/aggregate-failure-missing-metric-in-inputs.yml +43 -0
- package/manifests/integrations/cloud-metadata-divide-boavizta.yml +1 -1
- package/manifests/integrations/mock-obs-group-by-cloud-meta.yml +51 -0
- package/manifests/integrations/mock-obs-groupby.yml +2 -2
- package/manifests/integrations/mock-obs-time-sync.yml +1 -1
- package/manifests/plugins/cloud-metadata/failure-invalid-instance-type.yaml +21 -0
- package/manifests/plugins/cloud-metadata/failure-invalid-vendor.yaml +1 -1
- package/manifests/plugins/cloud-metadata/failure-missing-cloud-vendor.yml +21 -0
- package/manifests/plugins/cloud-metadata/success.yml +1 -1
- package/manifests/plugins/coefficient/failure-invalid-config-input-param.yml +1 -1
- package/manifests/plugins/coefficient/failure-output-param-is-null.yaml +24 -0
- package/manifests/plugins/coefficient/success.yml +1 -1
- package/manifests/plugins/csv-lookup/failure-missing-column.yml +26 -0
- package/manifests/plugins/csv-lookup/failure-missing-output.yml +26 -0
- package/manifests/plugins/csv-lookup/success-renaming.yml +26 -0
- package/manifests/plugins/csv-lookup/success.yml +26 -0
- package/manifests/plugins/divide/failure-denominator-equal-zero.yml +39 -0
- package/manifests/plugins/divide/failure-invalid-config-denominator.yml +1 -1
- package/manifests/plugins/divide/failure-missing-numerator.yml +39 -0
- package/manifests/plugins/divide/success.yml +2 -2
- package/manifests/plugins/groupby/failure-missing-cloud-instance-type.yml +49 -0
- package/manifests/plugins/interpolation/interpolation.yml +24 -0
- package/manifests/plugins/mock-observations/failure-invalid-config-cpu-range.yml +1 -1
- package/manifests/plugins/mock-observations/failure-invalid-memory-utilization-range.yml +34 -0
- package/manifests/plugins/mock-observations/failure-missing-timestamp-from-param.yml +34 -0
- package/manifests/plugins/mock-observations/success.yml +2 -2
- package/manifests/plugins/multiply/failure-input-parameter-is-missing.yml +1 -1
- package/manifests/plugins/multiply/success-with-multiple-inputs.yml +32 -0
- package/manifests/plugins/multiply/success.yml +3 -3
- package/manifests/plugins/regex/failure-missing-input-param.yml +1 -1
- package/manifests/plugins/regex/failure-not-matching-with-regex.yml +24 -0
- package/manifests/plugins/regex/success.yml +2 -2
- package/manifests/plugins/sci/failure-invalid-config-value.yml +2 -3
- package/manifests/plugins/sci/failure-missing-input-param.yml +27 -0
- package/manifests/plugins/sci/success.yml +5 -4
- package/manifests/plugins/{sci-m → sci-embodied}/failure-invalid-default-emission-value.yml +5 -6
- package/manifests/plugins/sci-embodied/failure-missing-expected-lifespan.yml +23 -0
- package/manifests/plugins/{sci-m → sci-embodied}/success.yml +5 -6
- package/manifests/plugins/shell/failure-invalid-command.yml +1 -1
- package/manifests/plugins/shell/success.yml +1 -2
- package/manifests/plugins/sum/failure-missing-input-param.yml +1 -1
- package/manifests/plugins/sum/failure-missing-output-param.yml +28 -0
- package/manifests/plugins/sum/success.yml +1 -1
- package/manifests/plugins/tdp-finder/failure-unsupported-physical-processor.yml +19 -0
- package/manifests/plugins/time-sync/failure-missing-global-config.yml +34 -0
- package/package.json +10 -2
- package/src/__tests__/integration/manifest/sci-e.yaml +23 -0
- package/src/builtins/README.md +5 -5
- package/src/builtins/coefficient/README.md +92 -0
- package/src/builtins/csv-lookup/README.md +142 -0
- package/src/builtins/divide/README.md +95 -0
- package/src/builtins/exponent/README.md +97 -0
- package/src/builtins/interpolation/README.md +168 -0
- package/src/builtins/mock-observations/README.md +97 -0
- package/src/builtins/multiply/README.md +94 -0
- package/src/builtins/regex/README.md +91 -0
- package/src/builtins/sci/README.md +89 -0
- package/src/builtins/sci-embodied/README.md +110 -0
- package/src/builtins/shell/README.md +130 -0
- package/src/builtins/subtract/README.md +94 -0
- package/src/builtins/sum/README.md +91 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Interpolation Plugin
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Interpolation is a way to infer new data points from a previously known set of points.
|
|
6
|
+
This plugin provides the `y` value at a given `x` by interpolating between known points. You provide a set of known `x`s and `y`s and a target `x`, the plugin returns the `y` for your `x`.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
To employ the `Interpolation` plugin, adhere to these steps:
|
|
11
|
+
|
|
12
|
+
1. **Initialize Plugin**: Import the `Interpolation` function and initialize it with global configuration parameters `method`, `x`, `y`, `input-parameter` and `output-parameter`.
|
|
13
|
+
|
|
14
|
+
2. **Execute Plugin**: Invoke the `execute` method of the initialized plugin instance with an array of input parameters. Each input parameter should include a `timestamp`, `duration` and `[input-parameter]` information.
|
|
15
|
+
|
|
16
|
+
3. **Result**: The plugin will return an array of plugin parameters enriched with the calculated average carbon intensity for each input.
|
|
17
|
+
|
|
18
|
+
## Global Config
|
|
19
|
+
|
|
20
|
+
- `method`: specifies the interpolation method for the data. Acceptable values are 'linear', 'spline', or 'polynomial'. The default method is linear. (optional)
|
|
21
|
+
- `x`: array of x points. Numbers should be in ascending order (required).
|
|
22
|
+
- `y`: array of y points. Numbers should be in ascending order (required).
|
|
23
|
+
- `input-parameter`: a string defining the name to use its value to calculate the interpolation. It should match an existing key in the inputs array (required).
|
|
24
|
+
- `output-parameter`: a string defining the name to use to add the result of interpolation with additional calculation (required).
|
|
25
|
+
|
|
26
|
+
`x` and `y` arrays must be equal lengths.
|
|
27
|
+
|
|
28
|
+
## Input Parameters
|
|
29
|
+
|
|
30
|
+
The plugin expects the following input parameters:
|
|
31
|
+
|
|
32
|
+
- `timestamp`: a timestamp for the input (required)
|
|
33
|
+
- `duration`: the amount of time, in seconds, that the input covers. (required)
|
|
34
|
+
- `[input-parameter]` - a field whose name matches the string provided to input-parameter in global config (i.e. if the input-parameter in global config is cpu/utilisation then cpu-utilisation must exist in the input data)
|
|
35
|
+
|
|
36
|
+
## Output
|
|
37
|
+
|
|
38
|
+
The plugin outputs a value `z` that is the result of looking up the `y` value at `x = 'input-parameter'` using the user-defined interpolation method in `kWh` units. `z` is assigned to a field with a name defined by `output-parameter` in the output data.
|
|
39
|
+
|
|
40
|
+
## Error Handling
|
|
41
|
+
|
|
42
|
+
The plugin conducts input validation using the `zod` library and may throw errors if the provided parameters are invalid.
|
|
43
|
+
|
|
44
|
+
## Plugin Algorithm
|
|
45
|
+
|
|
46
|
+
1. **Execution**:
|
|
47
|
+
|
|
48
|
+
- Validate Global config
|
|
49
|
+
|
|
50
|
+
- `method` - validates if the method is one of these methods: `linear`, `spline`, or `polynomial`. If the method isn’t provided, it sets to `linear`.
|
|
51
|
+
- `x` and `y` should be arrays of numbers, the length should be equal, and elements should be ordered in the ascendant order.
|
|
52
|
+
- `input-parameter` - validates if the parameter is string.
|
|
53
|
+
- `output-parameter` - validates if the parameter is string.
|
|
54
|
+
|
|
55
|
+
- Iterate through each input, and do corresponding validation and calculation.
|
|
56
|
+
|
|
57
|
+
- Validate input parameters
|
|
58
|
+
|
|
59
|
+
- `duration` - validate if the duration is a number
|
|
60
|
+
- `timestamp` - should be in string or date format
|
|
61
|
+
- `[input-parameter]` - validates whether the parameter name is included in the input, and if its value should be a number within the range of x points.
|
|
62
|
+
|
|
63
|
+
- Calculation
|
|
64
|
+
|
|
65
|
+
- If the `method` is provided, choose the right way to calculate. For the `linear` and `polynomial` methods, calculate according to their formulas. For spline interpolation, use the npm module `typescript-cubic-spline`.
|
|
66
|
+
|
|
67
|
+
2. **Output**: Output the provided input along with the calculated `cpu/energy`
|
|
68
|
+
|
|
69
|
+
### TypeScript Usage
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const globalConfig = {
|
|
73
|
+
method: 'linear',
|
|
74
|
+
x: [0, 10, 50, 100],
|
|
75
|
+
y: [0.12, 0.32, 0.75, 1.02],
|
|
76
|
+
'input-parameter': 'cpu/utilization'
|
|
77
|
+
'output-parameter': 'cpu/energy'
|
|
78
|
+
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const interpolationPlugin = Interpolation(globalConfig);
|
|
82
|
+
|
|
83
|
+
const inputs = [
|
|
84
|
+
{
|
|
85
|
+
timestamp: '2024-04-16T12:00:00Z',
|
|
86
|
+
duration: 3600,
|
|
87
|
+
'cpu/utilization': 45
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
const results = interpolationPlugin.execute(inputs);
|
|
92
|
+
|
|
93
|
+
console.log(results);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Manifest Usage
|
|
97
|
+
|
|
98
|
+
#### Input
|
|
99
|
+
|
|
100
|
+
```yaml
|
|
101
|
+
name: interpolation-demo
|
|
102
|
+
description: simple demo of interpolation plugin
|
|
103
|
+
tags:
|
|
104
|
+
initialize:
|
|
105
|
+
outputs:
|
|
106
|
+
- yaml
|
|
107
|
+
plugins:
|
|
108
|
+
interpolation:
|
|
109
|
+
method: Interpolation
|
|
110
|
+
path: 'builtin'
|
|
111
|
+
global-config:
|
|
112
|
+
method: linear
|
|
113
|
+
x: [0, 10, 50, 100]
|
|
114
|
+
y: [0.12, 0.32, 0.75, 1.02]
|
|
115
|
+
input-parameter: 'cpu/utilization'
|
|
116
|
+
output-parameter: 'cpu/energy'
|
|
117
|
+
tree:
|
|
118
|
+
children:
|
|
119
|
+
child:
|
|
120
|
+
pipeline:
|
|
121
|
+
- interpolation
|
|
122
|
+
inputs:
|
|
123
|
+
- timestamp: 2023-07-06T00:00
|
|
124
|
+
duration: 3600
|
|
125
|
+
cpu/utilization: 45
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### Output
|
|
129
|
+
|
|
130
|
+
```yaml
|
|
131
|
+
name: interpolation-demo
|
|
132
|
+
description: simple demo of interpolation plugin
|
|
133
|
+
tags:
|
|
134
|
+
initialize:
|
|
135
|
+
outputs:
|
|
136
|
+
- yaml
|
|
137
|
+
plugins:
|
|
138
|
+
interpolation:
|
|
139
|
+
method: Interpolation
|
|
140
|
+
path: 'builtin'
|
|
141
|
+
global-config:
|
|
142
|
+
method: linear
|
|
143
|
+
x: [0, 10, 50, 100]
|
|
144
|
+
y: [0.12, 0.32, 0.75, 1.02]
|
|
145
|
+
input-parameter: 'cpu/utilization'
|
|
146
|
+
output-parameter: 'cpu/energy'
|
|
147
|
+
tree:
|
|
148
|
+
children:
|
|
149
|
+
child:
|
|
150
|
+
pipeline:
|
|
151
|
+
- interpolation
|
|
152
|
+
inputs:
|
|
153
|
+
- timestamp: 2023-07-06T00:00
|
|
154
|
+
duration: 3600
|
|
155
|
+
cpu/utilization: 45
|
|
156
|
+
outputs:
|
|
157
|
+
- timestamp: 2023-07-06T00:00
|
|
158
|
+
duration: 3600
|
|
159
|
+
cpu/utilization: 45
|
|
160
|
+
cpu/energy: 0.00069625
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
You can execute this by passing it to `ie`. Run the impact using the following command from the project root:
|
|
164
|
+
|
|
165
|
+
```sh
|
|
166
|
+
npm i -g @grnsft/if
|
|
167
|
+
ie --manifest ./manifests/examples/interpolation.yml --output ./manifests/outputs/interpolation.yml
|
|
168
|
+
```
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Mock Observations Plugin
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
A plugin for mocking observations (inputs) for testing and demo purposes
|
|
6
|
+
|
|
7
|
+
## Scope
|
|
8
|
+
|
|
9
|
+
The mode currently mocks 2 types of observation data:
|
|
10
|
+
|
|
11
|
+
- Common key-value pairs, that are generated statically and are the same for each generated observation/input (see 'helpers/CommonGenerator.ts')
|
|
12
|
+
- Randomly generated integer values for predefined keys (see 'helpers/RandIntGenerator.ts')
|
|
13
|
+
|
|
14
|
+
### Plugin global config
|
|
15
|
+
|
|
16
|
+
- `timestamp-from`, `timestamp-to` and `duration` define time buckets for which to generate observations.
|
|
17
|
+
- `generators` define which fields to generate for each observation
|
|
18
|
+
- `components` define the components for which to generate observations. The observations generated according to `timestamp-from`, `timestamp-to`, `duration` and `generators` will be duplicated for each component.
|
|
19
|
+
|
|
20
|
+
### Authentication
|
|
21
|
+
|
|
22
|
+
N/A
|
|
23
|
+
|
|
24
|
+
### Inputs
|
|
25
|
+
|
|
26
|
+
The plugin's `global-config` section in the manifest file determines its behaviour.
|
|
27
|
+
'inputs' section is ignored.
|
|
28
|
+
|
|
29
|
+
### Typescript Usage
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const mockObservations = MockObservations({
|
|
33
|
+
'timestamp-from': '2023-07-06T00:00',
|
|
34
|
+
'timestamp-to': '2023-07-06T00:10',
|
|
35
|
+
duration: 60,
|
|
36
|
+
components: {
|
|
37
|
+
'instance-type': 'A1',
|
|
38
|
+
},
|
|
39
|
+
generators: {
|
|
40
|
+
common: {
|
|
41
|
+
region: 'uk-west',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const result = await mockObservations.execute([]);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### manifest Example
|
|
49
|
+
|
|
50
|
+
IF users will typically call the plugin as part of a pipeline defined in a `manifest` file. In this case, instantiating the plugin is handled by `ie` and does not have to be done explicitly by the user. The following is an example `manifest` that calls `mock-observation`:
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
name: mock-observation-demo
|
|
54
|
+
description: example invoking mock-observation plugin
|
|
55
|
+
tags:
|
|
56
|
+
initialize:
|
|
57
|
+
outputs:
|
|
58
|
+
- yaml
|
|
59
|
+
plugins:
|
|
60
|
+
mock-observations:
|
|
61
|
+
kind: plugin
|
|
62
|
+
method: MockObservations
|
|
63
|
+
path: 'builtin'
|
|
64
|
+
global-config:
|
|
65
|
+
timestamp-from: 2023-07-06T00:00
|
|
66
|
+
timestamp-to: 2023-07-06T00:10
|
|
67
|
+
duration: 60
|
|
68
|
+
components:
|
|
69
|
+
- instance-type: A1
|
|
70
|
+
- instance-type: B1
|
|
71
|
+
generators:
|
|
72
|
+
common:
|
|
73
|
+
region: uk-west
|
|
74
|
+
common-key: common-val
|
|
75
|
+
randint:
|
|
76
|
+
cpu/utilization:
|
|
77
|
+
min: 1
|
|
78
|
+
max: 99
|
|
79
|
+
memory/utilization:
|
|
80
|
+
min: 1
|
|
81
|
+
max: 99
|
|
82
|
+
tree:
|
|
83
|
+
children:
|
|
84
|
+
child:
|
|
85
|
+
pipeline:
|
|
86
|
+
- mock-observations
|
|
87
|
+
inputs:
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
You can run this example `manifest` by saving it as `manifests/plugins/mock-observation.yml` and executing the following command from the project root:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
npm i -g @grnsft/if
|
|
94
|
+
ie --manifest ./examples/manifests/test/mock-observation.yml --output ./examples/outputs/mock-observation
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The results will be saved to a new `yaml` file in `./examples/outputs`.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Multiply
|
|
2
|
+
|
|
3
|
+
`multiply` is a generic plugin for multiplying two or more values in an `input` array.
|
|
4
|
+
|
|
5
|
+
You provide the names of the values you want to multiply, and a name to use to append the product to the output array.
|
|
6
|
+
|
|
7
|
+
For example, you could multiply `cpu/energy` and `network/energy` and name the result `energy-product`. `energy-product` would then be added to every observation in your input array as the product of `cpu/energy` and `network/energy`.
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
### Plugin config
|
|
12
|
+
|
|
13
|
+
Two parameters are required in global config: `input-parameters` and `output-parameter`.
|
|
14
|
+
|
|
15
|
+
`input-parameters`: an array of strings. Each string should match an existing key in the `inputs` array
|
|
16
|
+
`output-parameter`: a string defining the name to use to add the product of the input parameters to the output array.
|
|
17
|
+
|
|
18
|
+
### Inputs
|
|
19
|
+
|
|
20
|
+
All of `input-parameters` must be available in the input array.
|
|
21
|
+
|
|
22
|
+
## Returns
|
|
23
|
+
|
|
24
|
+
- `output-parameter`: the product of all `input-parameters` with the parameter name defined by `output-parameter` in global config.
|
|
25
|
+
|
|
26
|
+
## Calculation
|
|
27
|
+
|
|
28
|
+
```pseudocode
|
|
29
|
+
output = input0 * input1 * input2 ... inputN
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Implementation
|
|
33
|
+
|
|
34
|
+
To run the plugin, you must first create an instance of `Multiply`. Then, you can call `execute()`.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import {Multiply} from 'builtins';
|
|
38
|
+
|
|
39
|
+
const config = {
|
|
40
|
+
inputParameters: ['cpu/energy', 'network/energy'],
|
|
41
|
+
outputParameter: 'energy-product',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const mult = Multiply(config);
|
|
45
|
+
const result = await mult.execute([
|
|
46
|
+
{
|
|
47
|
+
duration: 3600,
|
|
48
|
+
timestamp: '2021-01-01T00:00:00Z',
|
|
49
|
+
'cpu/energy': 0.001,
|
|
50
|
+
'memory/energy': 0.0005,
|
|
51
|
+
},
|
|
52
|
+
]);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Example manifest
|
|
56
|
+
|
|
57
|
+
IF users will typically call the plugin as part of a pipeline defined in a manifest file. In this case, instantiating the plugin is handled by `ie` and does not have to be done explicitly by the user. The following is an example manifest that calls `multiply`:
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
name: multiply-demo
|
|
61
|
+
description:
|
|
62
|
+
tags:
|
|
63
|
+
initialize:
|
|
64
|
+
outputs:
|
|
65
|
+
- yaml
|
|
66
|
+
plugins:
|
|
67
|
+
multiply:
|
|
68
|
+
method: Multiply
|
|
69
|
+
path: 'builtin'
|
|
70
|
+
global-config:
|
|
71
|
+
input-parameters: ['cpu/energy', 'network/energy']
|
|
72
|
+
output-parameter: 'energy-product'
|
|
73
|
+
tree:
|
|
74
|
+
children:
|
|
75
|
+
child:
|
|
76
|
+
pipeline:
|
|
77
|
+
- multiply
|
|
78
|
+
config:
|
|
79
|
+
multiply:
|
|
80
|
+
inputs:
|
|
81
|
+
- timestamp: 2023-08-06T00:00
|
|
82
|
+
duration: 3600
|
|
83
|
+
cpu/energy: 0.001
|
|
84
|
+
network/energy: 0.001
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
You can run this example by saving it as `./examples/manifests/test/multiply.yml` and executing the following command from the project root:
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
npm i -g @grnsft/if
|
|
91
|
+
ie --manifest ./examples/manifests/test/multiply.yml --output ./examples/outputs/multiply.yml
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The results will be saved to a new `yaml` file in `./examples/outputs`
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Regex
|
|
2
|
+
|
|
3
|
+
`regex` is a generic plugin to match part of one string in an `input` and extract it into an output.
|
|
4
|
+
|
|
5
|
+
You provide the name of the value you want to match, and a name to use to add the regex to the output array.
|
|
6
|
+
|
|
7
|
+
For example, `boavizta-cpu` need `cpu/name` to work, however `cloud-metadata` returns `physical-processor` which usually contains a long string of processors that the instance could be separated by `,`, like so:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
Intel® Xeon® Platinum 8272CL,Intel® Xeon® 8171M 2.1 GHz,Intel® Xeon® E5-2673 v4 2.3 GHz,Intel® Xeon® E5-2673 v3 2.4 GHz
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Parameters
|
|
14
|
+
|
|
15
|
+
### Plugin config
|
|
16
|
+
|
|
17
|
+
- `parameter` - a parameter by a specific configured string
|
|
18
|
+
- `match` - a regex by which needs to match the `parameter`
|
|
19
|
+
- `output` - output parameter name in the input
|
|
20
|
+
|
|
21
|
+
### Inputs
|
|
22
|
+
|
|
23
|
+
- `parameter` - as input parameter, must be available in the input array
|
|
24
|
+
|
|
25
|
+
## Returns
|
|
26
|
+
|
|
27
|
+
- `output`: the first match of `parameter` with the parameter name with `match` defined in global config.
|
|
28
|
+
|
|
29
|
+
## Implementation
|
|
30
|
+
|
|
31
|
+
To run the plugin, you must first create an instance of `Regex`. Then, you can call `execute()`.
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
|
|
35
|
+
const globalConfig = {
|
|
36
|
+
parameter: 'physical-processor',
|
|
37
|
+
match: '^[^,]+',
|
|
38
|
+
output: 'cpu/name',
|
|
39
|
+
};
|
|
40
|
+
const regex = Regex(globalConfig);
|
|
41
|
+
|
|
42
|
+
const input = [
|
|
43
|
+
{
|
|
44
|
+
timestamp: '2021-01-01T00:00:00Z',
|
|
45
|
+
duration: 3600,
|
|
46
|
+
'physical-processor':
|
|
47
|
+
'Intel® Xeon® Platinum 8272CL,Intel® Xeon® 8171M 2.1 GHz,Intel® Xeon® E5-2673 v4 2.3 GHz,Intel® Xeon® E5-2673 v3 2.4 GHz',
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Example manifest
|
|
53
|
+
|
|
54
|
+
IF users will typically call the plugin as part of a pipeline defined in a manifest file. In this case, instantiating the plugin is handled by `if` and does not have to be done explicitly by the user. The following is an example manifest that calls `regex`:
|
|
55
|
+
|
|
56
|
+
```yaml
|
|
57
|
+
name: regex-demo
|
|
58
|
+
description:
|
|
59
|
+
tags:
|
|
60
|
+
initialize:
|
|
61
|
+
outputs:
|
|
62
|
+
- yaml
|
|
63
|
+
plugins:
|
|
64
|
+
regex:
|
|
65
|
+
method: Regex
|
|
66
|
+
path: 'builtin'
|
|
67
|
+
global-config:
|
|
68
|
+
parameter: physical-processor
|
|
69
|
+
match: ^[^,]+
|
|
70
|
+
output: cpu/name
|
|
71
|
+
tree:
|
|
72
|
+
children:
|
|
73
|
+
child:
|
|
74
|
+
pipeline:
|
|
75
|
+
- regex
|
|
76
|
+
config:
|
|
77
|
+
regex:
|
|
78
|
+
inputs:
|
|
79
|
+
- timestamp: 2023-08-06T00:00
|
|
80
|
+
duration: 3600
|
|
81
|
+
physical-processor: Intel® Xeon® Platinum 8272CL,Intel® Xeon® 8171M 2.1 GHz,Intel® Xeon® E5-2673 v4 2.3 GHz,Intel® Xeon® E5-2673 v3 2.4 GHz
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
You can run this example by saving it as `manifests/plugins/regex.yml` and executing the following command from the project root:
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
npm i -g @grnsft/if
|
|
88
|
+
if --manifest manifests/examples/regex.yml --output manifests/outputs/regex.yml
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The results will be saved to a new `yaml` file in `manifests/outputs`.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# SCI (software carbon intensity)
|
|
2
|
+
|
|
3
|
+
[SCI](https://sci-guide.greensoftware.foundation/) represents the amount of carbon emitted per [functional unit](https://sci-guide.greensoftware.foundation/R/).
|
|
4
|
+
|
|
5
|
+
## Parameters
|
|
6
|
+
|
|
7
|
+
### Plugin global config
|
|
8
|
+
|
|
9
|
+
- `functional-unit`: the name of the functional unit in which to express the carbon impact (required)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Inputs
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
- `carbon`: total carbon in gCO2eq (required)
|
|
16
|
+
- `functional-unit`: whatever `functional-unit` you define in global config also has to be present in each input, for example if you provide `functional-unit: requests` in global config, `requests` must be present in your input data.
|
|
17
|
+
|
|
18
|
+
## Returns
|
|
19
|
+
|
|
20
|
+
- `sci`: carbon expressed in terms of the given functional unit
|
|
21
|
+
|
|
22
|
+
## Calculation
|
|
23
|
+
|
|
24
|
+
SCI is calculated as:
|
|
25
|
+
|
|
26
|
+
```pseudocode
|
|
27
|
+
sci = carbon / functional unit
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## IF Implementation
|
|
32
|
+
|
|
33
|
+
To run the plugin, you must first create an instance of `Sci`. Then, you can call `execute()` to return `sci`.
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import {Sci} from 'builtins';
|
|
37
|
+
|
|
38
|
+
const sci = Sci({'functional-unit': 'requests'});
|
|
39
|
+
const results = await sci.execute(
|
|
40
|
+
[
|
|
41
|
+
{
|
|
42
|
+
'carbon': 5'
|
|
43
|
+
duration: 1,
|
|
44
|
+
requests: 100,
|
|
45
|
+
},
|
|
46
|
+
]
|
|
47
|
+
);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Example manifest
|
|
51
|
+
|
|
52
|
+
IF users will typically call the plugin as part of a pipeline defined in a `manifest` file. In this case, instantiating the plugin is handled by `ie` and does not have to be done explicitly by the user.
|
|
53
|
+
|
|
54
|
+
The following is an example `manifest` that calls `sci`:
|
|
55
|
+
|
|
56
|
+
```yaml
|
|
57
|
+
name: sci-demo
|
|
58
|
+
description: example invoking sci plugin
|
|
59
|
+
tags:
|
|
60
|
+
initialize:
|
|
61
|
+
outputs:
|
|
62
|
+
- yaml
|
|
63
|
+
plugins:
|
|
64
|
+
sci:
|
|
65
|
+
method: Sci
|
|
66
|
+
path: 'builtin'
|
|
67
|
+
global-config:
|
|
68
|
+
functional-unit: 'requests'
|
|
69
|
+
tree:
|
|
70
|
+
children:
|
|
71
|
+
child:
|
|
72
|
+
pipeline:
|
|
73
|
+
- sci
|
|
74
|
+
config:
|
|
75
|
+
inputs:
|
|
76
|
+
- timestamp: 2023-07-06T00:00
|
|
77
|
+
carbon: 5
|
|
78
|
+
duration: 1
|
|
79
|
+
requests: 100
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
You can run this example `manifest` by saving it as `./manifests/plugins/sci.yml` and executing the following command from the project root:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
npm i -g @grnsft/if
|
|
86
|
+
ie --manifest manifests/plugins/sci.yml --output manifests/outputs/sci.yml
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The results will be saved to a new `yaml` file.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# SCI-Embodied
|
|
2
|
+
|
|
3
|
+
Software systems cause emissions through the hardware that they operate on, both through the energy that the physical hardware consumes and the emissions associated with manufacturing the hardware. Embodied carbon refers to the carbon emitted during the manufacture and eventual disposal of a component. It is added to the operational carbon (carbon emitted when a component is used) to give an overall SCI score.
|
|
4
|
+
|
|
5
|
+
Read more on [embodied carbon](https://github.com/Green-Software-Foundation/sci/blob/main/Software_Carbon_Intensity/Software_Carbon_Intensity_Specification.md#embodied-emissions)
|
|
6
|
+
|
|
7
|
+
## Parameters
|
|
8
|
+
|
|
9
|
+
### Plugin config
|
|
10
|
+
|
|
11
|
+
Not Needed
|
|
12
|
+
|
|
13
|
+
### Inputs
|
|
14
|
+
|
|
15
|
+
- `device/emissions-embodied`: the sum of Life Cycle Assessment (LCA) emissions for the component
|
|
16
|
+
- `device/expected-lifespan`: the length of time, in seconds, between a component's manufacture and its disposal
|
|
17
|
+
- `resources-reserved`: the number of resources reserved for use by the software
|
|
18
|
+
- `resources-total`: the total number of resources available
|
|
19
|
+
- `duration`: the amount of time covered by an observation, in this context it is used as the share of the total life span of the hardware reserved for use by an application, in seconds.
|
|
20
|
+
|
|
21
|
+
> Note that if you have a plugin pipeline that adds `vcpus-allocated` and `vcpus-total` to each observation, such as the `cloud-metadata` plugin, those values will be used **in preference** to the given `resources-reserved` and `resources-total` fields.
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
- `carbon-embodied`: the carbon emitted in manufacturing and disposing of a component, in gCO2eq
|
|
26
|
+
|
|
27
|
+
## Calculation
|
|
28
|
+
|
|
29
|
+
To calculate the embodied carbon, `m` for a software application, use the equation:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
m = te * ts * rs
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Where:
|
|
36
|
+
|
|
37
|
+
- `device/emissions-embodied` = Total embodied emissions; the sum of Life Cycle Assessment (LCA) emissions for the component.
|
|
38
|
+
|
|
39
|
+
- `timeShare` = Time-share; the share of the total life span of the hardware reserved for use by an application.
|
|
40
|
+
|
|
41
|
+
- `timeShare` is calculated as `duration/'device/expected-lifespan'`, where:
|
|
42
|
+
- `duration` = the length of time the hardware is reserved for use by the software.
|
|
43
|
+
- `device/expected-lifespan` = Expected lifespan: the length of time, in seconds, between a component's manufacture and its disposal.
|
|
44
|
+
|
|
45
|
+
- `resourceShare` = Resource-share; the share of the total available resources of the hardware reserved for use by an application.
|
|
46
|
+
- `resourceShare` is calculated as `resources-reserved/resources-total`, where:
|
|
47
|
+
- `resources-reserved` = Resources reserved; the number of resources reserved for use by the software.
|
|
48
|
+
- `resources-total` = Total Resources; the total number of resources available.
|
|
49
|
+
|
|
50
|
+
## Implementation
|
|
51
|
+
|
|
52
|
+
IF implements the plugin based on the logic described above. To run the plugin, you must first create an instance of `SciEmbodied`. Then, you can call `execute()` to return `m`.
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
The following snippet demonstrates how to call the `sci-embodied` plugin from Typescript.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import {SciEmbodied} from 'builtins';
|
|
60
|
+
|
|
61
|
+
const sciEmbodied = SciEmbodied();
|
|
62
|
+
const results = await sciEmbodied.execute([
|
|
63
|
+
{
|
|
64
|
+
'device/emissions-embodied': 200, // in gCO2e for total resource units
|
|
65
|
+
duration: 60 * 60 * 24 * 30, // time reserved in seconds, can point to another field "duration"
|
|
66
|
+
'device/expected-lifespan': 60 * 60 * 24 * 365 * 4, // lifespan in seconds (4 years)
|
|
67
|
+
'resources-reserved': 1, // resource units reserved / used
|
|
68
|
+
'resources-total': 1, // total resource units available
|
|
69
|
+
},
|
|
70
|
+
]);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Example manifest
|
|
74
|
+
|
|
75
|
+
IF users will typically call the plugin as part of a pipeline defined in a `manifest` file. In this case, instantiating the plugin is handled by `ie` and does not have to be done explicitly by the user. The following is an example `manifest` that calls `sci-embodied`:
|
|
76
|
+
|
|
77
|
+
```yaml
|
|
78
|
+
name: sci-embodied
|
|
79
|
+
description: simple demo invoking sci-embodied
|
|
80
|
+
tags:
|
|
81
|
+
initialize:
|
|
82
|
+
outputs:
|
|
83
|
+
- yaml
|
|
84
|
+
plugins:
|
|
85
|
+
sci-embodied:
|
|
86
|
+
method: SciEmbodied
|
|
87
|
+
path: 'builtins'
|
|
88
|
+
tree:
|
|
89
|
+
children:
|
|
90
|
+
child:
|
|
91
|
+
pipeline:
|
|
92
|
+
- sci-embodied # duration & config -> embodied
|
|
93
|
+
defaults:
|
|
94
|
+
device/emissions-embodied: 1533.120 # gCO2eq
|
|
95
|
+
device/expected-lifespan: 3 # 3 years in seconds
|
|
96
|
+
resources-reserved: 1
|
|
97
|
+
resources-total: 8
|
|
98
|
+
inputs:
|
|
99
|
+
- timestamp: 2023-07-06T00:00
|
|
100
|
+
duration: 3600
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
You can run this example `manifest` by executing the following command from the project root:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
npm i -g @grnsft/if
|
|
107
|
+
ie --manifest manifests/plugins/sci-embodied.yml --output manifests/outputs/sci-embodied.yml
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
The results will be saved to a new `yaml` file in `./examples/outputs`.
|