Skip to content

Commit 2afa1ba

Browse files
committed
Remove unused Metric types
Also move the relevant documentation back to the corresponding methods. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 4725b81 commit 2afa1ba

File tree

3 files changed

+31
-58
lines changed

3 files changed

+31
-58
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33

44
"""Manage a pool of batteries."""
55

6-
from ._result_types import Bound, CapacityMetrics, PowerMetrics, SoCMetrics
6+
from ._result_types import Bound, PowerMetrics
77
from .battery_pool import BatteryPool
88

99
__all__ = [
1010
"BatteryPool",
1111
"PowerMetrics",
12-
"SoCMetrics",
13-
"CapacityMetrics",
1412
"Bound",
1513
]

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

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,56 +18,6 @@ class Bound:
1818
"""Upper bound."""
1919

2020

21-
@dataclass
22-
class CapacityMetrics:
23-
"""Capacity metrics."""
24-
25-
# compare = False tells the dataclass to not use name for comparison methods
26-
timestamp: datetime = field(compare=False)
27-
"""Timestamp of the metrics,"""
28-
29-
total_capacity: float
30-
"""Total batteries capacity.
31-
32-
Calculated with the formula:
33-
```python
34-
working_batteries: Set[BatteryData] # working batteries from the battery pool
35-
total_capacity = sum(battery.capacity for battery in working_batteries)
36-
```
37-
"""
38-
39-
40-
@dataclass
41-
class SoCMetrics:
42-
"""Soc metrics."""
43-
44-
# compare = False tells the dataclass to not use name for comparison methods
45-
timestamp: datetime = field(compare=False)
46-
"""Timestamp of the metrics."""
47-
48-
average_soc: float
49-
"""Average SoC of working batteries in the pool, weighted by usable capacity.
50-
51-
The values are normalized to the 0-100% range.
52-
53-
Average soc is calculated with the formula:
54-
```python
55-
working_batteries: Set[BatteryData] # working batteries from the battery pool
56-
57-
battery.soc_scaled = max(
58-
0,
59-
(soc - soc_lower_bound) / (soc_upper_bound - soc_lower_bound) * 100,
60-
)
61-
used_capacity = sum(
62-
battery.usable_capacity * battery.soc_scaled
63-
for battery in working_batteries
64-
)
65-
total_capacity = sum(battery.usable_capacity for battery in working_batteries)
66-
average_soc = used_capacity/total_capacity
67-
```
68-
"""
69-
70-
7121
@dataclass
7222
class PowerMetrics:
7323
"""Power bounds metrics."""

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,26 @@ def consumption_power(self) -> FormulaEngine[Power]:
333333
def soc(self) -> MetricAggregator[Sample[Quantity]]:
334334
"""Fetch the normalized average weighted-by-capacity SoC values for the pool.
335335
336-
The formulas for calculating this metric are described
337-
[here][frequenz.sdk.timeseries.battery_pool.SoCMetrics]. `None` values will be
338-
sent if there are no components to calculate the metric with.
336+
The values are normalized to the 0-100% range.
337+
338+
Average soc is calculated with the formula:
339+
```
340+
working_batteries: Set[BatteryData] # working batteries from the battery pool
341+
342+
soc_scaled = max(
343+
0,
344+
(soc - soc_lower_bound) / (soc_upper_bound - soc_lower_bound) * 100,
345+
)
346+
used_capacity = sum(
347+
battery.usable_capacity * battery.soc_scaled
348+
for battery in working_batteries
349+
)
350+
total_capacity = sum(battery.usable_capacity for battery in working_batteries)
351+
average_soc = used_capacity/total_capacity
352+
```
353+
354+
`None` values will be sent if there are no components to calculate the metric
355+
with.
339356
340357
A receiver from the MetricAggregator can be obtained by calling the
341358
`new_receiver` method.
@@ -360,8 +377,16 @@ def soc(self) -> MetricAggregator[Sample[Quantity]]:
360377
def capacity(self) -> MetricAggregator[Sample[Energy]]:
361378
"""Get receiver to receive new capacity metrics when they change.
362379
363-
Capacity formulas are described in the receiver return type. None will be send
364-
if there is no component to calculate metrics.
380+
Calculated with the formula:
381+
```
382+
working_batteries: Set[BatteryData] # working batteries from the battery pool
383+
total_capacity = sum(
384+
battery.capacity * (soc_upper_bound - soc_lower_bound) / 100
385+
for battery in working_batteries
386+
)
387+
```
388+
389+
None will be send if there is no component to calculate metrics.
365390
366391
A receiver from the MetricAggregator can be obtained by calling the
367392
`new_receiver` method.

0 commit comments

Comments
 (0)