UI: fixed aggregation for entities table widget

This commit is contained in:
rusikv 2024-04-10 12:49:59 +03:00
parent 756bac5135
commit b19636111d

View File

@ -18,6 +18,7 @@ import { AggKey, IndexedSubscriptionData, } from '@app/shared/models/telemetry/t
import { import {
AggregationType, AggregationType,
calculateAggIntervalWithSubscriptionTimeWindow, calculateAggIntervalWithSubscriptionTimeWindow,
calculateInterval,
calculateIntervalComparisonEndTime, calculateIntervalComparisonEndTime,
calculateIntervalEndTime, calculateIntervalEndTime,
calculateIntervalStartEndTime, calculateIntervalStartEndTime,
@ -27,7 +28,7 @@ import {
SubscriptionTimewindow SubscriptionTimewindow
} from '@shared/models/time/time.models'; } from '@shared/models/time/time.models';
import { UtilsService } from '@core/services/utils.service'; import { UtilsService } from '@core/services/utils.service';
import { deepClone, isDefinedAndNotNull, isNumber, isNumeric } from '@core/utils'; import { deepClone, isDefined, isDefinedAndNotNull, isNumber, isNumeric } from '@core/utils';
import { DataEntry, DataSet, IndexedData } from '@shared/models/widget.models'; import { DataEntry, DataSet, IndexedData } from '@shared/models/widget.models';
import BTree from 'sorted-btree'; import BTree from 'sorted-btree';
import Timeout = NodeJS.Timeout; import Timeout = NodeJS.Timeout;
@ -63,9 +64,9 @@ class AggDataMap {
this.map.delete(ts); this.map.delete(ts);
} }
findDataForTs(ts: number): AggData | undefined { findDataForTs(ts: number, noAggregation: boolean): AggData | undefined {
if (ts >= this.endTs) { if (ts >= this.endTs) {
this.updateLastInterval(ts + 1); this.updateLastInterval(ts + 1, noAggregation);
} }
const pair = this.map.getPairOrNextLower(ts, this.reusePair); const pair = this.map.getPairOrNextLower(ts, this.reusePair);
if (pair) { if (pair) {
@ -78,16 +79,17 @@ class AggDataMap {
} }
calculateAggInterval(timestamp: number): [number, number] { calculateAggInterval(timestamp: number): [number, number] {
return calculateAggIntervalWithSubscriptionTimeWindow(this.subsTw, this.endTs, timestamp); return calculateInterval(this.subsTw.startTs, this.endTs, this.subsTw.aggregation.interval, this.subsTw.tsOffset, this.subsTw.timezone, timestamp);
} }
updateLastInterval(endTs: number) { updateLastInterval(endTs: number, noAggregation?: boolean) {
if (endTs > this.endTs) { if (endTs > this.endTs) {
this.endTs = endTs; this.endTs = endTs;
const lastTs = this.map.maxKey(); const lastTs = this.map.maxKey();
if (lastTs) { if (lastTs) {
const data = this.map.get(lastTs); const data = this.map.get(lastTs);
const interval = calculateAggIntervalWithSubscriptionTimeWindow(this.subsTw, endTs, data.ts); const interval = isDefined(noAggregation) && !noAggregation ? this.calculateAggInterval(data.ts) :
calculateAggIntervalWithSubscriptionTimeWindow(this.subsTw, endTs, data.ts);
data.interval = interval; data.interval = interval;
data.ts = interval[0] + Math.floor((interval[1] - interval[0]) / 2); data.ts = interval[0] + Math.floor((interval[1] - interval[0]) / 2);
} }
@ -454,7 +456,7 @@ export class DataAggregator {
keyData.forEach((kvPair) => { keyData.forEach((kvPair) => {
const timestamp = kvPair[0]; const timestamp = kvPair[0];
const value = DataAggregator.convertValue(kvPair[1], noAggregation); const value = DataAggregator.convertValue(kvPair[1], noAggregation);
let aggData = aggKeyData.findDataForTs(timestamp); let aggData = aggKeyData.findDataForTs(timestamp, noAggregation);
if (!aggData) { if (!aggData) {
let interval: [number, number] = [timestamp, timestamp]; let interval: [number, number] = [timestamp, timestamp];
if (!noAggregation) { if (!noAggregation) {