2424from frequenz .sdk .actor import ResamplerConfig
2525from frequenz .sdk .actor .power_distributing import BatteryStatus
2626from frequenz .sdk .microgrid .component import ComponentCategory
27- from frequenz .sdk .timeseries import Quantity , Sample
28- from frequenz .sdk .timeseries ._quantities import Power
29- from frequenz .sdk .timeseries .battery_pool import (
30- BatteryPool ,
31- Bound ,
32- CapacityMetrics ,
33- PowerMetrics ,
34- )
27+ from frequenz .sdk .timeseries import Energy , Power , Quantity , Sample
28+ from frequenz .sdk .timeseries .battery_pool import BatteryPool , Bound , PowerMetrics
3529from frequenz .sdk .timeseries .battery_pool ._metric_calculator import (
3630 battery_inverter_mapping ,
3731)
@@ -508,93 +502,115 @@ async def run_capacity_test(setup_args: SetupArgs) -> None:
508502 capacity_receiver .receive (), timeout = WAIT_FOR_COMPONENT_DATA_SEC + 0.2
509503 )
510504 now = datetime .now (tz = timezone .utc )
511- expected = CapacityMetrics (
505+ expected = Sample [ Energy ] (
512506 timestamp = now ,
513- total_capacity = 50.0 , # 50% of 50 kWh + 50% of 50 kWh = 25 + 25 = 50 kWh
507+ value = Energy .from_watt_hours (
508+ 50.0
509+ ), # 50% of 50 kWh + 50% of 50 kWh = 25 + 25 = 50 kWh
514510 )
515511 compare_messages (msg , expected , WAIT_FOR_COMPONENT_DATA_SEC + 0.2 )
516512
517513 batteries_in_pool = list (battery_pool .battery_ids )
518- scenarios : list [Scenario [CapacityMetrics ]] = [
514+ scenarios : list [Scenario [Sample [ Energy ] ]] = [
519515 Scenario (
520516 batteries_in_pool [0 ],
521517 {"capacity" : 90.0 },
522- CapacityMetrics (
518+ Sample (
523519 now ,
524- 70.0 , # 50% of 90 kWh + 50% of 50 kWh = 45 + 25 = 70 kWh
520+ Energy .from_watt_hours (
521+ 70.0
522+ ), # 50% of 90 kWh + 50% of 50 kWh = 45 + 25 = 70 kWh
525523 ),
526524 ),
527525 Scenario (
528526 batteries_in_pool [1 ],
529527 {"soc_lower_bound" : 0.0 , "soc_upper_bound" : 90.0 },
530- CapacityMetrics (
528+ Sample (
531529 now ,
532- 90.0 , # 50% of 90 kWh + 90% of 50 kWh = 45 + 45 = 90 kWh
530+ Energy .from_watt_hours (
531+ 90.0
532+ ), # 50% of 90 kWh + 90% of 50 kWh = 45 + 45 = 90 kWh
533533 ),
534534 ),
535535 Scenario (
536536 batteries_in_pool [0 ],
537537 {"capacity" : 0.0 , "soc_lower_bound" : 0.0 },
538- CapacityMetrics (
538+ Sample (
539539 now ,
540- 45.0 , # 75% of 0 kWh + 90% of 50 kWh = 0 + 45 = 45 kWh
540+ Energy .from_watt_hours (
541+ 45.0
542+ ), # 75% of 0 kWh + 90% of 50 kWh = 0 + 45 = 45 kWh
541543 ),
542544 ),
543545 # Test zero division error
544546 Scenario (
545547 batteries_in_pool [1 ],
546548 {"capacity" : 0.0 },
547- CapacityMetrics (
549+ Sample (
548550 now ,
549- 0.0 , # 75% of 0 kWh + 90% of 0 kWh = 0 + 0 = 0 kWh
551+ Energy .from_watt_hours (
552+ 0.0
553+ ), # 75% of 0 kWh + 90% of 0 kWh = 0 + 0 = 0 kWh
550554 ),
551555 ),
552556 Scenario (
553557 batteries_in_pool [1 ],
554558 {"capacity" : 50.0 },
555- CapacityMetrics (
559+ Sample (
556560 now ,
557- 45.0 , # 75% of 0 kWh + 90% of 50 kWh = 0 + 45 = 45 kWh
561+ Energy .from_watt_hours (
562+ 45.0
563+ ), # 75% of 0 kWh + 90% of 50 kWh = 0 + 45 = 45 kWh
558564 ),
559565 ),
560566 Scenario (
561567 batteries_in_pool [1 ],
562568 {"soc_upper_bound" : float ("NaN" )},
563- CapacityMetrics (
569+ Sample (
564570 now ,
565- 0.0 , # 75% of 0 kWh + 90% of 0 kWh = 0 + 0 = 0 kWh
571+ Energy .from_watt_hours (
572+ 0.0
573+ ), # 75% of 0 kWh + 90% of 0 kWh = 0 + 0 = 0 kWh
566574 ),
567575 ),
568576 Scenario (
569577 batteries_in_pool [0 ],
570578 {"capacity" : 30.0 , "soc_lower_bound" : 20.0 , "soc_upper_bound" : 90.0 },
571- CapacityMetrics (
579+ Sample (
572580 now ,
573- 21.0 , # 70% of 30 kWh + 90% of 0 kWh = 21 + 0 = 21 kWh
581+ Energy .from_watt_hours (
582+ 21.0
583+ ), # 70% of 30 kWh + 90% of 0 kWh = 21 + 0 = 21 kWh
574584 ),
575585 ),
576586 Scenario (
577587 batteries_in_pool [1 ],
578588 {"capacity" : 200.0 , "soc_lower_bound" : 20.0 , "soc_upper_bound" : 90.0 },
579- CapacityMetrics (
589+ Sample (
580590 now ,
581- 161.0 , # 70% of 30 kWh + 70% of 200 kWh = 21 + 140 = 161 kWh
591+ Energy .from_watt_hours (
592+ 161.0
593+ ), # 70% of 30 kWh + 70% of 200 kWh = 21 + 140 = 161 kWh
582594 ),
583595 ),
584596 Scenario (
585597 batteries_in_pool [1 ],
586598 {"capacity" : float ("NaN" )},
587- CapacityMetrics (
599+ Sample (
588600 now ,
589- 21.0 , # 70% of 30 kWh + 70% of 0 kWh = 21 + 0 = 21 kWh
601+ Energy .from_watt_hours (
602+ 21.0
603+ ), # 70% of 30 kWh + 70% of 0 kWh = 21 + 0 = 21 kWh
590604 ),
591605 ),
592606 Scenario (
593607 batteries_in_pool [1 ],
594608 {"capacity" : 200.0 },
595- CapacityMetrics (
609+ Sample (
596610 now ,
597- 161.0 , # 70% of 30 kWh + 70% of 200 kWh = 21 + 140 = 161 kWh
611+ Energy .from_watt_hours (
612+ 161.0
613+ ), # 70% of 30 kWh + 70% of 200 kWh = 21 + 140 = 161 kWh
598614 ),
599615 ),
600616 ]
@@ -608,15 +624,15 @@ async def run_capacity_test(setup_args: SetupArgs) -> None:
608624 all_batteries = all_batteries ,
609625 batteries_in_pool = batteries_in_pool ,
610626 waiting_time_sec = waiting_time_sec ,
611- all_pool_result = CapacityMetrics (now , 161.0 ),
612- only_first_battery_result = CapacityMetrics (now , 21.0 ),
627+ all_pool_result = Sample (now , Energy . from_watt_hours ( 161.0 ) ),
628+ only_first_battery_result = Sample (now , Energy . from_watt_hours ( 21.0 ) ),
613629 )
614630
615631 # One battery stopped sending data.
616632 await streamer .stop_streaming (batteries_in_pool [1 ])
617633 await asyncio .sleep (MAX_BATTERY_DATA_AGE_SEC + 0.2 )
618634 msg = await asyncio .wait_for (capacity_receiver .receive (), timeout = waiting_time_sec )
619- compare_messages (msg , CapacityMetrics (now , 21.0 ), 0.2 )
635+ compare_messages (msg , Sample (now , Energy . from_watt_hours ( 21.0 ) ), 0.2 )
620636
621637 # All batteries stopped sending data.
622638 await streamer .stop_streaming (batteries_in_pool [0 ])
@@ -628,7 +644,7 @@ async def run_capacity_test(setup_args: SetupArgs) -> None:
628644 latest_data = streamer .get_current_component_data (batteries_in_pool [0 ])
629645 streamer .start_streaming (latest_data , sampling_rate = 0.1 )
630646 msg = await asyncio .wait_for (capacity_receiver .receive (), timeout = waiting_time_sec )
631- compare_messages (msg , CapacityMetrics (now , 21.0 ), 0.2 )
647+ compare_messages (msg , Sample (now , Energy . from_watt_hours ( 21.0 ) ), 0.2 )
632648
633649
634650async def run_soc_test (setup_args : SetupArgs ) -> None :
0 commit comments