-
Notifications
You must be signed in to change notification settings - Fork 5
Implement ReceiveComponentDataStreamRequest
#178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # License: MIT | ||
| # Copyright © 2025 Frequenz Energy-as-a-Service GmbH | ||
|
|
||
| """Definition of a component data aggregate.""" | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
| from frequenz.client.common.microgrid.components import ComponentId | ||
|
|
||
| from ..metrics._sample import MetricSample | ||
| from ._state_sample import ComponentStateSample | ||
|
|
||
|
|
||
| @dataclass(frozen=True, kw_only=True) | ||
| class ComponentDataSamples: | ||
| """An aggregate of multiple metrics, states, and errors of a component.""" | ||
|
|
||
| component_id: ComponentId | ||
| """The unique identifier of the component.""" | ||
|
|
||
| metric_samples: list[MetricSample] | ||
| """The metrics sampled from the component.""" | ||
|
|
||
| states: list[ComponentStateSample] | ||
| """The states sampled from the component.""" |
88 changes: 88 additions & 0 deletions
88
src/frequenz/client/microgrid/component/_data_samples_proto.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # License: MIT | ||
| # Copyright © 2025 Frequenz Energy-as-a-Service GmbH | ||
|
|
||
| """Loading of ComponentDataSamples objects from protobuf messages.""" | ||
|
|
||
|
|
||
| import logging | ||
| from functools import partial | ||
|
|
||
| from frequenz.api.common.v1.microgrid.components import components_pb2 | ||
| from frequenz.client.common.microgrid.components import ComponentId | ||
|
|
||
| from ..metrics._sample_proto import metric_sample_from_proto_with_issues | ||
| from ._data_samples import ComponentDataSamples | ||
| from ._state_sample_proto import component_state_sample_from_proto | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def component_data_samples_from_proto( | ||
| message: components_pb2.ComponentData, | ||
| ) -> ComponentDataSamples: | ||
| """Convert a protobuf component data message to a component data object. | ||
|
|
||
| Args: | ||
| message: The protobuf message to convert. | ||
|
|
||
| Returns: | ||
| The resulting `ComponentDataSamples` object. | ||
| """ | ||
| major_issues: list[str] = [] | ||
| minor_issues: list[str] = [] | ||
|
|
||
| samples = component_data_samples_from_proto_with_issues( | ||
| message, major_issues=major_issues, minor_issues=minor_issues | ||
| ) | ||
|
|
||
| # This approach to logging issues might be too noisy. Samples are received | ||
| # very often, and sometimes can remain unchanged for a long time, leading to | ||
| # repeated log messages. We might need to adjust the logging strategy | ||
| # in the future. | ||
| if major_issues: | ||
| _logger.warning( | ||
| "Found issues in component data samples: %s | Protobuf message:\n%s", | ||
| ", ".join(major_issues), | ||
| message, | ||
| ) | ||
|
|
||
| if minor_issues: | ||
| _logger.debug( | ||
| "Found minor issues in component data samples: %s | Protobuf message:\n%s", | ||
| ", ".join(minor_issues), | ||
| message, | ||
| ) | ||
|
|
||
| return samples | ||
|
|
||
|
|
||
| def component_data_samples_from_proto_with_issues( | ||
| message: components_pb2.ComponentData, | ||
| *, | ||
| major_issues: list[str], | ||
| minor_issues: list[str], | ||
| ) -> ComponentDataSamples: | ||
| """Convert a protobuf component data message to a component data object collecting issues. | ||
|
|
||
| Args: | ||
| message: The protobuf message to convert. | ||
| major_issues: A list to append major issues to. | ||
| minor_issues: A list to append minor issues to. | ||
|
|
||
| Returns: | ||
| The resulting `ComponentDataSamples` object. | ||
| """ | ||
| return ComponentDataSamples( | ||
| component_id=ComponentId(message.component_id), | ||
| metric_samples=list( | ||
| map( | ||
| partial( | ||
| metric_sample_from_proto_with_issues, | ||
| major_issues=major_issues, | ||
| minor_issues=minor_issues, | ||
| ), | ||
| message.metric_samples, | ||
| ) | ||
| ), | ||
| states=list(map(component_state_sample_from_proto, message.states)), | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.