Rollup with Moment duration or certain duration factory methods generates error
The happy path works:
series.fixedWindowRollup({
window(duration('1h')),
aggregation: {v_sum: ['v', sum()]}
})
However, the following does not work, and generates TypeError: Cannot read property 'mid' of undefined:
series.fixedWindowRollup({
window(duration(moment.duration(1, 'h'))),
aggregation: {v_sum: ['v', sum()]}
})
Other variants have issues too:
duration(moment.duration(1, 'h').asMilliseconds())
But, if you hack the _string property, it works!
const d = duration(moment.duration(1, 'h').asMilliseconds())
d._string = '1h' // Normally is PT1H when moment is used
So it seems that rollups are sensitive to the string property?
Hi @jscottsf Here are a few tests for the duration code - https://github.com/esnet/pond/blob/master/packages/pond/tests/duration.test.ts
it("can construct one with a moment", () => {
const p = duration(moment.duration(24, "hours"));
expect(+p).toBe(86400000);
});
In your case, use it as duration(moment.duration(1, "hour"))
Actually, the duration itself is created correctly. It's that the duration created via a moment cannot be used in a fixedWindowRollup since the rollup produces an error.
Ah, okay. Got it. I'll look into it, thanks
@sartaj10 can you add a test or two to reproduce this?
I'm fairly sure this is the same bug - I was unable to produce a fixedWindowRollup with any_Durations, receiving the same error. (I'm on the latest Typescript alpha)
Modifying the Duration toString method to be:
toString(): string {
return `${this._duration}l`
}
Works for me.
The util.timeRangeFromIndexString function doesn't expect an ms time suffix.
The regex and timerange construction there could be modified to accept ms, or alternatively just passing exactly what it expects works?