Fix issue with delta calculation when previous interval has no telemetry
This commit is contained in:
parent
b1a234eba2
commit
6674c457f6
@ -314,9 +314,9 @@ public class DefaultTbEntityDataSubscriptionService implements TbEntityDataSubsc
|
|||||||
ReadTsKvQueryInfo queryInfo = queries.get(queryResult.getQueryId());
|
ReadTsKvQueryInfo queryInfo = queries.get(queryResult.getQueryId());
|
||||||
ComparisonTsValue comparisonTsValue = entityData.getAggLatest().computeIfAbsent(queryInfo.getKey().getId(), agg -> new ComparisonTsValue());
|
ComparisonTsValue comparisonTsValue = entityData.getAggLatest().computeIfAbsent(queryInfo.getKey().getId(), agg -> new ComparisonTsValue());
|
||||||
if (queryInfo.isPrevious()) {
|
if (queryInfo.isPrevious()) {
|
||||||
comparisonTsValue.setPrevious(queryResult.toTsValue());
|
comparisonTsValue.setPrevious(queryResult.toTsValue(queryInfo.getQuery()));
|
||||||
} else {
|
} else {
|
||||||
comparisonTsValue.setCurrent(queryResult.toTsValue());
|
comparisonTsValue.setCurrent(queryResult.toTsValue(queryInfo.getQuery()));
|
||||||
lastTsMap.put(queryInfo.getQuery().getKey(), queryResult.getLastEntryTs());
|
lastTsMap.put(queryInfo.getQuery().getKey(), queryResult.getLastEntryTs());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,9 +42,14 @@ public class ReadTsKvQueryResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TsValue toTsValue() {
|
public TsValue toTsValue(ReadTsKvQuery query) {
|
||||||
if (data == null || data.isEmpty()) {
|
if (data == null || data.isEmpty()) {
|
||||||
return TsValue.EMPTY;
|
if (Aggregation.SUM.equals(query.getAggregation()) || Aggregation.COUNT.equals(query.getAggregation())) {
|
||||||
|
long ts = query.getStartTs() + (query.getEndTs() - query.getStartTs()) / 2;
|
||||||
|
return new TsValue(ts, "0");
|
||||||
|
} else {
|
||||||
|
return TsValue.EMPTY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (data.size() > 1) {
|
if (data.size() > 1) {
|
||||||
throw new RuntimeException("Query Result has multiple data points!");
|
throw new RuntimeException("Query Result has multiple data points!");
|
||||||
|
|||||||
@ -165,7 +165,11 @@ export class EntityDataSubscription {
|
|||||||
if (key.comparisonResultType === ComparisonResultType.DELTA_ABSOLUTE) {
|
if (key.comparisonResultType === ComparisonResultType.DELTA_ABSOLUTE) {
|
||||||
value = currentVal - prevVal;
|
value = currentVal - prevVal;
|
||||||
} else {
|
} else {
|
||||||
value = (currentVal - prevVal) / prevVal * 100;
|
if(prevVal === 0){
|
||||||
|
value = 100;
|
||||||
|
} else {
|
||||||
|
value = (currentVal - prevVal) / prevVal * 100;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = '';
|
value = '';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user