IOT-DSA/sdk-dslink-dart

Rollup algorithm doesn't look good for me

Opened this issue · 0 comments

await for (ValuePair pair in fetchHistoryData(range)) {
rollup.add(pair.value);
if (lastTimestamp != -1) {
totalTime += pair.time.millisecondsSinceEpoch - lastTimestamp;
}
lastTimestamp = pair.time.millisecondsSinceEpoch;
if (totalTime >= interval.inMilliseconds) {
totalTime = 0;
result = new ValuePair(
new DateTime.fromMillisecondsSinceEpoch(
lastTimestamp
).toIso8601String(),
rollup.value
);
yield result;
result = null;
rollup.reset();
}
}

What I don't like

  1. if point out of interval, it gets included into interval
  2. beginning of the next interval is last point not included in the previous interval
  3. lastTimestamp goes to the result