Skip to content

Commit

Permalink
Extend cached history to 24 hours
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur committed Jun 16, 2023
1 parent 68b7487 commit 4d00b22
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@NonNullByDefault
public class CacheManager {

public static final int NUMBER_OF_HISTORIC_HOURS = 12;
public static final int NUMBER_OF_HISTORIC_HOURS = 24;
public static final int SPOT_PRICE_MAX_CACHE_SIZE = 24 + 11 + NUMBER_OF_HISTORIC_HOURS;
public static final int TARIFF_MAX_CACHE_SIZE = 24 * 2 + NUMBER_OF_HISTORIC_HOURS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class CacheManagerTest {
@Test
void areSpotPricesFullyCachedToday() {
Instant now = Instant.parse("2023-02-07T08:38:47Z");
Instant first = Instant.parse("2023-02-06T20:00:00Z");
Instant first = Instant.parse("2023-02-06T08:00:00Z");
Instant last = Instant.parse("2023-02-07T22:00:00Z");
Clock clock = Clock.fixed(now, EnergiDataServiceBindingConstants.NORD_POOL_TIMEZONE);
CacheManager cacheManager = new CacheManager(clock);
Expand Down Expand Up @@ -73,7 +73,7 @@ void areSpotPricesFullyCachedTodayMissingAtEnd() {
@Test
void areSpotPricesFullyCachedTodayOtherTimezoneIsIgnored() {
Instant now = Instant.parse("2023-02-07T08:38:47Z");
Instant first = Instant.parse("2023-02-06T20:00:00Z");
Instant first = Instant.parse("2023-02-06T08:00:00Z");
Instant last = Instant.parse("2023-02-07T22:00:00Z");
Clock clock = Clock.fixed(now, ZoneId.of("Asia/Tokyo"));
CacheManager cacheManager = new CacheManager(clock);
Expand All @@ -84,7 +84,7 @@ void areSpotPricesFullyCachedTodayOtherTimezoneIsIgnored() {
@Test
void areSpotPricesFullyCachedTomorrow() {
Instant now = Instant.parse("2023-02-07T12:00:00Z");
Instant first = Instant.parse("2023-02-07T00:00:00Z");
Instant first = Instant.parse("2023-02-06T12:00:00Z");
Instant last = Instant.parse("2023-02-08T22:00:00Z");
Clock clock = Clock.fixed(now, EnergiDataServiceBindingConstants.NORD_POOL_TIMEZONE);
CacheManager cacheManager = new CacheManager(clock);
Expand All @@ -95,7 +95,7 @@ void areSpotPricesFullyCachedTomorrow() {
@Test
void areHistoricSpotPricesCached() {
Instant now = Instant.parse("2023-02-07T08:38:47Z");
Instant first = Instant.parse("2023-02-06T20:00:00Z");
Instant first = Instant.parse("2023-02-06T08:00:00Z");
Instant last = Instant.parse("2023-02-07T07:00:00Z");
Clock clock = Clock.fixed(now, EnergiDataServiceBindingConstants.NORD_POOL_TIMEZONE);
CacheManager cacheManager = new CacheManager(clock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void toHourlyNoChanges() throws IOException {
DatahubPricelistRecords records = getObjectFromJson("DatahubPricelistN1.json", DatahubPricelistRecords.class);
Map<Instant, BigDecimal> tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList());

assertThat(tariffMap.size(), is(48));
assertThat(tariffMap.size(), is(60));
assertThat(tariffMap.get(Instant.parse("2023-01-23T15:00:00Z")), is(equalTo(new BigDecimal("0.432225"))));
assertThat(tariffMap.get(Instant.parse("2023-01-23T16:00:00Z")), is(equalTo(new BigDecimal("1.05619"))));
assertThat(tariffMap.get(Instant.parse("2023-01-24T15:00:00Z")), is(equalTo(new BigDecimal("0.432225"))));
Expand All @@ -85,7 +85,7 @@ void toHourlyNewTariffTomorrowWhenSummertime() throws IOException {
DatahubPricelistRecords records = getObjectFromJson("DatahubPricelistN1.json", DatahubPricelistRecords.class);
Map<Instant, BigDecimal> tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList());

assertThat(tariffMap.size(), is(48));
assertThat(tariffMap.size(), is(60));
assertThat(tariffMap.get(Instant.parse("2023-03-31T14:00:00Z")), is(equalTo(new BigDecimal("0.432225"))));
assertThat(tariffMap.get(Instant.parse("2023-03-31T15:00:00Z")), is(equalTo(new BigDecimal("1.05619"))));
assertThat(tariffMap.get(Instant.parse("2023-04-01T14:00:00Z")), is(equalTo(new BigDecimal("0.432225"))));
Expand All @@ -99,7 +99,7 @@ void toHourlyNewTariffAtMidnight() throws IOException {
DatahubPricelistRecords records = getObjectFromJson("DatahubPricelistN1.json", DatahubPricelistRecords.class);
Map<Instant, BigDecimal> tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList(), "CD");

assertThat(tariffMap.size(), is(48));
assertThat(tariffMap.size(), is(60));
assertThat(tariffMap.get(Instant.parse("2022-12-31T22:00:00Z")), is(equalTo(new BigDecimal("0.407717"))));
assertThat(tariffMap.get(Instant.parse("2022-12-31T23:00:00Z")), is(equalTo(new BigDecimal("0.432225"))));
assertThat(tariffMap.get(Instant.parse("2023-01-01T00:00:00Z")), is(equalTo(new BigDecimal("0.432225"))));
Expand All @@ -113,7 +113,7 @@ void toHourlyDiscount() throws IOException {
Map<Instant, BigDecimal> tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList(),
"CD R");

assertThat(tariffMap.size(), is(48));
assertThat(tariffMap.size(), is(60));
assertThat(tariffMap.get(Instant.parse("2022-12-31T22:00:00Z")), is(equalTo(new BigDecimal("-0.407717"))));
assertThat(tariffMap.get(Instant.parse("2022-12-31T23:00:00Z")), is(equalTo(new BigDecimal("0.0"))));
assertThat(tariffMap.get(Instant.parse("2023-01-01T00:00:00Z")), is(equalTo(new BigDecimal("0.0"))));
Expand All @@ -126,7 +126,7 @@ void toHourlyTariffAndDiscountIsSum() throws IOException {
DatahubPricelistRecords records = getObjectFromJson("DatahubPricelistN1.json", DatahubPricelistRecords.class);
Map<Instant, BigDecimal> tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList());

assertThat(tariffMap.size(), is(45));
assertThat(tariffMap.size(), is(57));
assertThat(tariffMap.get(Instant.parse("2022-11-30T15:00:00Z")), is(equalTo(new BigDecimal("0.387517"))));
assertThat(tariffMap.get(Instant.parse("2022-11-30T16:00:00Z")), is(equalTo(new BigDecimal("0.973404"))));
}
Expand All @@ -138,7 +138,7 @@ void toHourlyTariffAndDiscountIsFree() throws IOException {
DatahubPricelistRecords records = getObjectFromJson("DatahubPricelistN1.json", DatahubPricelistRecords.class);
Map<Instant, BigDecimal> tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList());

assertThat(tariffMap.size(), is(48));
assertThat(tariffMap.size(), is(60));
assertThat(tariffMap.get(Instant.parse("2022-12-31T16:00:00Z")), is(equalTo(new BigDecimal("0.000000"))));
assertThat(tariffMap.get(Instant.parse("2022-12-31T22:00:00Z")), is(equalTo(new BigDecimal("0.000000"))));
assertThat(tariffMap.get(Instant.parse("2022-12-31T23:00:00Z")), is(equalTo(new BigDecimal("0.432225"))));
Expand Down Expand Up @@ -168,7 +168,7 @@ void toHourlyDailyTariffs() throws IOException {
DatahubPricelistRecords.class);
Map<Instant, BigDecimal> tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList());

assertThat(tariffMap.size(), is(56));
assertThat(tariffMap.size(), is(68));
assertThat(tariffMap.get(Instant.parse("2023-01-28T04:00:00Z")), is(equalTo(new BigDecimal("0.2581"))));
assertThat(tariffMap.get(Instant.parse("2023-01-28T05:00:00Z")), is(equalTo(new BigDecimal("0.7742"))));
assertThat(tariffMap.get(Instant.parse("2023-01-28T16:00:00Z")), is(equalTo(new BigDecimal("2.3227"))));
Expand All @@ -187,7 +187,7 @@ void toHourlySystemTariff() throws IOException {
DatahubPricelistRecords.class);
Map<Instant, BigDecimal> tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList());

assertThat(tariffMap.size(), is(39));
assertThat(tariffMap.size(), is(51));
assertThat(tariffMap.get(Instant.parse("2023-06-30T21:00:00Z")), is(equalTo(new BigDecimal("0.008"))));
assertThat(tariffMap.get(Instant.parse("2023-06-30T22:00:00Z")), is(equalTo(new BigDecimal("0.697"))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void getPricesNetTariff() throws IOException {
mockCommonDatasets(actions);

Map<Instant, BigDecimal> actual = actions.getPrices("NetTariff");
assertThat(actual.size(), is(48));
assertThat(actual.size(), is(60));
assertThat(actual.get(Instant.parse("2023-02-04T12:00:00Z")), is(equalTo(new BigDecimal("0.432225"))));
assertThat(actual.get(Instant.parse("2023-02-04T16:00:00Z")), is(equalTo(new BigDecimal("1.05619"))));
}
Expand All @@ -122,7 +122,7 @@ void getPricesSystemTariff() throws IOException {
mockCommonDatasets(actions);

Map<Instant, BigDecimal> actual = actions.getPrices("SystemTariff");
assertThat(actual.size(), is(48));
assertThat(actual.size(), is(60));
assertThat(actual.get(Instant.parse("2023-02-04T12:00:00Z")), is(equalTo(new BigDecimal("0.054"))));
assertThat(actual.get(Instant.parse("2023-02-04T16:00:00Z")), is(equalTo(new BigDecimal("0.054"))));
}
Expand All @@ -132,7 +132,7 @@ void getPricesElectricityTax() throws IOException {
mockCommonDatasets(actions);

Map<Instant, BigDecimal> actual = actions.getPrices("ElectricityTax");
assertThat(actual.size(), is(48));
assertThat(actual.size(), is(60));
assertThat(actual.get(Instant.parse("2023-02-04T12:00:00Z")), is(equalTo(new BigDecimal("0.008"))));
assertThat(actual.get(Instant.parse("2023-02-04T16:00:00Z")), is(equalTo(new BigDecimal("0.008"))));
}
Expand All @@ -142,7 +142,7 @@ void getPricesTransmissionNetTariff() throws IOException {
mockCommonDatasets(actions);

Map<Instant, BigDecimal> actual = actions.getPrices("TransmissionNetTariff");
assertThat(actual.size(), is(48));
assertThat(actual.size(), is(60));
assertThat(actual.get(Instant.parse("2023-02-04T12:00:00Z")), is(equalTo(new BigDecimal("0.058"))));
assertThat(actual.get(Instant.parse("2023-02-04T16:00:00Z")), is(equalTo(new BigDecimal("0.058"))));
}
Expand Down

0 comments on commit 4d00b22

Please sign in to comment.