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

Amend deficit calculation in the power distributor #577

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions src/frequenz/sdk/power/_distribution_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,32 +404,24 @@ def _distribute_power( # pylint: disable=too-many-arguments
take_from = max(excess_reserved.items(), key=lambda item: item[1])
if is_close_to_zero(take_from[1]) or take_from[1] < 0.0:
break
if take_from[1] >= -deficit or math.isclose(
take_from[1], -deficit, abs_tol=1e-6
):
if take_from[1] >= -deficit or math.isclose(take_from[1], -deficit):
excess_reserved[take_from[0]] += deficit
deficits[inverter_id] = 0.0
deficit = 0.0
else:
deficit += excess_reserved[take_from[0]]
deficits[inverter_id] = deficit
excess_reserved[take_from[0]] = 0.0

for inverter_id, excess in excess_reserved.items():
distribution[inverter_id] += excess
distributed_power += excess

for inverter_id, deficit in deficits.items():
if deficit < -0.1:
left_over = power_w - distributed_power
if left_over > -deficit:
distributed_power += deficit
deficit = 0.0
deficits[inverter_id] = 0.0
elif left_over > 0.0:
deficit += left_over
distributed_power += left_over
deficits[inverter_id] = deficit

for inverter_id, excess in excess_reserved.items():
distribution[inverter_id] += excess
distributed_power += excess

left_over = power_w - distributed_power
dist = DistributionResult(distribution, left_over)
Expand Down