Skip to content

time-sync: add min/max/median aggregation methods ; treat as constants during normalization (Fixes #918)#1167

Open
kalialovish wants to merge 3 commits intoGreen-Software-Foundation:mainfrom
kalialovish:feat/time-sync-agg-methods-918
Open

time-sync: add min/max/median aggregation methods ; treat as constants during normalization (Fixes #918)#1167
kalialovish wants to merge 3 commits intoGreen-Software-Foundation:mainfrom
kalialovish:feat/time-sync-agg-methods-918

Conversation

@kalialovish
Copy link
Copy Markdown

What

[x] Adds min, max, median to allowed aggregation methods.
[x] Handle these test cases in time-sync, treating them as copy equivalents
[x] Add unit tests
[x] Add documentation to time-sync README

Why

To support edge cases where

Context

Expands time sync and aggregation functionality

SoW (scope of work)

[x] aggregation methods added
[x] time-sync updated to handle new methods
[x] documentation updated
[x] test cases added

@kalialovish kalialovish force-pushed the feat/time-sync-agg-methods-918 branch from fce2276 to 7d00244 Compare March 8, 2026 15:59
@kalialovish kalialovish force-pushed the feat/time-sync-agg-methods-918 branch from 7d00244 to 0bd9ba9 Compare March 17, 2026 08:26
@narekhovhannisyan
Copy link
Copy Markdown
Member

Hi @kalialovish, thanks for your contribution! I will review the PR asap and leave a comment if needed.

@narekhovhannisyan
Copy link
Copy Markdown
Member

Hi @kalialovish , I'm unable to run tests since aggregation methods are stored in if-core repository not here. So newly added aggregation methods like min, max, median are not included in AGGREGATION_METHODS constant.

see here in if-core

please rise a PR addind that methods, then I will cut a new release of if-core v0.0.31, so you can include that version in if's package.json.

Thanks!

@narekhovhannisyan
Copy link
Copy Markdown
Member

@kalialovish I have released v0.0.31 version of if-core. You should update if-core version here.

…ng normalization; tests + README (Green-Software-Foundation#918)

Signed-off-by: lovish.kalia <lovish.kalia@accenture.com>
Signed-off-by: lovish.kalia <https.ping@gmail.com>
@kalialovish kalialovish force-pushed the feat/time-sync-agg-methods-918 branch from 0bd9ba9 to 5b9faab Compare March 28, 2026 10:44
@kalialovish
Copy link
Copy Markdown
Author

@narekhovhannisyan this branch is now referring to if-core v0.0.31. Please test and review the changes. Thanks

@narekhovhannisyan
Copy link
Copy Markdown
Member

@kalialovish, I have pulled the latest changes. I'm unable to run the tests; they are failing:

Summary of all failing tests
 FAIL  src/__tests__/if-run/util/aggregation-helper.test.ts
  ● util/aggregation-helper:  › aggregateOutputsIntoOne():  › executes when aggregation properties are `min`.

    expect(received).toEqual(expected) // deep equality

    - Expected  - 2
    + Received  + 0

      Object {
        "carbon": 10,
    -   "duration": 10,
    -   "timeStamp": "",
      }

      192 |       };
      193 |       const aggregated = aggregateOutputsIntoOne(inputs, metrics, isTemporal);
    > 194 |       expect(aggregated).toEqual(expectedValue);
          |                          ^
      195 |     });
      196 |     it('executes when aggregation properties are `max`.', () => {
      197 |       storeAggregationMetrics({

      at Object.<anonymous> (src/__tests__/if-run/util/aggregation-helper.test.ts:194:26)

  ● util/aggregation-helper:  › aggregateOutputsIntoOne():  › executes when aggregation properties are `max`.

    expect(received).toEqual(expected) // deep equality

    - Expected  - 2
    + Received  + 0

      Object {
        "carbon": 30,
    -   "duration": 10,
    -   "timeStamp": "",
      }

      215 |       };
      216 |       const aggregated = aggregateOutputsIntoOne(inputs, metrics, isTemporal);
    > 217 |       expect(aggregated).toEqual(expectedValue);
          |                          ^
      218 |     });
      219 |     it('executes when aggregation properties are `median` for odd length.', () => {
      220 |       storeAggregationMetrics({

      at Object.<anonymous> (src/__tests__/if-run/util/aggregation-helper.test.ts:217:26)

  ● util/aggregation-helper:  › aggregateOutputsIntoOne():  › executes when aggregation properties are `median` for odd length.

    expect(received).toEqual(expected) // deep equality

    - Expected  - 2
    + Received  + 0

      Object {
        "carbon": 5,
    -   "duration": 10,
    -   "timeStamp": "",
      }

      238 |       };
      239 |       const aggregated = aggregateOutputsIntoOne(inputs, metrics, isTemporal);
    > 240 |       expect(aggregated).toEqual(expectedValue);
          |                          ^
      241 |     });
      242 |     it('executes when aggregation properties are `median` for even length.', () => {
      243 |       storeAggregationMetrics({

      at Object.<anonymous> (src/__tests__/if-run/util/aggregation-helper.test.ts:240:26)

  ● util/aggregation-helper:  › aggregateOutputsIntoOne():  › executes when aggregation properties are `median` for even length.

    expect(received).toEqual(expected) // deep equality

    - Expected  - 2
    + Received  + 0

      Object {
        "carbon": 6.5,
    -   "duration": 10,
    -   "timeStamp": "",
      }

      262 |       };
      263 |       const aggregated = aggregateOutputsIntoOne(inputs, metrics, isTemporal);
    > 264 |       expect(aggregated).toEqual(expectedValue);
          |                          ^
      265 |     });
      266 |     it('coerces numeric strings and ignores non-finite values when reducing', () => {
      267 |       storeAggregationMetrics({

      at Object.<anonymous> (src/__tests__/if-run/util/aggregation-helper.test.ts:264:26)

  ● util/aggregation-helper:  › aggregateOutputsIntoOne():  › coerces numeric strings and ignores non-finite values when reducing

    expect(received).toEqual(expected) // deep equality

    - Expected  - 2
    + Received  + 0

      Object {
        "carbon": -2.5,
    -   "duration": 10,
    -   "timeStamp": "",
      }

      286 |       };
      287 |       const aggregated = aggregateOutputsIntoOne(inputs, metrics, isTemporal);
    > 288 |       expect(aggregated).toEqual(expectedValue);
          |                          ^
      289 |     });
      290 |   });
      291 | });

      at Object.<anonymous> (src/__tests__/if-run/util/aggregation-helper.test.ts:288:26)


Test Suites: 1 failed, 57 passed, 58 total
Tests:       5 failed, 494 passed, 499 total
Snapshots:   0 total
Time:        4.613 s
Ran all test suites.

Also lint is not passing:


/Users/admin/Projects/UK/if/src/__tests__/if-run/util/aggregation-helper.test.ts
  178:27  error  Insert `,`                         prettier/prettier
  191:19  error  Insert `,`                         prettier/prettier
  200:27  error  Insert `,`                         prettier/prettier
  214:19  error  Insert `,`                         prettier/prettier
  223:30  error  Insert `,`                         prettier/prettier
  237:18  error  Insert `,`                         prettier/prettier
  246:30  error  Insert `,`                         prettier/prettier
  261:19  error  Replace `+9)/2` with `·+·9)·/·2,`  prettier/prettier
  270:27  error  Insert `,`                         prettier/prettier
  285:21  error  Insert `,`                         prettier/prettier

/Users/admin/Projects/UK/if/src/if-run/builtins/time-sync/index.ts
  143:58   error  Replace `·method·===·'copy'·||·method·===·'min'·||·method·===·'max'·||·method·===·'median';·` with `⏎······method·===·'copy'·||⏎······method·===·'min'·||⏎······method·===·'max'·||⏎······method·===·'median';`  prettier/prettier
  143:140  error  Trailing spaces not allowed                                                                                                                                                                                      no-trailing-spaces

/Users/admin/Projects/UK/if/src/if-run/util/aggregation-helper.ts
   44:61  error  Replace `·|·'none'·|'copy'·|·'sum'·|·'avg'·|·'min'·|·'max'` with `⏎··········|·'none'⏎··········|·'copy'⏎··········|·'sum'⏎··········|·'avg'⏎··········|·'min'⏎··········|·'max'⏎·········`                         prettier/prettier
   55:16  error  Insert `·`                                                                                                                                                                                                          prettier/prettier
   58:15  error  Insert `·`                                                                                                                                                                                                          prettier/prettier
   66:40  error  Insert `·`                                                                                                                                                                                                          prettier/prettier
   81:29  error  Replace `'Unsupported·aggregation·method:·${(String(method)}·for·${metric}'` with `⏎··············'Unsupported·aggregation·method:·${(String(method)}·for·${metric}'⏎············`                                  prettier/prettier
   90:13  error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   91:1   error  Replace `············` with `··············`                                                                                                                                                                        prettier/prettier
   92:11  error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   93:1   error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   94:1   error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   95:13  error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   96:15  error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   97:1   error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   98:15  error  Replace `arr.sort((a,b)·=>·a-` with `··arr.sort((a,·b)·=>·a·-·`                                                                                                                                                     prettier/prettier
   99:1   error  Insert `··`                                                                                                                                                                                                         prettier/prettier
  100:15  error  Replace `acc[metric]·=·arr.length·%·2·===·0·?·(arr[mid·-·1]·+·arr[mid])·/·2` with `··acc[metric]·=⏎··················arr.length·%·2·===·0⏎····················?·(arr[mid·-·1]·+·arr[mid])·/·2⏎···················`  prettier/prettier
  101:1   error  Insert `··`                                                                                                                                                                                                         prettier/prettier
  102:13  error  Insert `··`                                                                                                                                                                                                         prettier/prettier
  103:1   error  Replace `··········` with `············`                                                                                                                                                                            prettier/prettier
  104:1   error  Replace `··········default:` with `············default:⏎·············`                                                                                                                                              prettier/prettier
  105:1   error  Insert `··`                                                                                                                                                                                                         prettier/prettier

✖ 33 problems (33 errors, 0 warnings)
  33 errors and 0 warnings potentially fixable with the `--fix` option.

Please revise so I can test.

lovish.kalia added 2 commits April 9, 2026 20:56
…ng normalization; tests + README (Green-Software-Foundation#918)

Signed-off-by: lovish.kalia <lovish.kalia@accenture.com>
Signed-off-by: lovish.kalia <https.ping@gmail.com>
…ng normalization; tests + README (Green-Software-Foundation#918)

Signed-off-by: lovish.kalia <https.ping@gmail.com>
@kalialovish
Copy link
Copy Markdown
Author

@narekhovhannisyan fix deployed, please retest

@narekhovhannisyan
Copy link
Copy Markdown
Member

@kalialovish I have checked, and the functionality works fine. However, there are lint issues that will block the release flow.


/Users/admin/Projects/UK/if/src/__tests__/if-run/util/aggregation-helper.test.ts
  178:27  error  Insert `,`                         prettier/prettier
  191:19  error  Insert `,`                         prettier/prettier
  200:27  error  Insert `,`                         prettier/prettier
  214:19  error  Insert `,`                         prettier/prettier
  223:30  error  Insert `,`                         prettier/prettier
  237:18  error  Insert `,`                         prettier/prettier
  246:30  error  Insert `,`                         prettier/prettier
  261:19  error  Replace `+9)/2` with `·+·9)·/·2,`  prettier/prettier
  270:27  error  Insert `,`                         prettier/prettier
  285:21  error  Insert `,`                         prettier/prettier

/Users/admin/Projects/UK/if/src/if-run/builtins/time-sync/index.ts
  143:58   error  Replace `·method·===·'copy'·||·method·===·'min'·||·method·===·'max'·||·method·===·'median';·` with `⏎······method·===·'copy'·||⏎······method·===·'min'·||⏎······method·===·'max'·||⏎······method·===·'median';`  prettier/prettier
  143:140  error  Trailing spaces not allowed                                                                                                                                                                                      no-trailing-spaces

/Users/admin/Projects/UK/if/src/if-run/util/aggregation-helper.ts
   44:61  error  Replace `·|·'none'·|'copy'·|·'sum'·|·'avg'·|·'min'·|·'max'` with `⏎··········|·'none'⏎··········|·'copy'⏎··········|·'sum'⏎··········|·'avg'⏎··········|·'min'⏎··········|·'max'⏎·········`                         prettier/prettier
   55:16  error  Insert `·`                                                                                                                                                                                                          prettier/prettier
   58:15  error  Insert `·`                                                                                                                                                                                                          prettier/prettier
   66:40  error  Insert `·`                                                                                                                                                                                                          prettier/prettier
   81:29  error  Replace `'Unsupported·aggregation·method:·${(String(method)}·for·${metric}'` with `⏎··············'Unsupported·aggregation·method:·${(String(method)}·for·${metric}'⏎············`                                  prettier/prettier
   90:13  error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   91:1   error  Replace `············` with `··············`                                                                                                                                                                        prettier/prettier
   92:11  error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   93:1   error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   94:1   error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   95:13  error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   96:15  error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   97:1   error  Insert `··`                                                                                                                                                                                                         prettier/prettier
   98:15  error  Replace `arr.sort((a,b)·=>·a-` with `··arr.sort((a,·b)·=>·a·-·`                                                                                                                                                     prettier/prettier
   99:1   error  Insert `··`                                                                                                                                                                                                         prettier/prettier
  100:15  error  Replace `acc[metric]·=·arr.length·%·2·===·0·?·(arr[mid·-·1]·+·arr[mid])·/·2` with `··acc[metric]·=⏎··················arr.length·%·2·===·0⏎····················?·(arr[mid·-·1]·+·arr[mid])·/·2⏎···················`  prettier/prettier
  101:1   error  Insert `··`                                                                                                                                                                                                         prettier/prettier
  102:13  error  Insert `··`                                                                                                                                                                                                         prettier/prettier
  103:1   error  Replace `··········` with `············`                                                                                                                                                                            prettier/prettier
  104:1   error  Replace `··········default:` with `············default:⏎·············`                                                                                                                                              prettier/prettier
  105:1   error  Insert `··`                                                                                                                                                                                                         prettier/prettier

✖ 33 problems (33 errors, 0 warnings)
  33 errors and 0 warnings potentially fixable with the `--fix` option.

Please fix that so we can merge and go on!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants