Skip to content

Commit

Permalink
[rrd4j] Reuse the state for identical values (openhab#16379)
Browse files Browse the repository at this point in the history
Signed-off-by: Jörg Sautter <joerg.sautter@gmx.net>
Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
  • Loading branch information
joerg1985 authored and austvik committed Mar 27, 2024
1 parent 2dc420b commit 283c884
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,21 @@ public Iterable<HistoricItem> query(FilterCriteria filter) {
long ts = result.getFirstTimestamp();
ZonedDateTime zdt = ZonedDateTime.ofInstant(Instant.ofEpochSecond(ts), ZoneId.systemDefault());
long step = result.getRowCount() > 1 ? result.getStep() : 0;

double prevValue = Double.NaN;
State prevState = null;
for (double value : result.getValues(DATASOURCE_STATE)) {
if (!Double.isNaN(value) && (((ts >= start) && (ts <= end)) || (start == end))) {
RRD4jItem rrd4jItem = new RRD4jItem(itemName, toState.apply(value), zdt);
State state;

if (prevValue == value) {
state = prevState;
} else {
prevState = state = toState.apply(value);
prevValue = value;
}

RRD4jItem rrd4jItem = new RRD4jItem(itemName, state, zdt);
items.add(rrd4jItem);
}
zdt = zdt.plusSeconds(step);
Expand Down

0 comments on commit 283c884

Please sign in to comment.