Skip to content

Commit 91fe22a

Browse files
Consolidate deficits for-loops
Merge the two separate for-loops that iterated over the deficits items in `_distribute_power()`. It was determined that iterating twice over the deficits items is unnecessary. As a result, the two loops have been now consolidated into a single loop maintaining its functionality. Signed-off-by: Daniel Zullo <[email protected]>
1 parent fdd9e27 commit 91fe22a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/frequenz/sdk/power/_distribution_algorithm.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,19 +412,17 @@ def _distribute_power( # pylint: disable=too-many-arguments
412412
deficit += excess_reserved[take_from[0]]
413413
deficits[inverter_id] = deficit
414414
excess_reserved[take_from[0]] = 0.0
415-
416-
for inverter_id, excess in excess_reserved.items():
417-
distribution[inverter_id] += excess
418-
distributed_power += excess
419-
420-
for inverter_id, deficit in deficits.items():
421415
if deficit < -0.1:
422416
left_over = power_w - distributed_power
423417
if left_over > -deficit:
424418
distributed_power += deficit
425419
elif left_over > 0.0:
426420
distributed_power += left_over
427421

422+
for inverter_id, excess in excess_reserved.items():
423+
distribution[inverter_id] += excess
424+
distributed_power += excess
425+
428426
left_over = power_w - distributed_power
429427
dist = DistributionResult(distribution, left_over)
430428

0 commit comments

Comments
 (0)