Skip to content

Commit

Permalink
align method names
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
  • Loading branch information
mherwege committed Sep 13, 2023
1 parent f06b608 commit 10808d8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,8 @@ private static State internalSum(Item item, ZonedDateTime begin, @Nullable Zoned
* the given <code>timestamp</code>, or if there is a state but it is zero (which would cause a
* divide-by-zero error)
*/
public static DecimalType evolutionRate(Item item, ZonedDateTime timestamp) {
return evolutionRate(item, timestamp, getDefaultServiceId());
public static DecimalType evolutionRateSince(Item item, ZonedDateTime timestamp) {
return evolutionRateSince(item, timestamp, getDefaultServiceId());
}

/**
Expand All @@ -1050,8 +1050,8 @@ public static DecimalType evolutionRate(Item item, ZonedDateTime timestamp) {
* at the given interval, or if there is a state but it is zero (which would cause a
* divide-by-zero error)
*/
public static DecimalType evolutionRate(Item item, ZonedDateTime begin, ZonedDateTime end) {
return evolutionRate(item, begin, end, getDefaultServiceId());
public static DecimalType evolutionRateBetween(Item item, ZonedDateTime begin, ZonedDateTime end) {
return evolutionRateBetween(item, begin, end, getDefaultServiceId());
}

/**
Expand All @@ -1068,7 +1068,7 @@ public static DecimalType evolutionRate(Item item, ZonedDateTime begin, ZonedDat
* <code>serviceId</code>, or if there is a state but it is zero (which would cause a divide-by-zero
* error)
*/
public static @Nullable DecimalType evolutionRate(Item item, ZonedDateTime timestamp, String serviceId) {
public static @Nullable DecimalType evolutionRateSince(Item item, ZonedDateTime timestamp, String serviceId) {
HistoricItem itemThen = historicState(item, timestamp, serviceId);
DecimalType valueThen = (itemThen != null) ? itemThen.getState().as(DecimalType.class) : null;
DecimalType valueNow = getItemValue(item);
Expand All @@ -1095,7 +1095,7 @@ public static DecimalType evolutionRate(Item item, ZonedDateTime begin, ZonedDat
* given by <code>serviceId</code>, or if there is a state but it is zero (which would cause a
* divide-by-zero error)
*/
public static @Nullable DecimalType evolutionRate(Item item, ZonedDateTime begin, ZonedDateTime end,
public static @Nullable DecimalType evolutionRateBetween(Item item, ZonedDateTime begin, ZonedDateTime end,
String serviceId) {
HistoricItem itemStart = historicState(item, begin, serviceId);
HistoricItem itemStop = historicState(item, end, serviceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,45 +962,51 @@ public void testDeltaBetween() {
}

@Test
public void testEvolutionRate() {
public void testEvolutionRateSince() {
numberItem.setState(new DecimalType(2012));
DecimalType rate = PersistenceExtensions.evolutionRate(numberItem,
DecimalType rate = PersistenceExtensions.evolutionRateSince(numberItem,
ZonedDateTime.of(1940, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()), TestPersistenceService.ID);
assertThat(rate, is(nullValue()));

rate = PersistenceExtensions.evolutionRate(numberItem,
rate = PersistenceExtensions.evolutionRateSince(numberItem,
ZonedDateTime.of(2005, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()), TestPersistenceService.ID);
assertNotNull(rate);
// ((now - then) / then) * 100
assertThat(rate.doubleValue(), is(closeTo(0.349, 0.001)));

rate = PersistenceExtensions.evolutionRate(numberItem,
quantityItem.setState(new QuantityType<>(2012, SIUnits.CELSIUS));
rate = PersistenceExtensions.evolutionRateSince(quantityItem,
ZonedDateTime.of(2005, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()), TestPersistenceService.ID);
assertNotNull(rate);
// ((now - then) / then) * 100
assertThat(rate.doubleValue(), is(closeTo(0.349, 0.001)));

// default persistence service
rate = PersistenceExtensions.evolutionRateSince(numberItem,
ZonedDateTime.of(2005, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()));
assertThat(rate, is(nullValue()));
}

@Test
public void testEvolutionRateBetween() {
numberItem.setState(new DecimalType(2012));
DecimalType rate = PersistenceExtensions.evolutionRateBetween(numberItem,
ZonedDateTime.of(2005, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()),
ZonedDateTime.of(2011, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()), TestPersistenceService.ID);
assertNotNull(rate);
// ((now - then) / then) * 100
assertThat(rate.doubleValue(), is(closeTo(0.299, 0.001)));

quantityItem.setState(new QuantityType<>(2012, SIUnits.CELSIUS));
rate = PersistenceExtensions.evolutionRate(quantityItem,
ZonedDateTime.of(2005, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()), TestPersistenceService.ID);
assertNotNull(rate);
// ((now - then) / then) * 100
assertThat(rate.doubleValue(), is(closeTo(0.349, 0.001)));

rate = PersistenceExtensions.evolutionRate(quantityItem,
rate = PersistenceExtensions.evolutionRateBetween(quantityItem,
ZonedDateTime.of(2005, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()),
ZonedDateTime.of(2011, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()), TestPersistenceService.ID);
assertNotNull(rate);
// ((now - then) / then) * 100
assertThat(rate.doubleValue(), is(closeTo(0.299, 0.001)));

// default persistence service
rate = PersistenceExtensions.evolutionRate(numberItem,
ZonedDateTime.of(2005, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()));
assertThat(rate, is(nullValue()));

rate = PersistenceExtensions.evolutionRate(numberItem,
rate = PersistenceExtensions.evolutionRateBetween(numberItem,
ZonedDateTime.of(2005, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()),
ZonedDateTime.of(2011, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()));
assertThat(rate, is(nullValue()));
Expand Down

0 comments on commit 10808d8

Please sign in to comment.