Skip to content

Fix Energy Mix Berechnung - #3903

Open
AlexanderHa98 wants to merge 4 commits into
openWB:masterfrom
AlexanderHa98:fix_energy_mix
Open

Fix Energy Mix Berechnung#3903
AlexanderHa98 wants to merge 4 commits into
openWB:masterfrom
AlexanderHa98:fix_energy_mix

Conversation

@AlexanderHa98

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

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
AlexanderHa98 marked this pull request as ready for review September 7, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants