Fix Energy Mix Berechnung - #3903
Open
AlexanderHa98 wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new allocation logic can silently ignore unassigned grid export/battery import amounts, which can produce incorrect energy source shares for certain meter readings.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adjusts how the “Strom-Mix” (energy source shares) is calculated in analyse_percentage() by redistributing grid export and battery import according to defined priority rules, and adds targeted unit tests to validate the new distribution behavior.
Changes:
- Reworked energy source share calculation to (a) attribute grid export to PV/Battery/CP by priority and (b) attribute battery import to PV/Grid/CP by priority before computing source shares.
- Added new unit tests covering combined export/import scenarios and validating the resulting shares sum to ~100%.
File summaries
| File | Description |
|---|---|
| packages/helpermodules/measurement_logging/process_log.py | Updates the energy mix calculation logic in analyse_percentage() (priority-based export/import attribution). |
| packages/helpermodules/measurement_logging/process_log_unit_test.py | Adds unit tests for the new proportional/priority-based distribution logic and sanity-checks totals. |
Review details
Suppressed comments (1)
packages/helpermodules/measurement_logging/process_log.py:479
- If grid_exported is larger than the sum of pv/bat/cp exports (or bat_imported larger than the available pv/grid/cp after adjustments), the remainder stays in unassigned_* and is silently ignored, which can skew the computed shares because direct_total no longer matches the consumption formula. Consider assigning any remaining unassigned amount to the grid portion (as a last resort) so the totals stay consistent.
# Einspeißung aufteilen
unassigned_export = grid_exported
for source in ("pv", "bat", "cp"):
if direct[source] > unassigned_export:
direct[source] -= unassigned_export
break
else:
unassigned_export -= direct[source]
direct[source] = 0
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+448
to
+452
| """ | ||
| Berechnung der Energiequellenanteile: | ||
| Da die genaue Aufteilung der Energiequellen nicht bekannt ist, | ||
| wird die Einspeißung (grid_exported) entsprechend der folgenden Priorität aufgeteilt: | ||
| 1. PV |
AlexanderHa98
marked this pull request as ready for review
September 7, 2026 12:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.