|
16 | 16 | MicrogridComponentIDs as PBMicrogridComponentIDs, |
17 | 17 | ) |
18 | 18 | from frequenz.api.reporting.v1.reporting_pb2 import IncludeOptions as PBIncludeOptions |
| 19 | +from frequenz.api.reporting.v1.reporting_pb2 import ( |
| 20 | + MetricConnections as PBMetricConnections, |
| 21 | +) |
19 | 22 | from frequenz.api.reporting.v1.reporting_pb2 import ( |
20 | 23 | ReceiveMicrogridComponentsDataStreamRequest as PBReceiveMicrogridComponentsDataStreamRequest, |
21 | 24 | ) |
|
33 | 36 | from google.protobuf.timestamp_pb2 import Timestamp as PBTimestamp |
34 | 37 |
|
35 | 38 | MetricSample = namedtuple( |
36 | | - "MetricSample", ["timestamp", "microgrid_id", "component_id", "metric", "value"] |
| 39 | + "MetricSample", |
| 40 | + ["timestamp", "microgrid_id", "component_id", "metric", "value"], |
37 | 41 | ) |
38 | 42 | """Type for a sample of a time series incl. metric type, microgrid and component ID |
39 | 43 |
|
@@ -65,6 +69,7 @@ def is_empty(self) -> bool: |
65 | 69 | return True |
66 | 70 | return False |
67 | 71 |
|
| 72 | + # pylint: disable=too-many-locals |
68 | 73 | def __iter__(self) -> Iterator[MetricSample]: |
69 | 74 | """Get generator that iterates over all values in the batch. |
70 | 75 |
|
@@ -126,8 +131,6 @@ def __iter__(self) -> Iterator[MetricSample]: |
126 | 131 | # Skip if the category is not present |
127 | 132 | if not isinstance(category, Iterable): |
128 | 133 | continue |
129 | | - # Each category can have multiple states |
130 | | - # that are provided as individual samples |
131 | 134 | for s in category: |
132 | 135 | yield MetricSample( |
133 | 136 | timestamp=ts, |
@@ -317,11 +320,17 @@ def dt2ts(dt: datetime) -> PBTimestamp: |
317 | 320 | include_options=include_options, |
318 | 321 | ) |
319 | 322 |
|
320 | | - metrics_pb = [metric.to_proto() for metric in metrics] |
| 323 | + metric_conns_pb = [ |
| 324 | + PBMetricConnections( |
| 325 | + metric=metric.to_proto(), |
| 326 | + connections=[], |
| 327 | + ) |
| 328 | + for metric in metrics |
| 329 | + ] |
321 | 330 |
|
322 | 331 | request = PBReceiveMicrogridComponentsDataStreamRequest( |
323 | 332 | microgrid_components=microgrid_components_pb, |
324 | | - metrics=metrics_pb, |
| 333 | + metrics=metric_conns_pb, |
325 | 334 | filter=stream_filter, |
326 | 335 | ) |
327 | 336 |
|
|
0 commit comments