Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[energidataservice] Define grid tariff filters in YAML #17690

Merged
merged 1 commit into from
Nov 10, 2024

Conversation

jlaur
Copy link
Contributor

@jlaur jlaur commented Nov 2, 2024

This should make grid tariff filters more readable and therefore easier to maintain.

The current draft is a baseline providing only the same functionality as with the filters provided by code. The next step is to add support for periodization.

With the introduction of #16656, historic tariffs can be persisted. When grid company make changes to the way they publish tariffs, filters need to be adapted. This can include moving a cutoff date and querying new charge code types and notes. Without periodization of the filters, it's not possible to persist historic tariffs. Additionally, it's not possible to take into account upcoming filter changes.

@jlaur jlaur added enhancement An enhancement or new feature for an existing add-on rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Nov 2, 2024
@jlaur jlaur force-pushed the energidataservice-filters branch from 5163721 to 149a162 Compare November 6, 2024 19:12
@jlaur jlaur added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Nov 6, 2024
@jlaur
Copy link
Contributor Author

jlaur commented Nov 6, 2024

I'm marking this ready for review now, even though it's only the "middle" step/baseline. Tariff definitions are now in YAML, but periodization is not yet supported.

It's a bit more complicated than I initially thought. For example, when a console command requests persistence of period 01.01.2024-31.01.2024 and the tariff filter is changed per 16.01.2024, we need to calculate intersecting periods and handle them individually:

  • 01.01.2024-15.01.2024
  • 16.01.2024-31.01.2024

This needs to be rewritten:

DatahubTariffFilter filter = getDatahubTariffFilter(datahubTariff);
DateQueryParameter start = filter.getStart();
DateQueryParameterType filterStartDateType = start.getDateType();
LocalDate filterStartDate = start.getDate();
if (filterStartDateType != null) {
// For filters with date relative to current date, override with provided parameters.
filter = new DatahubTariffFilter(filter, DateQueryParameter.of(startDate), DateQueryParameter.of(endDate));
} else if (filterStartDate != null && startDate.isBefore(filterStartDate)) {
throw new IllegalArgumentException("Start date before " + start.getDate() + " is not supported");
}
Collection<DatahubPricelistRecord> datahubRecords = downloadPriceLists(globalLocationNumber, filter);
ZoneId zoneId = timeZoneProvider.getTimeZone();
Instant firstHourStart = startDate.atStartOfDay(zoneId).toInstant();
Instant lastHourStart = endDate.plusDays(1).atStartOfDay(zoneId).toInstant();
Map<Instant, BigDecimal> tariffMap = new PriceListParser().toHourly(datahubRecords, firstHourStart,
lastHourStart);

And this also needs to be more sophisticated:

private boolean downloadTariffs(DatahubPriceSubscription subscription, boolean force)
throws InterruptedException, DataServiceException {
GlobalLocationNumber globalLocationNumber = subscription.getGlobalLocationNumber();
if (globalLocationNumber.isEmpty()) {
return false;
}
DatahubPriceSubscriptionCache cache = getDatahubPriceSubscriptionDataCache(subscription);
if (!force && cache.areTariffsValidTomorrow()) {
logger.debug("Cached tariffs of type {} still valid, skipping download.", subscription.getDatahubTariff());
cache.update();
return false;
} else {
return cache.put(downloadPriceLists(subscription));
}
}

All in all, it requires more work and testing.

I still think using YAML even without periodization is an improvement in its own right.

@jlaur jlaur marked this pull request as ready for review November 6, 2024 19:27
@jlaur
Copy link
Contributor Author

jlaur commented Nov 10, 2024

@lsiepel - any chance of giving this some mileage with M3? 😉

@lsiepel
Copy link
Contributor

lsiepel commented Nov 10, 2024

@lsiepel - any chance of giving this some mileage with M3? 😉

Would have been nice, but Kai can start the build any moment, so better to not frustrate the build proces.

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks LGTM

@lsiepel lsiepel merged commit d918c20 into openhab:main Nov 10, 2024
5 checks passed
@lsiepel lsiepel added this to the 4.3 milestone Nov 10, 2024
matchews pushed a commit to matchews/openhab-addons that referenced this pull request Dec 16, 2024
cipianpascu pushed a commit to cipianpascu/openhab-addons that referenced this pull request Jan 2, 2025
Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Ciprian Pascu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants