Skip to content

Commit 3c17ac3

Browse files
committed
Use floating point constants in floating point calculations
This helps better leverage the new instruction specialization feature of Python. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent ea42350 commit 3c17ac3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/frequenz/sdk/timeseries/battery_pool/_metric_calculator.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ def calculate(
363363
Return None if there are no component metrics.
364364
"""
365365
timestamp = _MIN_TIMESTAMP
366-
usable_capacity_x100: float = 0
367-
used_capacity_x100: float = 0
368-
total_capacity_x100: float = 0
366+
usable_capacity_x100: float = 0.0
367+
used_capacity_x100: float = 0.0
368+
total_capacity_x100: float = 0.0
369369

370370
for battery_id in working_batteries:
371371
if battery_id not in metrics_data:
@@ -397,10 +397,10 @@ def calculate(
397397
# Therefore, the variables are named with a `_x100` suffix.
398398
usable_capacity_x100 = capacity * (soc_upper_bound - soc_lower_bound)
399399
soc_scaled = (
400-
(soc - soc_lower_bound) / (soc_upper_bound - soc_lower_bound) * 100
400+
(soc - soc_lower_bound) / (soc_upper_bound - soc_lower_bound) * 100.0
401401
)
402402
# we are clamping here because the SoC might be out of bounds
403-
soc_scaled = min(max(soc_scaled, 0), 100)
403+
soc_scaled = min(max(soc_scaled, 0.0), 100.0)
404404
timestamp = max(timestamp, metrics.timestamp)
405405
used_capacity_x100 += usable_capacity_x100 * soc_scaled
406406
total_capacity_x100 += usable_capacity_x100

0 commit comments

Comments
 (0)