File tree Expand file tree Collapse file tree 3 files changed +7
-4
lines changed
src/frequenz/sdk/timeseries/battery_pool Expand file tree Collapse file tree 3 files changed +7
-4
lines changed Original file line number Diff line number Diff line change 2828
2929- Fix formatting issue for ` Quantity ` objects with zero values.
3030- Fix formatting isuse for ` Quantity ` when the base value is float.inf or float.nan.
31+ - Fix clamping to 100% for the battery pool SoC scaling calculation.
3132
3233<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
Original file line number Diff line number Diff line change @@ -424,7 +424,8 @@ def calculate(
424424 soc_scaled = (
425425 (soc - soc_lower_bound ) / (soc_upper_bound - soc_lower_bound ) * 100
426426 )
427- soc_scaled = max (soc_scaled , 0 )
427+ # we are clamping here because the SoC might be out of bounds
428+ soc_scaled = min (max (soc_scaled , 0 ), 100 )
428429 timestamp = max (timestamp , metrics .timestamp )
429430 used_capacity_x100 += usable_capacity_x100 * soc_scaled
430431 total_capacity_x100 += usable_capacity_x100
Original file line number Diff line number Diff line change @@ -347,16 +347,17 @@ def consumption_power(self) -> FormulaEngine[Power]:
347347 def soc (self ) -> MetricAggregator [Sample [Percentage ]]:
348348 """Fetch the normalized average weighted-by-capacity SoC values for the pool.
349349
350- The values are normalized to the 0-100% range.
350+ The values are normalized to the 0-100% range and clamped if the SoC is out of
351+ bounds.
351352
352353 Average soc is calculated with the formula:
353354 ```
354355 working_batteries: Set[BatteryData] # working batteries from the battery pool
355356
356- soc_scaled = max(
357+ soc_scaled = min( max(
357358 0,
358359 (soc - soc_lower_bound) / (soc_upper_bound - soc_lower_bound) * 100,
359- )
360+ ), 100)
360361 used_capacity = sum(
361362 battery.usable_capacity * battery.soc_scaled
362363 for battery in working_batteries
You can’t perform that action at this time.
0 commit comments