-
Notifications
You must be signed in to change notification settings - Fork 121
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 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.
No description provided.