Skip to content

Commit 908a0b3

Browse files
committed
Move Sample to frequenz.sdk.timeseries
Now that we have a timeseries package it makes more sense to have the Sample class living there. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 5821901 commit 908a0b3

File tree

8 files changed

+35
-20
lines changed

8 files changed

+35
-20
lines changed

src/frequenz/sdk/actor/data_sourcing/microgrid_api_source.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from frequenz.channels import Receiver, Sender
1515

1616
from frequenz.sdk.actor import ChannelRegistry
17-
from frequenz.sdk.data_pipeline import ComponentMetricId, ComponentMetricRequest, Sample
17+
from frequenz.sdk.data_pipeline import ComponentMetricId, ComponentMetricRequest
1818
from frequenz.sdk.microgrid import (
1919
BatteryData,
2020
ComponentCategory,
@@ -23,6 +23,7 @@
2323
MeterData,
2424
microgrid_api,
2525
)
26+
from frequenz.sdk.timeseries import Sample
2627

2728
_MeterDataMethods: Dict[ComponentMetricId, Callable[[MeterData], float]] = {
2829
ComponentMetricId.ACTIVE_POWER: lambda msg: msg.active_power,

src/frequenz/sdk/actor/resampling.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
from frequenz.channels import MergeNamed, Receiver, Select, Sender, Timer
1717

18-
from ..data_pipeline import ComponentMetricRequest, Sample
18+
from ..data_pipeline import ComponentMetricRequest
19+
from ..timeseries import Sample
1920
from ..timeseries.resampler import ComponentMetricGroupResampler, ResamplingFunction
2021
from . import ChannelRegistry, actor
2122

src/frequenz/sdk/data_pipeline/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
MIT
88
"""
99

10-
from .types import ComponentMetricId, ComponentMetricRequest, Sample
10+
from .types import ComponentMetricId, ComponentMetricRequest
1111

1212
__all__ = [
1313
"ComponentMetricRequest",
1414
"ComponentMetricId",
15-
"Sample",
1615
]

src/frequenz/sdk/data_pipeline/types.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,3 @@ def get_channel_name(self) -> str:
7373
A string denoting a channel name.
7474
"""
7575
return f"{self.component_id}::{self.metric_id.name}::{self.start_time}::{self.namespace}"
76-
77-
78-
@dataclass(frozen=True)
79-
class Sample:
80-
"""A measurement taken at a particular point in time.
81-
82-
The `value` could be `None` if a component is malfunctioning or data is
83-
lacking for another reason, but a sample still needs to be sent to have a
84-
coherent view on a group of component metrics for a particular timestamp.
85-
"""
86-
87-
timestamp: datetime
88-
value: Optional[float] = None

src/frequenz/sdk/timeseries/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
ComponentMetricResampler,
1919
ResamplingFunction,
2020
)
21+
from .sample import Sample
2122

2223
__all__ = [
2324
"ComponentMetricGroupResampler",
2425
"ComponentMetricResampler",
2526
"ResamplingFunction",
27+
"Sample",
2628
]

src/frequenz/sdk/timeseries/resampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from datetime import datetime, timedelta, timezone
1414
from typing import Callable, Deque, Dict, Generator, Optional, Sequence, Tuple
1515

16-
from ..data_pipeline import Sample
16+
from .sample import Sample
1717

1818
logger = logging.Logger(__name__)
1919

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Common types for the Data Pipeline.
2+
3+
Copyright
4+
Copyright © 2022 Frequenz Energy-as-a-Service GmbH
5+
6+
License
7+
MIT
8+
"""
9+
10+
from dataclasses import dataclass
11+
from datetime import datetime
12+
from typing import Optional
13+
14+
15+
@dataclass(frozen=True)
16+
class Sample:
17+
"""A measurement taken at a particular point in time.
18+
19+
The `value` could be `None` if a component is malfunctioning or data is
20+
lacking for another reason, but a sample still needs to be sent to have a
21+
coherent view on a group of component metrics for a particular timestamp.
22+
"""
23+
24+
timestamp: datetime
25+
value: Optional[float] = None

tests/timeseries/test_resampling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
import time_machine
1515

16-
from frequenz.sdk.data_pipeline import Sample
17-
from frequenz.sdk.timeseries.resampler import (
16+
from frequenz.sdk.timeseries import (
1817
ComponentMetricGroupResampler,
1918
ComponentMetricResampler,
19+
Sample,
2020
)
2121

2222

0 commit comments

Comments
 (0)