@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.
Files changed (164) hide show
  1. package/.commitlintrc.js +0 -1
  2. package/.env +5 -0
  3. package/.lintstagedrc.js +6 -0
  4. package/README.md +12 -8
  5. package/Refactor-migration-guide.md +6 -6
  6. package/coverage/clover.xml +1590 -0
  7. package/coverage/coverage-final.json +50 -0
  8. package/coverage/lcov-report/base.css +224 -0
  9. package/coverage/lcov-report/block-navigation.js +87 -0
  10. package/coverage/lcov-report/builtins/coefficient/index.html +116 -0
  11. package/coverage/lcov-report/builtins/coefficient/index.ts.html +295 -0
  12. package/coverage/lcov-report/builtins/csv-lookup/index.html +116 -0
  13. package/coverage/lcov-report/builtins/csv-lookup/index.ts.html +832 -0
  14. package/coverage/lcov-report/builtins/divide/index.html +116 -0
  15. package/coverage/lcov-report/builtins/divide/index.ts.html +361 -0
  16. package/coverage/lcov-report/builtins/exponent/index.html +116 -0
  17. package/coverage/lcov-report/builtins/exponent/index.ts.html +355 -0
  18. package/coverage/lcov-report/builtins/export-csv-raw.ts.html +553 -0
  19. package/coverage/lcov-report/builtins/export-csv.ts.html +433 -0
  20. package/coverage/lcov-report/builtins/export-log.ts.html +145 -0
  21. package/coverage/lcov-report/builtins/export-yaml.ts.html +184 -0
  22. package/coverage/lcov-report/builtins/group-by.ts.html +364 -0
  23. package/coverage/lcov-report/builtins/index.html +206 -0
  24. package/coverage/lcov-report/builtins/index.ts.html +130 -0
  25. package/coverage/lcov-report/builtins/interpolation/index.html +131 -0
  26. package/coverage/lcov-report/builtins/interpolation/index.ts.html +670 -0
  27. package/coverage/lcov-report/builtins/interpolation/types.ts.html +100 -0
  28. package/coverage/lcov-report/builtins/mock-observations/helpers/common-generator.ts.html +181 -0
  29. package/coverage/lcov-report/builtins/mock-observations/helpers/index.html +131 -0
  30. package/coverage/lcov-report/builtins/mock-observations/helpers/rand-int-generator.ts.html +295 -0
  31. package/coverage/lcov-report/builtins/mock-observations/index.html +116 -0
  32. package/coverage/lcov-report/builtins/mock-observations/index.ts.html +613 -0
  33. package/coverage/lcov-report/builtins/multiply/index.html +116 -0
  34. package/coverage/lcov-report/builtins/multiply/index.ts.html +337 -0
  35. package/coverage/lcov-report/builtins/regex/index.html +116 -0
  36. package/coverage/lcov-report/builtins/regex/index.ts.html +379 -0
  37. package/coverage/lcov-report/builtins/sci/config.ts.html +205 -0
  38. package/coverage/lcov-report/builtins/sci/index.html +116 -0
  39. package/coverage/lcov-report/builtins/sci/index.ts.html +331 -0
  40. package/coverage/lcov-report/builtins/sci-embodied/index.html +116 -0
  41. package/coverage/lcov-report/builtins/sci-embodied/index.ts.html +481 -0
  42. package/coverage/lcov-report/builtins/shell/index.html +116 -0
  43. package/coverage/lcov-report/builtins/shell/index.ts.html +283 -0
  44. package/coverage/lcov-report/builtins/subtract/index.html +116 -0
  45. package/coverage/lcov-report/builtins/subtract/index.ts.html +373 -0
  46. package/coverage/lcov-report/builtins/sum/index.html +116 -0
  47. package/coverage/lcov-report/builtins/sum/index.ts.html +340 -0
  48. package/coverage/lcov-report/builtins/time-sync.ts.html +1459 -0
  49. package/coverage/lcov-report/config/config.ts.html +334 -0
  50. package/coverage/lcov-report/config/index.html +161 -0
  51. package/coverage/lcov-report/config/index.ts.html +94 -0
  52. package/coverage/lcov-report/config/params.ts.html +697 -0
  53. package/coverage/lcov-report/config/strings.ts.html +415 -0
  54. package/coverage/lcov-report/favicon.png +0 -0
  55. package/coverage/lcov-report/index.html +386 -0
  56. package/coverage/lcov-report/lib/aggregate.ts.html +331 -0
  57. package/coverage/lcov-report/lib/compare.ts.html +283 -0
  58. package/coverage/lcov-report/lib/compute.ts.html +391 -0
  59. package/coverage/lcov-report/lib/environment.ts.html +343 -0
  60. package/coverage/lcov-report/lib/exhaust.ts.html +283 -0
  61. package/coverage/lcov-report/lib/index.html +221 -0
  62. package/coverage/lcov-report/lib/initialize.ts.html +388 -0
  63. package/coverage/lcov-report/lib/load.ts.html +268 -0
  64. package/coverage/lcov-report/lib/parameterize.ts.html +283 -0
  65. package/coverage/lcov-report/prettify.css +1 -0
  66. package/coverage/lcov-report/prettify.js +2 -0
  67. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  68. package/coverage/lcov-report/sorter.js +196 -0
  69. package/coverage/lcov-report/types/aggregation.ts.html +94 -0
  70. package/coverage/lcov-report/types/index.html +146 -0
  71. package/coverage/lcov-report/types/interface.ts.html +181 -0
  72. package/coverage/lcov-report/types/parameters.ts.html +106 -0
  73. package/coverage/lcov-report/util/aggregation-helper.ts.html +286 -0
  74. package/coverage/lcov-report/util/args.ts.html +508 -0
  75. package/coverage/lcov-report/util/errors.ts.html +232 -0
  76. package/coverage/lcov-report/util/helpers.ts.html +613 -0
  77. package/coverage/lcov-report/util/index.html +266 -0
  78. package/coverage/lcov-report/util/json.ts.html +115 -0
  79. package/coverage/lcov-report/util/log-memoize.ts.html +145 -0
  80. package/coverage/lcov-report/util/logger.ts.html +151 -0
  81. package/coverage/lcov-report/util/os-checker.ts.html +421 -0
  82. package/coverage/lcov-report/util/plugin-storage.ts.html +199 -0
  83. package/coverage/lcov-report/util/validations.ts.html +526 -0
  84. package/coverage/lcov-report/util/yaml.ts.html +193 -0
  85. package/coverage/lcov.info +2811 -0
  86. package/github-processes.md +16 -42
  87. package/manifests/bugs/aggregation-error-wrong-metric.yml +6 -6
  88. package/manifests/bugs/azure-importer-ignoring-defaults.yml +3 -3
  89. package/manifests/bugs/azure-importer-incorrect-calculation.yml +2 -2
  90. package/manifests/bugs/mock-observations-failure-duration-is-zero.yml +34 -0
  91. package/manifests/bugs/pipeline-error-uninitialized-plugin.yml +1 -1
  92. package/manifests/bugs/pipeline-ordering-error.yml +6 -6
  93. package/manifests/bugs/sci-embodied-missing-resources-total.yml +23 -0
  94. package/manifests/examples/generics.yml +3 -3
  95. package/manifests/examples/instance-metadata.yml +36 -0
  96. package/manifests/examples/mock-cpu-util-to-carbon.yml +3 -3
  97. package/manifests/examples/nesting.yml +37 -10
  98. package/manifests/examples/pipeline-teads-sci.yml +17 -9
  99. package/manifests/examples/pipeline-with-aggregate.yml +24 -9
  100. package/manifests/examples/pipeline-with-mocks.yml +26 -9
  101. package/manifests/examples/sci.yml +131 -0
  102. package/manifests/examples/teads-curve.yml +78 -0
  103. package/manifests/features/aggregate-failure-inalid-metrics.yml +43 -0
  104. package/manifests/features/aggregate-failure-missing-metric-in-inputs.yml +43 -0
  105. package/manifests/integrations/cloud-metadata-divide-boavizta.yml +1 -1
  106. package/manifests/integrations/mock-obs-group-by-cloud-meta.yml +51 -0
  107. package/manifests/integrations/mock-obs-groupby.yml +2 -2
  108. package/manifests/integrations/mock-obs-time-sync.yml +1 -1
  109. package/manifests/plugins/cloud-metadata/failure-invalid-instance-type.yaml +21 -0
  110. package/manifests/plugins/cloud-metadata/failure-invalid-vendor.yaml +1 -1
  111. package/manifests/plugins/cloud-metadata/failure-missing-cloud-vendor.yml +21 -0
  112. package/manifests/plugins/cloud-metadata/success.yml +1 -1
  113. package/manifests/plugins/coefficient/failure-invalid-config-input-param.yml +1 -1
  114. package/manifests/plugins/coefficient/failure-output-param-is-null.yaml +24 -0
  115. package/manifests/plugins/coefficient/success.yml +1 -1
  116. package/manifests/plugins/csv-lookup/failure-missing-column.yml +26 -0
  117. package/manifests/plugins/csv-lookup/failure-missing-output.yml +26 -0
  118. package/manifests/plugins/csv-lookup/success-renaming.yml +26 -0
  119. package/manifests/plugins/csv-lookup/success.yml +26 -0
  120. package/manifests/plugins/divide/failure-denominator-equal-zero.yml +39 -0
  121. package/manifests/plugins/divide/failure-invalid-config-denominator.yml +1 -1
  122. package/manifests/plugins/divide/failure-missing-numerator.yml +39 -0
  123. package/manifests/plugins/divide/success.yml +2 -2
  124. package/manifests/plugins/groupby/failure-missing-cloud-instance-type.yml +49 -0
  125. package/manifests/plugins/interpolation/interpolation.yml +24 -0
  126. package/manifests/plugins/mock-observations/failure-invalid-config-cpu-range.yml +1 -1
  127. package/manifests/plugins/mock-observations/failure-invalid-memory-utilization-range.yml +34 -0
  128. package/manifests/plugins/mock-observations/failure-missing-timestamp-from-param.yml +34 -0
  129. package/manifests/plugins/mock-observations/success.yml +2 -2
  130. package/manifests/plugins/multiply/failure-input-parameter-is-missing.yml +1 -1
  131. package/manifests/plugins/multiply/success-with-multiple-inputs.yml +32 -0
  132. package/manifests/plugins/multiply/success.yml +3 -3
  133. package/manifests/plugins/regex/failure-missing-input-param.yml +1 -1
  134. package/manifests/plugins/regex/failure-not-matching-with-regex.yml +24 -0
  135. package/manifests/plugins/regex/success.yml +2 -2
  136. package/manifests/plugins/sci/failure-invalid-config-value.yml +2 -3
  137. package/manifests/plugins/sci/failure-missing-input-param.yml +27 -0
  138. package/manifests/plugins/sci/success.yml +5 -4
  139. package/manifests/plugins/{sci-m → sci-embodied}/failure-invalid-default-emission-value.yml +5 -6
  140. package/manifests/plugins/sci-embodied/failure-missing-expected-lifespan.yml +23 -0
  141. package/manifests/plugins/{sci-m → sci-embodied}/success.yml +5 -6
  142. package/manifests/plugins/shell/failure-invalid-command.yml +1 -1
  143. package/manifests/plugins/shell/success.yml +1 -2
  144. package/manifests/plugins/sum/failure-missing-input-param.yml +1 -1
  145. package/manifests/plugins/sum/failure-missing-output-param.yml +28 -0
  146. package/manifests/plugins/sum/success.yml +1 -1
  147. package/manifests/plugins/tdp-finder/failure-unsupported-physical-processor.yml +19 -0
  148. package/manifests/plugins/time-sync/failure-missing-global-config.yml +34 -0
  149. package/package.json +10 -2
  150. package/src/__tests__/integration/manifest/sci-e.yaml +23 -0
  151. package/src/builtins/README.md +5 -5
  152. package/src/builtins/coefficient/README.md +92 -0
  153. package/src/builtins/csv-lookup/README.md +142 -0
  154. package/src/builtins/divide/README.md +95 -0
  155. package/src/builtins/exponent/README.md +97 -0
  156. package/src/builtins/interpolation/README.md +168 -0
  157. package/src/builtins/mock-observations/README.md +97 -0
  158. package/src/builtins/multiply/README.md +94 -0
  159. package/src/builtins/regex/README.md +91 -0
  160. package/src/builtins/sci/README.md +89 -0
  161. package/src/builtins/sci-embodied/README.md +110 -0
  162. package/src/builtins/shell/README.md +130 -0
  163. package/src/builtins/subtract/README.md +94 -0
  164. package/src/builtins/sum/README.md +91 -0
@@ -1,18 +1,17 @@
1
- name: sci-m
1
+ name: sci-embodied
2
2
  description: successful path
3
3
  tags:
4
4
  initialize:
5
5
  outputs: ['yaml']
6
6
  plugins:
7
- "sci-m": # a model that calculates m from te, tir, el, rr and rtor
8
- method: SciM
9
- verbose: false
10
- path: "@grnsft/if-plugins"
7
+ "sci-embodied": # a model that calculates m from te, tir, el, rr and rtor
8
+ method: SciEmbodied
9
+ path: "builtin"
11
10
  tree:
12
11
  children:
13
12
  child:
14
13
  pipeline:
15
- - sci-m # duration & config -> embodied
14
+ - sci-embodied # duration & config -> embodied
16
15
  defaults:
17
16
  device/emissions-embodied: 1533.120 # gCO2eq
18
17
  time-reserved: 3600 # 1hr in seconds
@@ -6,7 +6,7 @@ initialize:
6
6
  plugins:
7
7
  shell:
8
8
  method: Shell
9
- path: "@grnsft/if-plugins"
9
+ path: "builtin"
10
10
  global-config:
11
11
  command: 1000
12
12
  tree:
@@ -2,11 +2,10 @@ name: shell
2
2
  description: successful path
3
3
  tags:
4
4
  initialize:
5
- outputs: ['yaml']
6
5
  plugins:
7
6
  shell:
8
7
  method: Shell
9
- path: "@grnsft/if-plugins"
8
+ path: 'builtin'
10
9
  global-config:
11
10
  command: python3 /usr/local/bin/sampler
12
11
  tree:
@@ -6,7 +6,7 @@ initialize:
6
6
  plugins:
7
7
  sum:
8
8
  method: Sum
9
- path: "@grnsft/if-plugins"
9
+ path: "builtin"
10
10
  global-config:
11
11
  input-parameters: ["cpu/energy", "network/energy"]
12
12
  output-parameter: "energy"
@@ -0,0 +1,28 @@
1
+ name: sum
2
+ description: missing `output-parameter` in global-config
3
+ tags:
4
+ initialize:
5
+ outputs: ['yaml']
6
+ plugins:
7
+ sum:
8
+ method: Sum
9
+ path: "builtin"
10
+ global-config:
11
+ input-parameters: ["cpu/energy", "network/energy"]
12
+ # output-parameter: "energy"
13
+ tree:
14
+ children:
15
+ child:
16
+ pipeline:
17
+ - sum
18
+ config:
19
+ sum:
20
+ inputs:
21
+ - timestamp: 2023-08-06T00:00
22
+ duration: 3600
23
+ cpu/energy: 0.001
24
+ network/energy: 0.001
25
+ - timestamp: 2023-08-06T00:00
26
+ duration: 3600
27
+ cpu/energy: 0.001
28
+ network/energy: e
@@ -6,7 +6,7 @@ initialize:
6
6
  plugins:
7
7
  sum:
8
8
  method: Sum
9
- path: "@grnsft/if-plugins"
9
+ path: "builtin"
10
10
  global-config:
11
11
  input-parameters: ["cpu/energy", "network/energy"]
12
12
  output-parameter: "energy"
@@ -0,0 +1,19 @@
1
+ name: tdp-finder
2
+ description: successful path
3
+ tags:
4
+ initialize:
5
+ outputs: ['yaml']
6
+ plugins:
7
+ tdp-finder: # a model that returns an embodied value given the sci embodied attribution equation.
8
+ method: TdpFinder
9
+ path: "@grnsft/if-plugins"
10
+ tree:
11
+ children:
12
+ child:
13
+ pipeline:
14
+ - tdp-finder
15
+ config:
16
+ inputs:
17
+ - timestamp: 2023-07-06T00:00
18
+ duration: 300
19
+ physical-processor: AMD 302
@@ -0,0 +1,34 @@
1
+ name: time-sync
2
+ description: missing global config
3
+ tags:
4
+ initialize:
5
+ output:
6
+ - yaml
7
+ plugins:
8
+ 'time-sync':
9
+ method: TimeSync
10
+ path: "builtin"
11
+ global-config:
12
+ # start-time: '2023-12-12T00:00:00.000Z'
13
+ # end-time: '2023-12-12T00:01:00.000Z'
14
+ # interval: 5
15
+ # allow-padding: true
16
+ tree:
17
+ children:
18
+ child:
19
+ pipeline:
20
+ - time-sync
21
+ config:
22
+ inputs:
23
+ - timestamp: '2023-12-12T00:00:00.000Z'
24
+ duration: 3
25
+ energy-cpu: 0.001
26
+ - timestamp: '2023-12-12T00:00:01.000Z'
27
+ duration: 5
28
+ energy-cpu: 0.001
29
+ - timestamp: '2023-12-12T00:00:06.000Z'
30
+ duration: 7
31
+ energy-cpu: 0.001
32
+ - timestamp: '2023-12-12T00:00:13.000Z'
33
+ duration: 30
34
+ energy-cpu: 0.001
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@grnsft/if",
3
3
  "description": "Impact Framework",
4
- "version": "0.3.3-beta.0",
4
+ "version": "0.4.0-beta.0",
5
5
  "author": {
6
6
  "name": "Green Software Foundation",
7
7
  "email": "info@gsf.com"
8
8
  },
9
9
  "bin": {
10
- "ie": "./build/index.js"
10
+ "ie": "./build/index.js",
11
+ "if-diff": "./build/diff.js"
11
12
  },
12
13
  "bugs": {
13
14
  "url": "https://github.com/Green-Software-Foundation/if/issues/new?assignees=&labels=feedback&projects=&template=feedback.md&title=Feedback+-+"
@@ -15,11 +16,14 @@
15
16
  "dependencies": {
16
17
  "@commitlint/cli": "^18.6.0",
17
18
  "@commitlint/config-conventional": "^18.6.0",
19
+ "axios": "^1.7.2",
20
+ "csv-parse": "^5.5.6",
18
21
  "csv-stringify": "^6.4.6",
19
22
  "js-yaml": "^4.1.0",
20
23
  "luxon": "^3.4.4",
21
24
  "ts-command-line-args": "^2.5.1",
22
25
  "typescript": "^5.1.6",
26
+ "typescript-cubic-spline": "^1.0.1",
23
27
  "winston": "^3.11.0",
24
28
  "zod": "^3.22.4"
25
29
  },
@@ -31,10 +35,12 @@
31
35
  "@types/js-yaml": "^4.0.5",
32
36
  "@types/luxon": "^3.4.2",
33
37
  "@types/node": "^20.8.9",
38
+ "axios-mock-adapter": "^1.22.0",
34
39
  "fixpack": "^4.0.0",
35
40
  "gts": "^5.0.0",
36
41
  "husky": "^8.0.0",
37
42
  "jest": "^29.6.1",
43
+ "lint-staged": "^15.2.2",
38
44
  "release-it": "^16.3.0",
39
45
  "rimraf": "^5.0.5",
40
46
  "ts-jest": "^29.1.1"
@@ -67,7 +73,9 @@
67
73
  "fix": "gts fix",
68
74
  "fix:package": "fixpack",
69
75
  "ie": "npx ts-node src/index.ts",
76
+ "if-diff": "npx ts-node src/diff.ts",
70
77
  "lint": "gts lint",
78
+ "pre-commit": "lint-staged",
71
79
  "prepare": "husky install",
72
80
  "prepublish": "npm run build",
73
81
  "release": "release-it",
@@ -0,0 +1,23 @@
1
+ name: integration-template
2
+ description: null
3
+ tags: null
4
+ initialize:
5
+ plugins:
6
+ sci-e:
7
+ method: SciE
8
+ path: '@grnsft/if-plugins'
9
+ outputs:
10
+ - log
11
+ tree:
12
+ children:
13
+ child:
14
+ pipeline:
15
+ - sci-e
16
+ config:
17
+ sci-e: {}
18
+ inputs:
19
+ - timestamp: 2023-08-06T00:00
20
+ duration: 3600
21
+ cpu/energy: 10
22
+ memory/energy: 100
23
+ network/energy: 100
@@ -231,9 +231,9 @@ initialize:
231
231
  sci-e:
232
232
  method: SciE
233
233
  path: '@grnsft/if-plugins'
234
- sci-m:
235
- path: '@grnsft/if-plugins'
236
- method: SciM
234
+ sci-embodied:
235
+ path: 'builtin'
236
+ method: SciEmbodied
237
237
  sci-o:
238
238
  method: SciO
239
239
  path: '@grnsft/if-plugins'
@@ -250,13 +250,13 @@ tree:
250
250
  pipeline:
251
251
  - teads-curve
252
252
  - sci-e
253
- - sci-m
253
+ - sci-embodied
254
254
  - sci-o
255
255
  - time-sync
256
256
  config:
257
257
  teads-curve:
258
258
  cpu/thermal-design-power: 65
259
- sci-m:
259
+ sci-embodied:
260
260
  device/emissions-embodied: 251000 # gCO2eq
261
261
  time-reserved: 3600 # 1 hour in s
262
262
  device/expected-lifespan: 126144000 # 4 years in seconds
@@ -0,0 +1,92 @@
1
+ # Coefficient
2
+
3
+ `Coefficient` is a generic plugin for multiplying a value in an `input` array by a given coefficient.
4
+
5
+ You provide the name of the value you want to multiply, a coefficient value, and a name to use to append the product to the output array.
6
+
7
+ For example, you could multiply `cpu/energy` by 10 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 10.
8
+
9
+ ## Parameters
10
+
11
+ ### Plugin global config
12
+
13
+ Three parameters are required in global config: `input-parameter`, `coefficient` and `output-parameter`.
14
+
15
+ - `input-parameter`: a string matching an existing key in the `inputs` array
16
+ - `coefficient`: the value to multiply `input-parameter` by.
17
+ - `output-parameter`: a string defining the name to use to add the product of the input parameters to the output array.
18
+
19
+ ### Inputs
20
+
21
+ All of `input-parameters` must be available in the input array.
22
+
23
+ ## Returns
24
+
25
+ - `output-parameter`: the product of all `input-parameters` with the parameter name defined by `output-parameter` in global config.
26
+
27
+ ## Calculation
28
+
29
+ ```pseudocode
30
+ output = input * coefficient
31
+ ```
32
+
33
+ ## Implementation
34
+
35
+ To run the plugin from a Typescript app, you must first create an instance of `Coefficient`. Then, you can call `execute()`.
36
+
37
+ ```typescript
38
+ const config = {
39
+ 'input-parameter': 'carbon',
40
+ coefficient: 10,
41
+ 'output-parameter': 'carbon-product',
42
+ };
43
+
44
+ const coeff = Coefficient(config);
45
+ const result = coeff.execute([
46
+ {
47
+ duration: 3600,
48
+ timestamp: '2021-01-01T00:00:00Z',
49
+ carbon: 3,
50
+ },
51
+ ]);
52
+ ```
53
+
54
+ ## Example manifest
55
+
56
+ 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 `coefficient`:
57
+
58
+ ```yaml
59
+ name: coefficient-demo
60
+ description:
61
+ tags:
62
+ initialize:
63
+ outputs:
64
+ - yaml
65
+ plugins:
66
+ coefficient:
67
+ method: Coefficient
68
+ path: 'builtin'
69
+ global-config:
70
+ input-parameter: 'carbon'
71
+ coefficient: 3
72
+ output-parameter: 'carbon-product'
73
+ tree:
74
+ children:
75
+ child:
76
+ pipeline:
77
+ - coefficient
78
+ config:
79
+ coefficient:
80
+ inputs:
81
+ - timestamp: 2023-08-06T00:00
82
+ duration: 3600
83
+ carbon: 30
84
+ ```
85
+
86
+ You can run this example by saving it as `./examples/manifests/coefficient.yml` and executing the following command from the project root:
87
+
88
+ ```sh
89
+ ie --manifest ./examples/manifests/coefficient.yml --output ./examples/outputs/coefficient.yml
90
+ ```
91
+
92
+ The results will be saved to a new `yaml` file in `./examples/outputs`
@@ -0,0 +1,142 @@
1
+ # CSV Lookup Plugin
2
+
3
+ `csv-lookup` is a generic plugin that enables you to select arbitrary data from a given csv file and add it to your manifest file's `input` data.
4
+
5
+ You provide path to the target csv file pus some query parameters. The filepath can point to a location on the local filesystem or it can be a URL for an online resource. The query parameters include the column names for the target data you want to return (can be one column name, multiple column names or all column names, indicated using `"*"`), plus the column names and values you want to use as selectors.
6
+
7
+ For example, for the following CSV:
8
+
9
+ | | | | | | | | | | | | | | | | | |
10
+ | ---- | -------------- | --------------- | ---------- | ---------- | ------------ | --------- | ---------------- | ---------- | ---------- | ---------------------- | ---------- | -------------------------- | --------------------------------- | ------------------------------ | -------------------------------- | --------------------- |
11
+ | year | cloud-provider | cloud-region | cfe-region | em-zone-id | wt-region-id | location | geolocation | cfe-hourly | cfe-annual | power-usage-efficiency | net-carbon | grid-carbon-intensity-24x7 | grid-carbon-intensity-consumption | grid-carbon-intensity-marginal | grid-carbon-intensity-production | grid-carbon-intensity |
12
+ | 2022 | Google Cloud | asia-east1 | Taiwan | TW | TW | Taiwan | 25.0375,121.5625 | 0.18 | | | 0 | 453 | | | | 453 |
13
+ | 2022 | Google Cloud | asia-east2 | Hong Kong | HK | HK | Hong Kong | 22.3,114.2 | 0.28 | | | 0 | 453 | | | | 360 |
14
+ | 2022 | Google Cloud | asia-northeast1 | Tokyo | JP-TK | JP-TK | Tokyo | 35.6897,139.692 | 0.28 | | | 0 | 463 | | | | 463 |
15
+
16
+
17
+ You could select all the data for the cloud provider `Google Cloud` in the region `asia-east2` using the following configuration:
18
+
19
+ ```yaml
20
+ filepath: https://raw.githubusercontent.com/Green-Software-Foundation/if-data/main/region-metadata.csv
21
+ query:
22
+ cloud-provider: "cloud/provider"
23
+ cloud-region: "cloud/region"
24
+ output: "*"
25
+ ```
26
+
27
+ Notice that the query parameters are key/value pairs where the key is the column name in the target CSV and the value is a **reference to a value** in your `input` data (*not* an actual value - a reference). This is to enable you to chain CSV lookups together based on information from other plugins in your pipeline.
28
+
29
+
30
+ ## Parameters
31
+
32
+ ### Plugin config
33
+
34
+ - `filepath` - path to a csv file, either on the local filesystem or on the internet
35
+ - `query` - an array of key/value pairs where the key is a column name in the target csv and the value is a parameter from inputs
36
+ - `output` - the columns to grab data from and add to output data - should support wildcard or multiple values.
37
+
38
+ The plugin also supports data renaming. This means you can grab data from a named column but push it into your manifest file data under another name, for example, maybe we want to grab data from the `processor-name` column int he target csv and add it to the manifest file data as `processor-id` because this is the name expected by some other plugin in your piepline. You can do this by passing comma separated values in arrays.
39
+
40
+ ```yaml
41
+ output:
42
+ ["processor-name": "processor-id"]
43
+ ```
44
+
45
+ You can nest arrays to do this renaming for multiple columns.
46
+
47
+ ```yaml
48
+ output:
49
+ [["processor-name", "processor-model-id"],["tdp","thermal-design-power"]]
50
+ ```
51
+
52
+ All the following values are valid for the `output` field:
53
+ - `"*"`
54
+ - `"tdp"`
55
+ - `["processor-name", "processor-model-id"]`
56
+ - `[["processor-name", "processor-model-id"],["tdp","thermal-design-power"]]`
57
+
58
+ ### Inputs
59
+
60
+ There are no strict requirements on input for this plugin because they depend upon the contents of the target CSV and your input data at the time the CSV lookup is invoked. Please make sure you are requesting data from columns that exist in the target csv file and that your query values are available in your `input` data.
61
+
62
+ ## Returns
63
+
64
+ The input data with the requested csv content appended to it.
65
+
66
+ ## Plugin logic
67
+
68
+ 1. Validates global config which contains `filepath`, `query` and `output`.
69
+ 2. Tries to retrieve given file (with url or local path).
70
+ 3. Parses given CSV.
71
+ 4. Filters requested information from CSV.
72
+ 5. Adds new key-value pairs to the input data
73
+ 6. Returns enriched input data
74
+
75
+ ## Implementation
76
+
77
+ To run the plugin, you must first create an instance of `CSVLookup`. Then, you can call `execute()`.
78
+
79
+ ```typescript
80
+ const globalConfig = {
81
+ filepath: 'https://raw.githubusercontent.com/Green-Software-Foundation/if-data/main/cloud-metdata-aws-instances.csv',
82
+ query: {
83
+ 'cloud-provider': 'cloud/provider'
84
+ region: 'cloud/region'
85
+ 'instance-type': 'cloud/instance-type'
86
+ },
87
+ output: ['cpu-tdp', 'tdp'],
88
+ };
89
+ const divide = CSVLookup(globalConfig);
90
+
91
+ const input = [
92
+ {
93
+ timestamp: '2023-08-06T00:00'
94
+ duration: 3600
95
+ 'cpu/energy': 0.001
96
+ 'cloud/provider': gcp
97
+ 'cloud/region': asia-east
98
+ },
99
+ ];
100
+ ```
101
+
102
+ ## Example manifest
103
+
104
+ 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 `csv-lookup`:
105
+
106
+ ```yaml
107
+ name: csv-lookup-demo
108
+ description:
109
+ tags:
110
+ initialize:
111
+ outputs:
112
+ - yaml
113
+ plugins:
114
+ cloud-metadata:
115
+ method: CSVLookup
116
+ path: 'builtin'
117
+ global-config:
118
+ filepath: https://raw.githubusercontent.com/Green-Software-Foundation/if-data/main/region-metadata.csv
119
+ query:
120
+ cloud-provider: "cloud/provider"
121
+ cloud-region: "cloud/region"
122
+ output: "*"
123
+ tree:
124
+ children:
125
+ child:
126
+ pipeline:
127
+ - cloud-metadata
128
+ inputs:
129
+ - timestamp: 2023-08-06T00:00
130
+ duration: 3600
131
+ cloud/provider: Google Cloud
132
+ cloud/region: europe-north1
133
+ ```
134
+
135
+ You can run this example by saving it as `./examples/manifests/csv-lookup.yml` and executing the following command from the project root:
136
+
137
+ ```sh
138
+ npm i -g @grnsft/if
139
+ ie --manifest manifests/plugins/csv-lookup.yml --output manifests/outputs/csv-lookup
140
+ ```
141
+
142
+ The results will be saved to a new `yaml` file in `manifests/outputs`.
@@ -0,0 +1,95 @@
1
+ # Divide
2
+
3
+ `divide` is a generic plugin for doing arithmetic division of two values in an `input` array.
4
+
5
+ You provide the names of the values you want to divide, and a name to use to add the divide to the output array.
6
+
7
+ For example, `boavizta-cpu` need `cpu/number-cores` to work, however `cloud-metadata` returns `vcpus-allocated`, to get number of cores you divide `vcpus-allocated` by 2.
8
+
9
+ ## Parameters
10
+
11
+ ### Plugin config
12
+
13
+ - `numerator` - a parameter by a specific configured number
14
+ - `denominator` - a parameter by a specific configured number or the number by which `numerator` is divided
15
+ - `output` - the number to a configured output parameter
16
+
17
+ ### Inputs
18
+
19
+ - `numerator` - as input parameter, must be available in the input array
20
+ - `denominator` - must be available in the input array if is an input parameter
21
+ - `output` - as input parameter, must be available in the input array
22
+
23
+ ## Returns
24
+
25
+ - `output`: the division of `numerator` with the parameter name into `denominator` with the parameter name defined by `output` in global config.
26
+
27
+ The plugin throws an exception if the division result is not a number.
28
+
29
+ ## Calculation
30
+
31
+ ```pseudocode
32
+ output = input0 / input1
33
+ ```
34
+
35
+ ## Implementation
36
+
37
+ To run the plugin, you must first create an instance of `Divide`. Then, you can call `execute()`.
38
+
39
+ ```typescript
40
+ const globalConfig = {
41
+ numerator: 'vcpus-allocated',
42
+ denominator: 2,
43
+ output: 'cpu/number-cores',
44
+ };
45
+ const divide = Divide(globalConfig);
46
+
47
+ const input = [
48
+ {
49
+ timestamp: '2021-01-01T00:00:00Z',
50
+ duration: 3600,
51
+ 'vcpus-allocated': 24,
52
+ },
53
+ ];
54
+ ```
55
+
56
+ ## Example manifest
57
+
58
+ 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 `divide`:
59
+
60
+ ```yaml
61
+ name: divide-demo
62
+ description:
63
+ tags:
64
+ initialize:
65
+ outputs:
66
+ - yaml
67
+ plugins:
68
+ divide:
69
+ method: Divide
70
+ path: 'builtin'
71
+ global-config:
72
+ numerator: vcpus-allocated
73
+ denominator: 2
74
+ output: cpu/number-cores
75
+ tree:
76
+ children:
77
+ child:
78
+ pipeline:
79
+ - divide
80
+ config:
81
+ divide:
82
+ inputs:
83
+ - timestamp: 2023-08-06T00:00
84
+ duration: 3600
85
+ vcpus-allocated: 24
86
+ ```
87
+
88
+ You can run this example by saving it as `./examples/manifests/divide.yml` and executing the following command from the project root:
89
+
90
+ ```sh
91
+ npm i -g @grnsft/if
92
+ ie --manifest ./examples/manifests/divide.yml --output ./examples/outputs/divide.yml
93
+ ```
94
+
95
+ The results will be saved to a new `yaml` file in `./examples/outputs`.
@@ -0,0 +1,97 @@
1
+ # Exponent
2
+
3
+ `exponent` is a generic plugin for calculating exponent of an input param (as base) and another (as the exponent) in an `input` array.
4
+
5
+ You provide the names of the values you want to use for the exponent calculation, and a name to use to add the exponent result to the output array.
6
+
7
+ For example, you use `cpu/energy` as base and `network/energy` as and name the result `energy`. `energy` would then be added to every observation in your input array as `cpu/energy` raised by the exponent `network/energy`.
8
+
9
+ ## Parameters
10
+
11
+ ### Plugin config
12
+
13
+ Three parameters are required in global config: `input-parameter`, `exponent` and `output-parameter`.
14
+
15
+ `input-parameter`: a string defining the base. Must match an existing key in the `inputs` array
16
+ `exponent`: a number defining the exponent.
17
+ `output-parameter`: a string defining the name to use to add the result of the exponent to the output array.
18
+
19
+ ### Inputs
20
+
21
+ `input-parameter` and `exponent` must be available in the input array.
22
+
23
+ ## Returns
24
+
25
+ - `output-parameter`: `input-parameter` raised by `exponent` with the parameter name defined by `output-parameter` in global config.
26
+
27
+ ## Calculation
28
+
29
+ ```pseudocode
30
+ output = input ^ exponent
31
+ ```
32
+
33
+ ## Implementation
34
+
35
+ To run the plugin, you must first create an instance of `Exponent`. Then, you can call `execute()`.
36
+
37
+ ```typescript
38
+ import {Exponent} from 'builtins';
39
+
40
+ const config = {
41
+ inputParameter: ['cpu/energy'],
42
+ exponent: 2
43
+ outputParameter: 'energy',
44
+ };
45
+
46
+ const exponent = Exponent(config);
47
+ const result = await exponent.execute([
48
+ {
49
+ duration: 3600,
50
+ timestamp: '2021-01-01T00:00:00Z',
51
+ 'cpu/energy': 0.1,
52
+ 'energy': 0.01,
53
+ },
54
+ ]);
55
+ ```
56
+
57
+ ## Example manifest
58
+
59
+ 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 and does not have to be done explicitly by the user. The following is an example manifest that calls `exponent`:
60
+
61
+ ```yaml
62
+ name: exponent demo
63
+ description:
64
+ tags:
65
+ initialize:
66
+ outputs:
67
+ - yaml
68
+ plugins:
69
+ exponent:
70
+ method: Exponent
71
+ path: 'builtin'
72
+ global-config:
73
+ input-parameter: 'cpu/energy'
74
+ exponent: 2
75
+ output-parameter: 'energy'
76
+ tree:
77
+ children:
78
+ child:
79
+ pipeline:
80
+ - exponent
81
+ config:
82
+ exponent:
83
+ inputs:
84
+ - timestamp: 2023-08-06T00:00
85
+ duration: 3600
86
+ cpu/energy: 0.001
87
+ network/energy: 0.001
88
+ ```
89
+
90
+ You can run this example by saving it as `manifests/examples/test/exponent.yml` and executing the following command from the project root:
91
+
92
+ ```sh
93
+ npm i -g @grnsft/if
94
+ ie --manifest manifests/examples/test/exponent.yml --output manifests/outputs/exponent.yml
95
+ ```
96
+
97
+ The results will be saved to a new `yaml` file in `manifests/outputs`.