@@ -24,8 +24,18 @@ def main() -> None:
2424        help = "URL of the Reporting service" ,
2525        default = "localhost:50051" ,
2626    )
27-     parser .add_argument ("--mid" , type = int , help = "Microgrid ID" , required = True )
28-     parser .add_argument ("--cid" , type = int , help = "Component ID" , required = True )
27+     parser .add_argument (
28+         "--mid" ,
29+         type = int ,
30+         help = "Microgrid ID" ,
31+         required = True ,
32+     )
33+     parser .add_argument (
34+         "--cid" ,
35+         nargs = "+" ,
36+         type = str ,
37+         help = "Component IDs or formulae" ,
38+     )
2939    parser .add_argument (
3040        "--metrics" ,
3141        type = str ,
@@ -97,7 +107,7 @@ def main() -> None:
97107async  def  run (
98108    * ,
99109    microgrid_id : int ,
100-     component_id : int ,
110+     component_id : list [ str ] ,
101111    metric_names : list [str ],
102112    start_dt : datetime  |  None ,
103113    end_dt : datetime  |  None ,
@@ -130,30 +140,47 @@ async def run(
130140
131141    metrics  =  [Metric [mn ] for  mn  in  metric_names ]
132142
133-     def  data_iter () ->  AsyncIterator [MetricSample ]:
143+     cids  =  [int (cid .strip ()) for  cid  in  component_id  if  cid .strip ().isdigit ()]
144+     formulas  =  [cid .strip () for  cid  in  component_id  if  not  cid .strip ().isdigit ()]
145+     microgrid_components  =  [(microgrid_id , cids )]
146+ 
147+     async  def  data_iter () ->  AsyncIterator [MetricSample ]:
134148        """Iterate over single metric. 
135149
136150        Just a wrapper around the client method for readability. 
137151
138-         Returns : 
139-             Iterator over single  metric samples 
152+         Yields : 
153+             Single  metric samples 
140154        """ 
141155        resampling_period  =  (
142156            timedelta (seconds = resampling_period_s )
143157            if  resampling_period_s  is  not None 
144158            else  None 
145159        )
146160
147-         return  client .list_single_component_data (
148-             microgrid_id = microgrid_id ,
149-             component_id = component_id ,
161+         async  for  sample  in  client .list_microgrid_components_data (
162+             microgrid_components = microgrid_components ,
150163            metrics = metrics ,
151164            start_dt = start_dt ,
152165            end_dt = end_dt ,
153166            resampling_period = resampling_period ,
154167            include_states = states ,
155168            include_bounds = bounds ,
156-         )
169+         ):
170+             yield  sample 
171+ 
172+         for  formula  in  formulas :
173+             assert  resampling_period  is  not None 
174+             for  metric  in  metrics :
175+                 async  for  sample  in  client .receive_aggregated_data (
176+                     microgrid_id = microgrid_id ,
177+                     metric = metric ,
178+                     aggregation_formula = formula ,
179+                     start = start_dt ,
180+                     end = end_dt ,
181+                     resampling_period = resampling_period ,
182+                 ):
183+                     yield  sample 
157184
158185    if  fmt  ==  "iter" :
159186        # Iterate over single metric generator 
0 commit comments