|  | 
| 5 | 5 | import asyncio | 
| 6 | 6 | from datetime import datetime | 
| 7 | 7 | 
 | 
|  | 8 | +from frequenz.client.reporting.formula_engine._formula_generators._pv_power_formula import PVPowerFormula, FormulaGeneratorConfig | 
|  | 9 | + | 
| 8 | 10 | from frequenz.client.common.metric import Metric | 
| 9 | 11 | def build_graph(json_data: dict) -> ComponentGraph: | 
| 10 | 12 |     components = [] | 
| @@ -47,23 +49,38 @@ async def main(): | 
| 47 | 49 |     key = open("key.txt", "r").read().strip() | 
| 48 | 50 |     client = ReportingApiClient(server_url="grpc://reporting.api.frequenz.com:443?ssl=true", key=key) | 
| 49 | 51 | 
 | 
| 50 |  | -    microgrid_id = 13 | 
| 51 |  | -    component_ids = [256, 258] | 
| 52 |  | -    microgrid_components = [ | 
| 53 |  | -        (microgrid_id, component_ids), | 
| 54 |  | -    ] | 
| 55 |  | -    start_dt = datetime(2024, 9, 17) | 
| 56 |  | -    end_dt = datetime(2024, 9, 18) | 
| 57 |  | -    resolution = 900 | 
|  | 52 | +    def get_receiver(component_id, metric_id): | 
|  | 53 | +        microgrid_id = 13 | 
|  | 54 | +        component_ids = [component_id] | 
|  | 55 | +        microgrid_components = [ | 
|  | 56 | +            (microgrid_id, component_ids), | 
|  | 57 | +        ] | 
|  | 58 | + | 
|  | 59 | +        start_dt = datetime(2024, 9, 17) | 
|  | 60 | +        end_dt = datetime(2024, 9, 18) | 
|  | 61 | +        resolution = 900 | 
|  | 62 | +        receiver = list_microgrid_components_data_receiver( | 
|  | 63 | +            client, | 
|  | 64 | +            microgrid_components=microgrid_components, | 
|  | 65 | +            metrics=[Metric.AC_ACTIVE_POWER], | 
|  | 66 | +            start_dt=start_dt, | 
|  | 67 | +            end_dt=end_dt, | 
|  | 68 | +            resolution=resolution, | 
|  | 69 | +        ) | 
|  | 70 | +        return receiver | 
|  | 71 | + | 
|  | 72 | +    #async for sample in get_receiver(256, 4711): | 
|  | 73 | +    #    print(sample) | 
|  | 74 | + | 
|  | 75 | +    formula = PVPowerFormula( | 
|  | 76 | +        get_receiver=get_receiver, | 
|  | 77 | +        config=FormulaGeneratorConfig(), | 
|  | 78 | +        component_graph=component_graph, | 
|  | 79 | +    ) | 
| 58 | 80 | 
 | 
| 59 |  | -    async for sample in list_microgrid_components_data_receiver( | 
| 60 |  | -        client, | 
| 61 |  | -        microgrid_components=microgrid_components, | 
| 62 |  | -        metrics=[Metric.AC_ACTIVE_POWER], | 
| 63 |  | -        start_dt=start_dt, | 
| 64 |  | -        end_dt=end_dt, | 
| 65 |  | -        resolution=resolution, | 
| 66 |  | -    ): | 
|  | 81 | +    engine = formula.generate() | 
|  | 82 | +    recv = engine.new_receiver() | 
|  | 83 | +    async for sample in recv: | 
| 67 | 84 |         print(sample) | 
| 68 | 85 | 
 | 
| 69 | 86 | if __name__ == "__main__": | 
|  | 
0 commit comments