Commit d5b5994
authored
Rewrite the resampler class to be more reusable (#101)
First we introduce a timeseries `Source` (async iterator of `Sample`)
and `Sink` (an async function taking a `Sample`) types. The idea is for
all classes in the `timeseries` package to be based on these types.
On advantage of using a function as a `Sink` (instead of a channel) is
that for cases where we don't really need a channel (like if we only
need to store samples in a buffer), there is no added overhead (peak
shaving for example could benefit from this).
The `GroupResampler` and `Resampler` classes are not very reusable, or
at least require quite a bit of work from users to use them and they
need to take care of handling timers and calling methods at the right
time for them to be useful.
The new `Resampler` class has its own task(s) to handle all the
resampling, users only need to subscribe to new timeseries by passing a
timeseries `Source` and `Sink`. The `Sink` will be called each time a
new sample is produced.
A new `frequenz.sdk.timeseries.resampling` module is added because there
are more classes only used by the `Resampler` that might not be needed
by anyone just wanting to use `frequenz.sdk.timeseries`.
This PR also introduces the use of
[`async-solipsism`](https://pypi.org/project/async-solipsism/) (see #70)
for testing, so tests using timers can be mocked in a way that they
don't really need to wait for timers and time comparisons can be done
precisely. It works pretty well in combination with
[`time_machine`](https://pypi.org/project/time-machine/).
Fixes #56.File tree
22 files changed
+1304
-600
lines changed- examples
- src/frequenz/sdk
- actor
- timeseries
- logical_meter
- util
- tests
- actor
- timeseries
- utils
22 files changed
+1304
-600
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
10 | 19 | | |
11 | 20 | | |
12 | 21 | | |
13 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
14 | 31 | | |
15 | 32 | | |
16 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | | - | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
24 | 43 | | |
25 | 44 | | |
26 | 45 | | |
| |||
32 | 51 | | |
33 | 52 | | |
34 | 53 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
38 | 57 | | |
39 | 58 | | |
40 | 59 | | |
| |||
44 | 63 | | |
45 | 64 | | |
46 | 65 | | |
47 | | - | |
48 | | - | |
49 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
50 | 69 | | |
51 | 70 | | |
52 | 71 | | |
| |||
56 | 75 | | |
57 | 76 | | |
58 | 77 | | |
59 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
60 | 81 | | |
61 | 82 | | |
62 | 83 | | |
| |||
69 | 90 | | |
70 | 91 | | |
71 | 92 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 93 | + | |
76 | 94 | | |
77 | 95 | | |
78 | 96 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
84 | 100 | | |
85 | | - | |
| 101 | + | |
86 | 102 | | |
87 | 103 | | |
88 | | - | |
89 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
90 | 125 | | |
91 | 126 | | |
92 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
17 | 24 | | |
18 | 25 | | |
19 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
104 | 103 | | |
105 | 104 | | |
106 | 105 | | |
107 | 106 | | |
108 | 107 | | |
109 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
0 commit comments