From 45dde859eb86ebff02acf2acc9835854b41c5fa5 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Tue, 15 Oct 2024 16:46:20 +0400 Subject: [PATCH 01/11] feat(builtins): enable interpolation to accept 0 or off values --- src/if-run/builtins/interpolation/index.ts | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/if-run/builtins/interpolation/index.ts b/src/if-run/builtins/interpolation/index.ts index 30226e5a..d980ba52 100644 --- a/src/if-run/builtins/interpolation/index.ts +++ b/src/if-run/builtins/interpolation/index.ts @@ -54,12 +54,13 @@ export const Interpolation = PluginFactory({ .object({ timestamp: z.string().or(z.date()), duration: z.number(), - [inputParameter]: z.number().gt(0), + [inputParameter]: z.number().gte(0).or(z.literal('off')), }) .refine( data => - data[inputParameter] >= config.x[0] && - data[inputParameter] <= config.x[config.x.length - 1], + (data[inputParameter] >= config.x[0] && + data[inputParameter] <= config.x[config.x.length - 1]) || + data[inputParameter] === 'off', { message: WITHIN_THE_RANGE, } @@ -68,14 +69,22 @@ export const Interpolation = PluginFactory({ return validate>(schema, input, index); }, implementation: async (inputs: PluginParams[], config: ConfigParams) => { - const {'output-parameter': outputParameter} = config; + const { + 'input-parameter': inputParameter, + 'output-parameter': outputParameter, + } = config; return inputs.map(input => { - const calculatedResult = calculateResult(config, input); + if (input[inputParameter] === 'off') { + return { + ...input, + [inputParameter]: 0, + }; + } return { ...input, - [outputParameter]: calculatedResult, + [outputParameter]: calculateResult(config, input), }; }); }, @@ -169,7 +178,8 @@ const getPolynomialInterpolation = ( return result; }; +/** + * Sorts given point items in ascending order. + */ const sortPoints = (items: number[]) => - items.sort((a: number, b: number) => { - return a - b; - }); + items.sort((a: number, b: number) => a - b); From a9de9d341a8b1170b8118cdb247bfef45b83b35e Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Tue, 15 Oct 2024 16:48:06 +0400 Subject: [PATCH 02/11] fix(lib): in compute rename inputsStorage to outputsStorage --- src/if-run/lib/compute.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/if-run/lib/compute.ts b/src/if-run/lib/compute.ts index 5e73cbbb..577790ca 100644 --- a/src/if-run/lib/compute.ts +++ b/src/if-run/lib/compute.ts @@ -99,8 +99,8 @@ const computeNode = async (node: Node, params: ComputeParams): Promise => { }); } - let inputStorage = structuredClone(node.inputs) as PluginParams[]; - inputStorage = mergeDefaults(inputStorage, defaults); + let outputStorage = structuredClone(node.inputs) as PluginParams[]; + outputStorage = mergeDefaults(outputStorage, defaults); const pipelineCopy = structuredClone(pipeline) || {}; /** Checks if pipeline is not an array or empty object. */ @@ -125,8 +125,8 @@ const computeNode = async (node: Node, params: ComputeParams): Promise => { const plugin = params.pluginStorage.get(pluginName); const nodeConfig = config && config[pluginName]; - inputStorage = await plugin.execute(inputStorage, nodeConfig); - node.inputs = inputStorage; + outputStorage = await plugin.execute(outputStorage, nodeConfig); + node.inputs = outputStorage; if (params.context.explainer) { addExplainData({ @@ -145,7 +145,7 @@ const computeNode = async (node: Node, params: ComputeParams): Promise => { const originalOutputs = params.append ? node.outputs || [] : []; node.children = Regroup( - inputStorage, + outputStorage, originalOutputs, pipelineCopy.regroup ); @@ -183,10 +183,12 @@ const computeNode = async (node: Node, params: ComputeParams): Promise => { console.debug(COMPUTING_PIPELINE_FOR_NODE(pluginName)); debugLogger.setExecutingPluginName(pluginName); - inputStorage = await plugin.execute(inputStorage, nodeConfig); + console.log(outputStorage); + outputStorage = await plugin.execute(outputStorage, nodeConfig); + console.log(outputStorage); debugLogger.setExecutingPluginName(); - node.outputs = inputStorage; + node.outputs = outputStorage; if (params.context.explainer) { addExplainData({ From addb108f781193106b499d73bdaa3479ad352ca0 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Tue, 15 Oct 2024 16:48:34 +0400 Subject: [PATCH 03/11] chore(package): update if-core version --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 177c8051..40ce2721 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.25", + "@grnsft/if-core": "^0.0.26", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", @@ -1186,9 +1186,9 @@ } }, "node_modules/@grnsft/if-core": { - "version": "0.0.25", - "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.25.tgz", - "integrity": "sha512-1W4SXsXhXos06q4SBPc8QpgQPDhHEc03njrGcd/X2UiJyh0ycBKTqGCjuRPRipEayGgUxO0DwRNOgNcgzzcDkA==", + "version": "0.0.26", + "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.26.tgz", + "integrity": "sha512-j8oO4/2y+229ei2LObZtwZJYey/3vqZVErsad0tCQp++aVAoP6y8/0iVRGbOUw7Mg7UITRXFcbnbN6Kgy0Ix4A==", "dependencies": { "typescript": "^5.1.6", "zod": "^3.23.8" diff --git a/package.json b/package.json index 343382e7..af1d8162 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.25", + "@grnsft/if-core": "^0.0.26", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", From 7039956a6970d703bcfb4b0e6e772d3febeb6352 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Tue, 15 Oct 2024 16:51:19 +0400 Subject: [PATCH 04/11] feat(manifests): add success with off to interpolation --- .../interpolation/success-with-off.yml | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 manifests/examples/builtins/interpolation/success-with-off.yml diff --git a/manifests/examples/builtins/interpolation/success-with-off.yml b/manifests/examples/builtins/interpolation/success-with-off.yml new file mode 100644 index 00000000..0aebabbf --- /dev/null +++ b/manifests/examples/builtins/interpolation/success-with-off.yml @@ -0,0 +1,24 @@ +name: interpolation-demo +description: simple demo of interpolation plugin +tags: +initialize: + plugins: + interpolation: + method: Interpolation + path: "builtin" + config: + method: linear + x: [0, 10, 50, 100] + y: [0.12, 0.32, 0.75, 1.02] + input-parameter: "cpu/utilization" + output-parameter: "result" +tree: + children: + child: + pipeline: + compute: + - interpolation + inputs: + - timestamp: 2023-07-06T00:00 + duration: 3600 + cpu/utilization: off From a379f158095a34857c86425b57922cc66ed10e03 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Tue, 15 Oct 2024 16:59:55 +0400 Subject: [PATCH 05/11] feat(doc): update interpolation README --- src/if-run/builtins/interpolation/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/if-run/builtins/interpolation/README.md b/src/if-run/builtins/interpolation/README.md index d328dc9a..9b62e700 100644 --- a/src/if-run/builtins/interpolation/README.md +++ b/src/if-run/builtins/interpolation/README.md @@ -62,7 +62,7 @@ The plugin expects the following input parameters: - `timestamp`: a timestamp for the input (required) - `duration`: the amount of time, in seconds, that the input covers. (required) -- `[input-parameter]` - a field whose name matches the string provided to input-parameter in config (i.e. if the input-parameter in config is cpu/utilisation then cpu-utilisation must exist in the input data) +- `[input-parameter]` - a field whose name matches the string provided to input-parameter in config (i.e. if the input-parameter in config is cpu/utilisation then cpu-utilisation must exist in the input data). Value can be greater or equal to 0. For modeling server which totally turned off, `off` value can be used. ## Output From 702b96146e9d1a40c20eab6dd0d8a48a84176818 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Tue, 15 Oct 2024 18:55:12 +0400 Subject: [PATCH 06/11] test(builtins): add cases to cover interpolation input 0 and off --- .../if-run/builtins/interpolation.test.ts | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/__tests__/if-run/builtins/interpolation.test.ts b/src/__tests__/if-run/builtins/interpolation.test.ts index be379b3d..268d9ebf 100644 --- a/src/__tests__/if-run/builtins/interpolation.test.ts +++ b/src/__tests__/if-run/builtins/interpolation.test.ts @@ -55,6 +55,49 @@ describe('builtins/interpolation: ', () => { expect(result).toEqual(outputs); }); + it('returns valid output parameter if input parameter is 0.', async () => { + const inputs = [ + { + timestamp: '2023-07-06T00:00', + duration: 3600, + 'cpu/utilization': 0, + }, + ]; + const outputs = [ + { + timestamp: '2023-07-06T00:00', + duration: 3600, + 'cpu/utilization': 0, + 'interpolation-result': 0.12, + }, + ]; + + const result = await plugin.execute(inputs); + + expect(result).toEqual(outputs); + }); + + it('returns no output parameter if input parameter is `off`.', async () => { + const inputs = [ + { + timestamp: '2023-07-06T00:00', + duration: 3600, + 'cpu/utilization': 'off', + }, + ]; + const outputs = [ + { + timestamp: '2023-07-06T00:00', + duration: 3600, + 'cpu/utilization': 0, + }, + ]; + + const result = await plugin.execute(inputs); + + expect(result).toEqual(outputs); + }); + it('returns result when `mapping` has valid data.', async () => { const mapping = { 'cpu/utilization': 'cpu/util', From a00faca6f14ac0141ec03be3e3a1789b45429060 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Tue, 15 Oct 2024 18:57:59 +0400 Subject: [PATCH 07/11] fix(.github): update pull request template --- .github/PULL_REQUEST_TEMPLATE.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 50c9aaba..9254fe1f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -4,11 +4,8 @@ - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) -- [ ] My code follows the code style of this project. -- [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [ ] I have added tests to cover my changes. -- [ ] All new and existing tests passed. ### A description of the changes proposed in the Pull Request From 004a73f835139a44171b28f324c4788b4f9e95c4 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Wed, 16 Oct 2024 11:52:05 +0400 Subject: [PATCH 08/11] fix(lib): remove console.log Co-authored-by: Manushak Keramyan Signed-off-by: Narek Hovhannisyan --- src/if-run/lib/compute.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/if-run/lib/compute.ts b/src/if-run/lib/compute.ts index 577790ca..81bc768e 100644 --- a/src/if-run/lib/compute.ts +++ b/src/if-run/lib/compute.ts @@ -183,7 +183,6 @@ const computeNode = async (node: Node, params: ComputeParams): Promise => { console.debug(COMPUTING_PIPELINE_FOR_NODE(pluginName)); debugLogger.setExecutingPluginName(pluginName); - console.log(outputStorage); outputStorage = await plugin.execute(outputStorage, nodeConfig); console.log(outputStorage); debugLogger.setExecutingPluginName(); From 6200ad4b75b241ca2bf7d097f9def0b97cb0e70c Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Mon, 21 Oct 2024 12:57:25 +0400 Subject: [PATCH 09/11] chore(package): update if core version to 0.0.28 --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 40ce2721..ded744c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.26", + "@grnsft/if-core": "^0.0.28", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", @@ -1186,9 +1186,9 @@ } }, "node_modules/@grnsft/if-core": { - "version": "0.0.26", - "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.26.tgz", - "integrity": "sha512-j8oO4/2y+229ei2LObZtwZJYey/3vqZVErsad0tCQp++aVAoP6y8/0iVRGbOUw7Mg7UITRXFcbnbN6Kgy0Ix4A==", + "version": "0.0.28", + "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.28.tgz", + "integrity": "sha512-DM88HFeBbR1yl3bU0vFRgy6FnmUiyP4KhmtXp7HK1tMQHtnuKxzdPSxbfdpHsnUuHlvgDG7R/dI67/PmQD4U5w==", "dependencies": { "typescript": "^5.1.6", "zod": "^3.23.8" diff --git a/package.json b/package.json index af1d8162..7a05f574 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.26", + "@grnsft/if-core": "^0.0.28", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", From 47731dd8415180d20f813629cceca9a652586f07 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Mon, 21 Oct 2024 12:57:39 +0400 Subject: [PATCH 10/11] feat(builtins): return zero output param if input `is off` --- src/if-run/builtins/interpolation/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/if-run/builtins/interpolation/index.ts b/src/if-run/builtins/interpolation/index.ts index d980ba52..bfc39e3c 100644 --- a/src/if-run/builtins/interpolation/index.ts +++ b/src/if-run/builtins/interpolation/index.ts @@ -79,6 +79,7 @@ export const Interpolation = PluginFactory({ return { ...input, [inputParameter]: 0, + [outputParameter]: 0, }; } From c4e47651f786850b3fecb3b34f06bf1d39d21248 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Mon, 21 Oct 2024 12:59:17 +0400 Subject: [PATCH 11/11] test(builtins): update interpolation units --- src/__tests__/if-run/builtins/interpolation.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/__tests__/if-run/builtins/interpolation.test.ts b/src/__tests__/if-run/builtins/interpolation.test.ts index 268d9ebf..dd538152 100644 --- a/src/__tests__/if-run/builtins/interpolation.test.ts +++ b/src/__tests__/if-run/builtins/interpolation.test.ts @@ -90,6 +90,7 @@ describe('builtins/interpolation: ', () => { timestamp: '2023-07-06T00:00', duration: 3600, 'cpu/utilization': 0, + 'interpolation-result': 0, }, ];