PersistenceExtensions { public static DecimalType averageSince(Item item, ZonedDateTime timestamp) { return averageSince(item, timestamp, getDefaultServiceId()); } @Activate  PersistenceExtensions(@Reference PersistenceServiceRegistry registry); static void persist(Item item, String serviceId); static void persist(Item item); static HistoricItem historicState(Item item, ZonedDateTime timestamp); static HistoricItem historicState(Item item, ZonedDateTime timestamp, String serviceId); static Boolean changedSince(Item item, ZonedDateTime timestamp); static Boolean changedSince(Item item, ZonedDateTime timestamp, String serviceId); static Boolean updatedSince(Item item, ZonedDateTime timestamp); static Boolean updatedSince(Item item, ZonedDateTime timestamp, String serviceId); static HistoricItem maximumSince(Item item, ZonedDateTime timestamp); static HistoricItem maximumSince(final Item item, ZonedDateTime timestamp, String serviceId); static HistoricItem minimumSince(Item item, ZonedDateTime timestamp); static HistoricItem minimumSince(final Item item, ZonedDateTime timestamp, String serviceId); static DecimalType varianceSince(Item item, ZonedDateTime timestamp); static DecimalType varianceSince(Item item, ZonedDateTime timestamp, String serviceId); static DecimalType deviationSince(Item item, ZonedDateTime timestamp); static DecimalType deviationSince(Item item, ZonedDateTime timestamp, String serviceId); static DecimalType averageSince(Item item, ZonedDateTime timestamp); static DecimalType averageSince(Item item, ZonedDateTime timestamp, String serviceId); static DecimalType sumSince(Item item, ZonedDateTime timestamp); static DecimalType sumSince(Item item, ZonedDateTime timestamp, String serviceId); static ZonedDateTime lastUpdate(Item item); static ZonedDateTime lastUpdate(Item item, String serviceId); static DecimalType deltaSince(Item item, ZonedDateTime timestamp); static DecimalType deltaSince(Item item, ZonedDateTime timestamp, String serviceId); static DecimalType evolutionRate(Item item, ZonedDateTime timestamp); static DecimalType evolutionRate(Item item, ZonedDateTime timestamp, String serviceId); static HistoricItem previousState(Item item); static HistoricItem previousState(Item item, boolean skipEqual); static HistoricItem previousState(Item item, boolean skipEqual, String serviceId);  }
@Test public void testAverageSince() { item.setState(new DecimalType(3025)); ZonedDateTime startStored = ZonedDateTime.of(2003, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()); ZonedDateTime endStored = ZonedDateTime.of(2012, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()); long storedInterval = endStored.toInstant().toEpochMilli() - startStored.toInstant().toEpochMilli(); long recentInterval = Instant.now().toEpochMilli() - endStored.toInstant().toEpochMilli(); double expected = (2007.4994 * storedInterval + 2518.5 * recentInterval) / (storedInterval + recentInterval); DecimalType average = PersistenceExtensions.averageSince(item, startStored, TestPersistenceService.ID); assertNotNull(average); assertEquals(expected, average.doubleValue(), 0.01); item.setState(new QuantityType<>(3025, SIUnits.CELSIUS)); average = PersistenceExtensions.averageSince(item, startStored, TestPersistenceService.ID); assertNotNull(average); assertEquals(expected, average.doubleValue(), 0.01); average = PersistenceExtensions.averageSince(item, startStored); assertNull(average); }