Refactor fix hour tariff price calculation for quarter hours#3145
Refactor fix hour tariff price calculation for quarter hours#3145tpd-opitz wants to merge 12 commits intoopenWB:masterfrom
Conversation
6f0fe50 to
1293739
Compare
765bf4e to
bf1def5
Compare
bf1def5 to
f02d728
Compare
a93b40a to
0493f0b
Compare
| bereits ein festes Netzentgeld enthalten. | ||
| ''' | ||
| grid_fee_prices = __reduce_prices(grid_fee_prices) | ||
| grid_fee_prices = {int(float(k)): v for k, v in grid_fee_prices.items() if int(float(k)) <= max_timestamp} |
There was a problem hiding this comment.
Die Absicht war hier, die Liste der Netzentgeldpreise auf die Länge der Preissumme zu kürzen, damit sie die Darstellung im PreisChart der Statusseite nicht verzerrt. Für die Berechnungen wäre das nicht notwendig.
Leider funktioniert das nicht zuverlässig, aber openWB/openwb-ui-settings#905 wird das Problem beheben.
| if (hasattr(data.data.optional_data.grid_fee_module.config, "default_price") and | ||
| data.data.optional_data.grid_fee_module.config.default_price is not None): | ||
| print("Using default grid fee price from configuration: " + | ||
| f"{data.data.optional_data.grid_fee_module.config.default_price}") | ||
| return data.data.optional_data.grid_fee_module.config.default_price | ||
| else: | ||
| # Fallback: Median der vorhandenen Netzentgelte wird | ||
| # als Schätzung für das Standard-Netzentgelt verwenden | ||
| distinct_grid_fee_values = sorted(set(prices.values())) | ||
| return ( | ||
| distinct_grid_fee_values[len(distinct_grid_fee_values) // 2] | ||
| if distinct_grid_fee_values else 0) |
There was a problem hiding this comment.
Bedeutet das, das für alle Module, die nicht default_price implementieren, ein vom Backend ermittelter Wert von den abgefragten Preisen abgezogen wird?
There was a problem hiding this comment.
ja.
Die Alternative wäre, wie vorher die Netzentgelte stumpf drauf zuschlagen, was zu deutlich größeren Abweichungen führen würde.
| try: | ||
| with SingleComponentUpdateContext(self.fault_state): | ||
| tariff_state, timeslot_length_seconds = self.__update_et_provider_data() | ||
| self.__store_and_publish_updated_data(tariff_state) | ||
| self.__log_and_publish_progress(timeslot_length_seconds, tariff_state) | ||
| except Exception as e: | ||
| log.exception(f"Fehler beim Aktualisieren der Tarifdaten {e}") | ||
| self.fault_state.warning("Error updating tariff data, retry in 5 minutes") |
There was a problem hiding this comment.
| try: | |
| with SingleComponentUpdateContext(self.fault_state): | |
| tariff_state, timeslot_length_seconds = self.__update_et_provider_data() | |
| self.__store_and_publish_updated_data(tariff_state) | |
| self.__log_and_publish_progress(timeslot_length_seconds, tariff_state) | |
| except Exception as e: | |
| log.exception(f"Fehler beim Aktualisieren der Tarifdaten {e}") | |
| self.fault_state.warning("Error updating tariff data, retry in 5 minutes") | |
| with SingleComponentUpdateContext(self.fault_state): | |
| tariff_state, timeslot_length_seconds = self.__update_et_provider_data() | |
| self.__store_and_publish_updated_data(tariff_state) | |
| self.__log_and_publish_progress(timeslot_length_seconds, tariff_state) |
Fehlermeldungen werden so verschluckt und der nachfolgende Code weiß nicht, dass ein Fehler aufgetreten ist.
There was a problem hiding this comment.
Das Verschlucken ist hier OK, weil ja Preise vorhanden sind und der nachfolgende Code weiter arbeiten kann. Der Fehler wird im Status angezeigt.
|
@copilot |
|
Ich glaube, so funktioniert das noch nicht. Habe das Review manuell angestoßen. |
There was a problem hiding this comment.
Pull request overview
This pull request refactors the fixed hour tariff price calculation to use 15-minute intervals instead of hourly intervals, harmonizing it with dynamic tariffs. The changes introduce independent update mechanisms for electricity pricing and grid fees, with separate MQTT topics for next_query_time tracking. The implementation includes logic to handle grid fees that may already be included in flexible tariff prices by subtracting the median grid fee value.
Changes:
- Refactored fixed hours tariff to generate prices in 15-minute intervals for 36 hours ahead
- Introduced separate next_query_time tracking for flexible tariff and grid fee modules with dedicated MQTT topics
- Implemented grid fee normalization logic that subtracts median grid fee when tariffs include grid fees
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/modules/loadvars.py | Changed price update trigger condition from checking next_query_time to checking configured status |
| packages/modules/electricity_pricing/flexible_tariffs/tibber/config.py | Added update_hours and includes_grid_fee configuration attributes |
| packages/modules/electricity_pricing/flexible_tariffs/ostrom/config.py | Added update_hours configuration for multiple daily updates |
| packages/modules/electricity_pricing/flexible_tariffs/fixed_hours/tariff_test.py | Added comprehensive test suite for quarter-hour price calculations |
| packages/modules/electricity_pricing/flexible_tariffs/fixed_hours/tariff.py | Refactored to generate prices in 15-minute intervals for 36 hours with corrected return type |
| packages/modules/electricity_pricing/flexible_tariffs/fixed_hours/config.py | Added update_hours configuration to enable all-day updates |
| packages/modules/configuration.py | Enhanced exception logging with path information |
| packages/modules/common/store/_tariff_test.py | Extended tests to cover grid fee normalization and quarter-hour alignment |
| packages/modules/common/store/_tariff.py | Implemented grid fee price normalization and improved price summing logic |
| packages/modules/common/configurable_tariff.py | Refactored to support independent tariff updates with per-module next_query_time calculation |
| packages/helpermodules/setdata.py | Moved next_query_time validation to per-module topics |
| packages/control/optional_test.py | Updated tests to support separate flexible_tariff and grid_fee tracking |
| packages/control/optional_data.py | Moved next_query_time from global to per-module PricingGet dataclass |
| packages/control/optional.py | Refactored price update logic to support independent module updates |
Comments suppressed due to low confidence (1)
packages/control/optional.py:174
- The return value type is inconsistent with the return type annotation. The function is annotated to return
int, but line 174 returnsfloat(timestamp)which is a float. The return type should either be changed tofloator the conversion should be removed.
def __get_current_timeslot_start(self) -> int:
timestamp = self.__get_first_entry()[0]
return float(timestamp)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/modules/electricity_pricing/flexible_tariffs/fixed_hours/tariff_test.py
Show resolved
Hide resolved
packages/modules/electricity_pricing/flexible_tariffs/fixed_hours/tariff.py
Outdated
Show resolved
Hide resolved
913053a to
0bec238
Compare
…query time calculation
harmonize fixed hours tariff with dynamic tariffs by shortening the intervals and extending end to (next) day
0bec238 to
6486cc9
Compare
harmonize fixed hours tariff with dynamic tariffs
backend updates are done via MQTT listener in optional_data.py
known issue
see forum