Index
frequenz.sdk.timeseries
¤
Handling of timeseries streams.
A timeseries is a stream (normally an async iterator) of
Sample
s.
Periodicity and alignment¤
All the data produced by this package is always periodic and aligned to the
UNIX_EPOCH
(by default).
Classes normally take a (re)sampling period as and argument and, optionally, an
align_to
argument.
This means timestamps are always separated exaclty by a period, and that this
timestamp falls always at multiples of the period, starting at the align_to
.
This ensures that the data is predictable and consistent among restarts.
Example
If we have a period of 10 seconds, and are aligning to the UNIX
epoch. Assuming the following timeline starts in 1970-01-01 00:00:00
UTC and our current now
is 1970-01-01 00:00:32 UTC, then the next
timestamp will be at 1970-01-01 00:00:40 UTC:
Attributes¤
frequenz.sdk.timeseries.UNIX_EPOCH = datetime.fromtimestamp(0.0, tz=timezone.utc)
module-attribute
¤
The UNIX epoch (in UTC).
Classes¤
frequenz.sdk.timeseries.Current
¤
Bases: Quantity
A current quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
|
Functions¤
__mul__(other)
¤
Return a current or power from multiplying this current by the given value.
PARAMETER | DESCRIPTION |
---|---|
other |
The percentage or voltage to multiply by.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self | Power
|
A current or power. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the given value is not a percentage or voltage. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
as_milliamperes()
¤
Return the current in milliamperes.
RETURNS | DESCRIPTION |
---|---|
float
|
The current in milliamperes. |
from_amperes(amperes)
classmethod
¤
from_milliamperes(milliamperes)
classmethod
¤
frequenz.sdk.timeseries.Energy
¤
Bases: Quantity
An energy quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 |
|
Functions¤
__truediv__(other)
¤
Return a power or duration from dividing this energy by the given value.
PARAMETER | DESCRIPTION |
---|---|
other |
The power or duration to divide by. |
RETURNS | DESCRIPTION |
---|---|
Power | timedelta
|
A power or duration from dividing this energy by the given value. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the given value is not a power or duration. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
as_kilowatt_hours()
¤
Return the energy in kilowatt hours.
RETURNS | DESCRIPTION |
---|---|
float
|
The energy in kilowatt hours. |
as_megawatt_hours()
¤
Return the energy in megawatt hours.
RETURNS | DESCRIPTION |
---|---|
float
|
The energy in megawatt hours. |
as_watt_hours()
¤
Return the energy in watt hours.
RETURNS | DESCRIPTION |
---|---|
float
|
The energy in watt hours. |
from_kilowatt_hours(kilowatt_hours)
classmethod
¤
from_megawatt_hours(megawatt_hours)
classmethod
¤
from_watt_hours(watt_hours)
classmethod
¤
frequenz.sdk.timeseries.Frequency
¤
Bases: Quantity
A frequency quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 |
|
Functions¤
as_gigahertz()
¤
Return the frequency in gigahertz.
RETURNS | DESCRIPTION |
---|---|
float
|
The frequency in gigahertz. |
as_kilohertz()
¤
Return the frequency in kilohertz.
RETURNS | DESCRIPTION |
---|---|
float
|
The frequency in kilohertz. |
as_megahertz()
¤
Return the frequency in megahertz.
RETURNS | DESCRIPTION |
---|---|
float
|
The frequency in megahertz. |
from_gigahertz(gigahertz)
classmethod
¤
from_hertz(hertz)
classmethod
¤
from_kilohertz(kilohertz)
classmethod
¤
from_megahertz(megahertz)
classmethod
¤
frequenz.sdk.timeseries.MovingWindow
¤
Bases: BackgroundService
A data window that moves with the latest datapoints of a data stream.
After initialization the MovingWindow
can be accessed by an integer
index or a timestamp. A sub window can be accessed by using a slice of
integers or timestamps.
Note that a numpy ndarray is returned and thus users can use numpys operations directly on a window.
The window uses a ring buffer for storage and the first element is aligned to
a fixed defined point in time. Since the moving nature of the window, the
date of the first and the last element are constantly changing and therefore
the point in time that defines the alignment can be outside of the time window.
Modulo arithmetic is used to move the align_to
timestamp into the latest
window.
If for example the align_to
parameter is set to
datetime(1, 1, 1, tzinfo=timezone.utc)
and the window size is bigger than
one day then the first element will always be aligned to midnight.
Resampling might be required to reduce the number of samples to store, and it can be set by specifying the resampler config parameter so that the user can control the granularity of the samples to be stored in the underlying buffer.
If resampling is not required, the resampler config parameter can be set to None in which case the MovingWindow will not perform any resampling.
Example: Calculate the mean of a time interval
```python
from datetime import datetime, timedelta, timezone
async def send_mock_data(sender: Sender[Sample]) -> None:
while True:
await sender.send(Sample(datetime.now(tz=timezone.utc), 10.0))
await asyncio.sleep(1.0)
async def run() -> None:
resampled_data_channel = Broadcast[Sample]("sample-data")
resampled_data_receiver = resampled_data_channel.new_receiver()
resampled_data_sender = resampled_data_channel.new_sender()
send_task = asyncio.create_task(send_mock_data(resampled_data_sender))
async with MovingWindow(
size=timedelta(seconds=5),
resampled_data_recv=resampled_data_receiver,
input_sampling_period=timedelta(seconds=1),
) as window:
time_start = datetime.now(tz=timezone.utc)
time_end = time_start + timedelta(seconds=5)
# ... wait for 5 seconds until the buffer is filled
await asyncio.sleep(5)
# return an numpy array from the window
array = window[time_start:time_end]
# and use it to for example calculate the mean
mean = array.mean()
asyncio.run(run())
```
Example: Create a polars data frame from a MovingWindow
```python
import polars as pl
from datetime import datetime, timedelta, timezone
async def send_mock_data(sender: Sender[Sample]) -> None:
while True:
await sender.send(Sample(datetime.now(tz=timezone.utc), 10.0))
await asyncio.sleep(1.0)
async def run() -> None:
resampled_data_channel = Broadcast[Sample]("sample-data")
resampled_data_receiver = resampled_data_channel.new_receiver()
resampled_data_sender = resampled_data_channel.new_sender()
send_task = asyncio.create_task(send_mock_data(resampled_data_sender))
# create a window that stores two days of data
# starting at 1.1.23 with samplerate=1
async with MovingWindow(
size=timedelta(days=2),
resampled_data_recv=resampled_data_receiver,
input_sampling_period=timedelta(seconds=1),
) as window:
# wait for one full day until the buffer is filled
await asyncio.sleep(60*60*24)
# create a polars series with one full day of data
time_start = datetime(2023, 1, 1, tzinfo=timezone.utc)
time_end = datetime(2023, 1, 2, tzinfo=timezone.utc)
series = pl.Series("Jan_1", window[time_start:time_end])
asyncio.run(run())
```
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_moving_window.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
Attributes¤
sampling_period: timedelta
property
¤
Return the sampling period of the MovingWindow.
RETURNS | DESCRIPTION |
---|---|
timedelta
|
The sampling period of the MovingWindow. |
Functions¤
__getitem__(key)
¤
Return a sub window of the MovingWindow
.
The MovingWindow
is accessed either by timestamp or by index
or by a slice of timestamps or integers.
- If the key is an integer, the float value of that key at the given position is returned.
- If the key is a datetime object, the float value of that key that corresponds to the timestamp is returned.
- If the key is a slice of timestamps or integers, an ndarray is returned, where the bounds correspond to the slice bounds. Note that a half open interval, which is open at the end, is returned.
PARAMETER | DESCRIPTION |
---|---|
key |
Either an integer or a timestamp or a slice of timestamps or integers.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
IndexError
|
when requesting an out of range timestamp or index |
TypeError
|
when the key is not a datetime or slice object. |
RETURNS | DESCRIPTION |
---|---|
float | ArrayLike
|
A float if the key is a number or a timestamp. |
float | ArrayLike
|
an numpy array if the key is a slice. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_moving_window.py
__init__(size, resampled_data_recv, input_sampling_period, resampler_config=None, align_to=UNIX_EPOCH, *, name=None)
¤
Initialize the MovingWindow.
This method creates the underlying ring buffer and starts a new task that updates the ring buffer with new incoming samples. The task stops running only if the channel receiver is closed.
PARAMETER | DESCRIPTION |
---|---|
size |
The time span of the moving window over which samples will be stored.
TYPE:
|
resampled_data_recv |
A receiver that delivers samples with a given sampling period. |
input_sampling_period |
The time interval between consecutive input samples.
TYPE:
|
resampler_config |
The resampler configuration in case resampling is required.
TYPE:
|
align_to |
A datetime object that defines a point in time to which the window is aligned to modulo window size. For further information, consult the class level documentation.
TYPE:
|
name |
The name of this moving window. If
TYPE:
|
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_moving_window.py
__len__()
¤
Return the size of the MovingWindow
s underlying buffer.
RETURNS | DESCRIPTION |
---|---|
int
|
The size of the |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_moving_window.py
start()
¤
Start the MovingWindow.
This method starts the MovingWindow tasks.
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_moving_window.py
frequenz.sdk.timeseries.Percentage
¤
Bases: Quantity
A percentage quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
Functions¤
as_fraction()
¤
Return this quantity as a fraction.
RETURNS | DESCRIPTION |
---|---|
float
|
This quantity as a fraction. |
as_percent()
¤
Return this quantity as a percentage.
RETURNS | DESCRIPTION |
---|---|
float
|
This quantity as a percentage. |
from_fraction(fraction)
classmethod
¤
Initialize a new percentage quantity from a fraction.
PARAMETER | DESCRIPTION |
---|---|
fraction |
The fraction, normally in the 0.0-1.0 range.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A new percentage quantity. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
from_percent(percent)
classmethod
¤
Initialize a new percentage quantity from a percent value.
PARAMETER | DESCRIPTION |
---|---|
percent |
The percent value, normally in the 0.0-100.0 range.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A new percentage quantity. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
frequenz.sdk.timeseries.PeriodicFeatureExtractor
¤
A feature extractor for historical timeseries data.
This class is creating a profile from periodically occurring windows in a buffer of historical data.
The profile is created out of all windows that are fully contained in the underlying buffer with the same start and end time modulo a fixed period.
Consider for example a timeseries $T$ of historical data and sub-series $S_i$ of $T$ all having the same size $l$ and the same fixed distance $p$ called period, where period of two sub-windows is defined as the distance of two points at the same position within the sub-windows.
This class calculates a statistical profile $S$ over all $S_i$, i.e. the value of $S$ at position $i$ is calculated by performing a certain calculation, e.g. an average, over all values of $S_i$ at position $i$.
Note
The oldest window or the window that is currently overwritten in the
MovingWindow
is not considered in the profile.
Note
When constructing a PeriodicFeatureExtractor
object the
MovingWindow
size has to be a integer multiple of the period.
Example
from frequenz.sdk import microgrid
from datetime import datetime, timedelta, timezone
async with MovingWindow(
size=timedelta(days=35),
resampled_data_recv=microgrid.logical_meter().grid_power.new_receiver(),
input_sampling_period=timedelta(seconds=1),
) as moving_window:
feature_extractor = PeriodicFeatureExtractor(
moving_window=moving_window,
period=timedelta(days=7),
)
now = datetime.now(timezone.utc)
# create a daily weighted average for the next 24h
avg_24h = feature_extractor.avg(
now,
now + timedelta(hours=24),
weights=[0.1, 0.2, 0.3, 0.4]
)
# create a daily average for Thursday March 23 2023
th_avg_24h = feature_extractor.avg(datetime(2023, 3, 23), datetime(2023, 3, 24))
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_periodic_feature_extractor.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
Functions¤
__init__(moving_window, period)
¤
Initialize a PeriodicFeatureExtractor object.
PARAMETER | DESCRIPTION |
---|---|
moving_window |
The MovingWindow that is used for the average calculation.
TYPE:
|
period |
The distance between two succeeding intervals.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the MovingWindow size is not a integer multiple of the period. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_periodic_feature_extractor.py
avg(start, end, weights=None)
¤
Create the average window out of the window defined by start
and end
.
This method calculates the average of a window by averaging over all
windows fully inside the MovingWindow having the period
self.period
.
PARAMETER | DESCRIPTION |
---|---|
start |
The start of the window to average over.
TYPE:
|
end |
The end of the window to average over.
TYPE:
|
weights |
The weights to use for the average calculation (oldest first). |
RETURNS | DESCRIPTION |
---|---|
NDArray[float_]
|
The averaged timeseries window. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_periodic_feature_extractor.py
frequenz.sdk.timeseries.Power
¤
Bases: Quantity
A power quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
|
Functions¤
__mul__(other)
¤
Return a power or energy from multiplying this power by the given value.
PARAMETER | DESCRIPTION |
---|---|
other |
The percentage or duration to multiply by.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self | Energy
|
A power or energy. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the given value is not a percentage or duration. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__truediv__(other)
¤
Return a current or voltage from dividing this power by the given value.
PARAMETER | DESCRIPTION |
---|---|
other |
The current or voltage to divide by. |
RETURNS | DESCRIPTION |
---|---|
Voltage | Current
|
A current or voltage from dividing this power by the given value. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the given value is not a current or voltage. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
from_kilowatts(kilowatts)
classmethod
¤
from_megawatts(megawatts)
classmethod
¤
from_milliwatts(milliwatts)
classmethod
¤
frequenz.sdk.timeseries.Quantity
¤
A quantity with a unit.
Quantities try to behave like float and are also immutable.
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
|
Attributes¤
base_unit: str | None
property
¤
Return the base unit of this quantity.
None if this quantity has no unit.
RETURNS | DESCRIPTION |
---|---|
str | None
|
The base unit of this quantity. |
base_value: float
property
¤
Return the value of this quantity in the base unit.
RETURNS | DESCRIPTION |
---|---|
float
|
The value of this quantity in the base unit. |
Functions¤
__abs__()
¤
Return the absolute value of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The absolute value of this quantity. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__add__(other)
¤
Return the sum of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other |
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The sum of this quantity and another. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__eq__(other)
¤
Return whether this quantity is equal to another.
PARAMETER | DESCRIPTION |
---|---|
other |
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is equal to another. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__format__(__format_spec)
¤
Return a formatted string representation of this quantity.
If specified, must be of this form: [0].{precision}
. If a 0 is not given, the
trailing zeros will be omitted. If no precision is given, the default is 3.
The returned string will use the unit that will result in the maxium precision, based on the magnitude of the value.
Example
PARAMETER | DESCRIPTION |
---|---|
__format_spec |
The format specifier.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given format specifier is invalid. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__ge__(other)
¤
Return whether this quantity is greater than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other |
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is greater than or equal to another. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__gt__(other)
¤
Return whether this quantity is greater than another.
PARAMETER | DESCRIPTION |
---|---|
other |
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is greater than another. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__init__(value, exponent=0)
¤
Initialize a new quantity.
PARAMETER | DESCRIPTION |
---|---|
value |
The value of this quantity in a given exponent of the base unit.
TYPE:
|
exponent |
The exponent of the base unit the given value is in.
TYPE:
|
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__init_subclass__(exponent_unit_map)
¤
Initialize a new subclass of Quantity.
PARAMETER | DESCRIPTION |
---|---|
exponent_unit_map |
A mapping from the exponent of the base unit to the unit symbol. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the given exponent_unit_map is not a dict. |
ValueError
|
If the given exponent_unit_map does not contain a base unit (exponent 0). |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__le__(other)
¤
Return whether this quantity is less than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other |
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is less than or equal to another. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__lt__(other)
¤
Return whether this quantity is less than another.
PARAMETER | DESCRIPTION |
---|---|
other |
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is less than another. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__mul__(percent)
¤
Return the product of this quantity and a percentage.
PARAMETER | DESCRIPTION |
---|---|
percent |
The percentage.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The product of this quantity and a percentage. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__neg__()
¤
Return the negation of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The negation of this quantity. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__repr__()
¤
Return a representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A representation of this quantity. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__str__()
¤
Return a string representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
__sub__(other)
¤
Return the difference of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other |
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The difference of this quantity and another. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
isclose(other, rel_tol=1e-09, abs_tol=0.0)
¤
Return whether this quantity is close to another.
PARAMETER | DESCRIPTION |
---|---|
other |
The quantity to compare to.
TYPE:
|
rel_tol |
The relative tolerance.
TYPE:
|
abs_tol |
The absolute tolerance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is close to another. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
isinf()
¤
Return whether this quantity is infinite.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is infinite. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
isnan()
¤
Return whether this quantity is NaN.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is NaN. |
frequenz.sdk.timeseries.ResamplerConfig
dataclass
¤
Resampler configuration.
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_resampling.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
Attributes¤
align_to: datetime | None = UNIX_EPOCH
class-attribute
instance-attribute
¤
The time to align the resampling period to.
The resampling period will be aligned to this time, so the first resampled
sample will be at the first multiple of resampling_period
starting from
align_to
. It must be an aware datetime and can be in the future too.
If align_to
is None
, the resampling period will be aligned to the
time the resampler is created.
initial_buffer_len: int = DEFAULT_BUFFER_LEN_INIT
class-attribute
instance-attribute
¤
The initial length of the resampling buffer.
The buffer could grow or shrink depending on the source properties, like sampling rate, to make sure all the requested past sampling periods can be stored.
It must be at least 1 and at most max_buffer_len
.
max_buffer_len: int = DEFAULT_BUFFER_LEN_MAX
class-attribute
instance-attribute
¤
The maximum length of the resampling buffer.
Buffers won't be allowed to grow beyond this point even if it would be needed to keep all the requested past sampling periods. An error will be emitted in the logs if the buffer length needs to be truncated to this value.
It must be at bigger than warn_buffer_len
.
max_data_age_in_periods: float = 3.0
class-attribute
instance-attribute
¤
The maximum age a sample can have to be considered relevant for resampling.
Expressed in number of periods, where period is the resampling_period
if we are downsampling (resampling period bigger than the input period) or
the input sampling period if we are upsampling (input period bigger than
the resampling period).
It must be bigger than 1.0.
Example
If resampling_period
is 3 seconds, the input sampling period is
1 and max_data_age_in_periods
is 2, then data older than 3*2
= 6 seconds will be discarded when creating a new sample and never
passed to the resampling function.
If resampling_period
is 3 seconds, the input sampling period is
5 and max_data_age_in_periods
is 2, then data older than 5*2
= 10 seconds will be discarded when creating a new sample and never
passed to the resampling function.
resampling_function: ResamplingFunction = average
class-attribute
instance-attribute
¤
The resampling function.
This function will be applied to the sequence of relevant samples at a given time. The result of the function is what is sent as the resampled value.
resampling_period: timedelta
instance-attribute
¤
The resampling period.
This is the time it passes between resampled data should be calculated.
It must be a positive time span.
warn_buffer_len: int = DEFAULT_BUFFER_LEN_WARN
class-attribute
instance-attribute
¤
The minimum length of the resampling buffer that will emit a warning.
If a buffer grows bigger than this value, it will emit a warning in the logs, so buffers don't grow too big inadvertently.
It must be at least 1 and at most max_buffer_len
.
Functions¤
__post_init__()
¤
Check that config values are valid.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If any value is out of range. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_resampling.py
frequenz.sdk.timeseries.Sample
dataclass
¤
Bases: Generic[QuantityT]
A measurement taken at a particular point in time.
The value
could be None
if a component is malfunctioning or data is
lacking for another reason, but a sample still needs to be sent to have a
coherent view on a group of component metrics for a particular timestamp.
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_base_types.py
frequenz.sdk.timeseries.Sample3Phase
dataclass
¤
Bases: Generic[QuantityT]
A 3-phase measurement made at a particular point in time.
Each of the value
fields could be None
if a component is malfunctioning
or data is lacking for another reason, but a sample still needs to be sent
to have a coherent view on a group of component metrics for a particular
timestamp.
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_base_types.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
Attributes¤
timestamp: datetime
instance-attribute
¤
The time when this sample was generated.
value_p1: QuantityT | None
instance-attribute
¤
The value of the 1st phase in this sample.
value_p2: QuantityT | None
instance-attribute
¤
The value of the 2nd phase in this sample.
value_p3: QuantityT | None
instance-attribute
¤
The value of the 3rd phase in this sample.
Functions¤
__iter__()
¤
Return an iterator that yields values from each of the phases.
YIELDS | DESCRIPTION |
---|---|
QuantityT | None
|
Per-phase measurements one-by-one. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_base_types.py
map(function, default=None)
¤
Apply the given function on each of the phase values and return the result.
If a phase value is None
, replace it with default
instead.
PARAMETER | DESCRIPTION |
---|---|
function |
The function to apply on each of the phase values.
TYPE:
|
default |
The value to apply if a phase value is
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A new instance, with the given function applied on values for each of the phases. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_base_types.py
max(default=None)
¤
Return the max value among all phases, or default if they are all None
.
PARAMETER | DESCRIPTION |
---|---|
default |
value to return if all phases are
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
QuantityT | None
|
Max value among all phases, if available, default value otherwise. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_base_types.py
min(default=None)
¤
Return the min value among all phases, or default if they are all None
.
PARAMETER | DESCRIPTION |
---|---|
default |
value to return if all phases are
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
QuantityT | None
|
Min value among all phases, if available, default value otherwise. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_base_types.py
frequenz.sdk.timeseries.Temperature
¤
Bases: Quantity
A temperature quantity (in degrees Celsius).
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
Functions¤
as_celsius()
¤
Return the temperature in degrees Celsius.
RETURNS | DESCRIPTION |
---|---|
float
|
The temperature in degrees Celsius. |
from_celsius(value)
classmethod
¤
frequenz.sdk.timeseries.Voltage
¤
Bases: Quantity
A voltage quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
|
Functions¤
__mul__(other)
¤
Return a voltage or power from multiplying this voltage by the given value.
PARAMETER | DESCRIPTION |
---|---|
other |
The percentage or current to multiply by.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self | Power
|
The calculated voltage or power. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the given value is not a percentage or current. |
Source code in /opt/hostedtoolcache/Python/3.11.5/x64/lib/python3.11/site-packages/frequenz/sdk/timeseries/_quantities.py
as_kilovolts()
¤
Return the voltage in kilovolts.
RETURNS | DESCRIPTION |
---|---|
float
|
The voltage in kilovolts. |
as_millivolts()
¤
Return the voltage in millivolts.
RETURNS | DESCRIPTION |
---|---|
float
|
The voltage in millivolts. |