Skip to content

Commit f418214

Browse files
committed
docs: Indent examples
This is needed to get them properly rendered and in a collapsable way. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 7dc14f5 commit f418214

File tree

5 files changed

+229
-181
lines changed

5 files changed

+229
-181
lines changed

src/frequenz/sdk/actor/resampling.py

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -71,73 +71,73 @@ def __init__( # pylint: disable=too-many-arguments
7171
a resampling period to produce a single output sample
7272
7373
Example:
74-
```python
75-
async def run() -> None:
76-
await microgrid_api.initialize(HOST, PORT)
74+
```python
75+
async def run() -> None:
76+
await microgrid_api.initialize(HOST, PORT)
7777
78-
channel_registry = ChannelRegistry(name="Microgrid Channel Registry")
78+
channel_registry = ChannelRegistry(name="Microgrid Channel Registry")
7979
80-
data_source_request_channel = Broadcast[ComponentMetricRequest](
81-
"Data Source Request Channel"
82-
)
83-
data_source_request_sender = data_source_request_channel.get_sender()
84-
data_source_request_receiver = data_source_request_channel.get_receiver()
85-
86-
resampling_actor_request_channel = Broadcast[ComponentMetricRequest](
87-
"Resampling Actor Request Channel"
88-
)
89-
resampling_actor_request_sender = resampling_actor_request_channel.get_sender()
90-
resampling_actor_request_receiver = resampling_actor_request_channel.get_receiver()
80+
data_source_request_channel = Broadcast[ComponentMetricRequest](
81+
"Data Source Request Channel"
82+
)
83+
data_source_request_sender = data_source_request_channel.get_sender()
84+
data_source_request_receiver = data_source_request_channel.get_receiver()
9185
92-
_data_sourcing_actor = DataSourcingActor(
93-
request_receiver=data_source_request_receiver, registry=channel_registry
94-
)
86+
resampling_actor_request_channel = Broadcast[ComponentMetricRequest](
87+
"Resampling Actor Request Channel"
88+
)
89+
resampling_actor_request_sender = resampling_actor_request_channel.get_sender()
90+
resampling_actor_request_receiver = resampling_actor_request_channel.get_receiver()
9591
96-
_resampling_actor = ComponentMetricsResamplingActor(
97-
channel_registry=channel_registry,
98-
subscription_sender=data_source_request_sender,
99-
subscription_receiver=resampling_actor_request_receiver,
100-
resampling_period_s=1.0,
101-
)
92+
_data_sourcing_actor = DataSourcingActor(
93+
request_receiver=data_source_request_receiver, registry=channel_registry
94+
)
10295
103-
components = await microgrid_api.get().microgrid_api_client.components()
104-
battery_ids = [
105-
comp.component_id
106-
for comp in components
107-
if comp.category == ComponentCategory.BATTERY
108-
]
109-
110-
subscription_requests = [
111-
ComponentMetricRequest(
112-
namespace="Resampling",
113-
component_id=component_id,
114-
metric_id=ComponentMetricId.SOC,
115-
start_time=None,
96+
_resampling_actor = ComponentMetricsResamplingActor(
97+
channel_registry=channel_registry,
98+
subscription_sender=data_source_request_sender,
99+
subscription_receiver=resampling_actor_request_receiver,
100+
resampling_period_s=1.0,
116101
)
117-
for component_id in battery_ids
118-
]
119102
120-
await asyncio.gather(
121-
*[
122-
resampling_actor_request_sender.send(request)
123-
for request in subscription_requests
103+
components = await microgrid_api.get().microgrid_api_client.components()
104+
battery_ids = [
105+
comp.component_id
106+
for comp in components
107+
if comp.category == ComponentCategory.BATTERY
124108
]
125-
)
126109
127-
sample_receiver = MergeNamed(
128-
**{
129-
channel_name: channel_registry.get_receiver(channel_name)
130-
for channel_name in map(
131-
lambda req: req.get_channel_name(), subscription_requests
110+
subscription_requests = [
111+
ComponentMetricRequest(
112+
namespace="Resampling",
113+
component_id=component_id,
114+
metric_id=ComponentMetricId.SOC,
115+
start_time=None,
132116
)
133-
}
134-
)
117+
for component_id in battery_ids
118+
]
119+
120+
await asyncio.gather(
121+
*[
122+
resampling_actor_request_sender.send(request)
123+
for request in subscription_requests
124+
]
125+
)
126+
127+
sample_receiver = MergeNamed(
128+
**{
129+
channel_name: channel_registry.get_receiver(channel_name)
130+
for channel_name in map(
131+
lambda req: req.get_channel_name(), subscription_requests
132+
)
133+
}
134+
)
135135
136-
async for channel_name, msg in sample_receiver:
137-
print(msg)
136+
async for channel_name, msg in sample_receiver:
137+
print(msg)
138138
139-
asyncio.run(run())
140-
```
139+
asyncio.run(run())
140+
```
141141
"""
142142
self._channel_registry = channel_registry
143143
self._subscription_sender = subscription_sender

src/frequenz/sdk/configs/config.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,14 @@ def get_as(self, key: str, expected_type: Any) -> Any:
103103
Value for the specified key, converted to specified type.
104104
105105
Example:
106-
For var1='[1, 2.0, 3.5]':
107-
* get_as("var1", List[int]) -> [1,2,3]
108-
* get_as("var1", List[float]) -> [1.0,2.0,3.5]
109-
* get_as("var1", List[pydantic.StrictInt]) -> ValueError
110-
* get_as("var1", List[pydantic.StrictFloat]) -> ValueError
111-
For var1='[1,2,3]':
112-
* get_as("var1", List[pydantic.StrictInt]) -> [1,2,3]
106+
For `var1='[1, 2.0, 3.5]'`:
107+
* `get_as("var1", List[int])` -> `[1,2,3]`
108+
* `get_as("var1", List[float])` -> `[1.0,2.0,3.5]`
109+
* `get_as("var1", List[pydantic.StrictInt])` -> [ValueError][]
110+
* `get_as("var1", List[pydantic.StrictFloat])` -> [ValueError][]
111+
112+
For `var1='[1,2,3]'`:
113+
* `get_as("var1", List[pydantic.StrictInt])` -> `[1,2,3]`
113114
114115
"""
115116
value = self[key]

src/frequenz/sdk/power_distribution/distribution_algorithm.py

Lines changed: 102 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -122,63 +122,108 @@ def __init__(self, distributor_exponent: float = 1) -> None:
122122
* 3 - means proportion would be like x^3 from SoC.
123123
124124
Example:
125-
Lets say we have two batteries Bat1 and Bat2. All parameters
126-
except SoC are equal.
127-
SoC bounds for each battery is lower = 20, upper = 80.
128-
129-
Example1:
130-
Let Bat1.soc = 70 and Bat2.soc = 50.
131-
Bat1.available_soc = 10, Bat2.available_soc = 30
132-
Bat1.available_soc / Bat2.available_soc = 3
133-
We need to distribute 8000W.
134-
If distribution_exponent is
135-
* 0: distribution for each battery will be the equal.
136-
Bat1.distribution = 4000; Bat2.distribution = 4000
137-
* 1: then Bat2 will have 3x more power assigned then Bat1.
138-
10x+30x = 8000
139-
x = 200
140-
Bat1.distribution = 2000; Bat2.distribution = 6000
141-
* 2: then Bat2 will have 9x more power assigned then Bat1.
142-
(10)^2 * x + (30)^2 * x = 8000
143-
x = 80
144-
Bat1.distribution = 800; Bat2.distribution = 7200
145-
* 3: then Bat2 will have 27x more power assigned then Bat1.
146-
(10)^3 * x + (30)^3 * x = 8000
147-
x = 0,285714286
148-
Bat1.distribution = 285; Bat2.distribution = 7715
149-
150-
Example2:
151-
Let Bat1.soc = 50 and Bat2.soc = 20.
152-
Bat1.available_soc = 30, Bat2.available_soc = 60
153-
Bat1.available_soc / Bat2.available_soc = 2
154-
We need to distribute 900W.
155-
If distribution_exponent is
156-
* 0: distribution for each battery will be the same.
157-
Bat1.distribution = 4500; Bat2.distribution = 450
158-
* 1: then Bat2 will have 2x more power assigned then Bat1.
159-
30x + 60x = 900
160-
x = 100
161-
Bat1.distribution = 300; Bat2.distribution = 600
162-
* 2: then Bat2 will have 4x more power assigned then Bat1.
163-
30^2 * x + 60^2 * x = 900
164-
x = 0.2
165-
Bat1.distribution = 180; Bat2.distribution = 720
166-
* 3: then Bat2 will have 8x more power assigned then Bat1.
167-
30^3 * x + 60^3 * x = 900
168-
x = 0,003703704
169-
Bat1.distribution = 100; Bat2.distribution = 800
170-
171-
Example3:
172-
Let Bat1.soc = 44 and Bat2.soc = 64.
173-
Bat1.available_soc = 36 (80 - 44), Bat2.available_soc = 16 (80 - 64)
174-
We need to distribute 900W.
175-
If distribution_exponent is
176-
* 0: distribution for each battery will be the equal.
177-
Bat1.distribution = 450; Bat2.distribution = 450
178-
* 0.5: then Bat2 will have 6/4x more power assigned then Bat1.
179-
sqrt(36)x + sqrt(16)x = 900
180-
x = 100
181-
Bat1.distribution = 600; Bat2.distribution = 400
125+
Lets say we have two batteries `Bat1` and `Bat2`. All parameters
126+
except SoC are equal. SoC bounds for each battery is `lower = 20`,
127+
`upper = 80`.
128+
129+
# Example 1
130+
131+
Let:
132+
133+
* `Bat1.soc = 70` and `Bat2.soc = 50`.
134+
* `Bat1.available_soc = 10`, `Bat2.available_soc = 30`
135+
* `Bat1.available_soc / Bat2.available_soc = 3`
136+
137+
We need to distribute 8000W.
138+
139+
If `distribution_exponent` is:
140+
141+
* `0`: distribution for each battery will be the equal.
142+
``` python
143+
Bat1.distribution = 4000; Bat2.distribution = 4000
144+
```
145+
146+
* `1`: then `Bat2` will have 3x more power assigned then `Bat1`.
147+
``` python
148+
10 * x + 30 * x = 8000
149+
x = 200
150+
Bat1.distribution = 2000; Bat2.distribution = 6000
151+
```
152+
153+
* `2`: then `Bat2` will have 9x more power assigned then `Bat1`.
154+
``` python
155+
10^2 * x + 30^2 * x = 8000
156+
x = 80
157+
Bat1.distribution = 800; Bat2.distribution = 7200
158+
```
159+
160+
* `3`: then `Bat2` will have 27x more power assigned then `Bat1`.
161+
``` python
162+
10^3 * x + 30^3 * x = 8000
163+
x = 0,285714286
164+
Bat1.distribution = 285; Bat2.distribution = 7715
165+
```
166+
167+
# Example 2
168+
169+
Let:
170+
171+
* `Bat1.soc = 50` and `Bat2.soc = 20`.
172+
* `Bat1.available_soc = 30`, `Bat2.available_soc = 60`
173+
* `Bat1.available_soc / Bat2.available_soc = 2`
174+
175+
We need to distribute 900W.
176+
177+
If `distribution_exponent` is:
178+
179+
* `0`: distribution for each battery will be the same.
180+
``` python
181+
Bat1.distribution = 4500; Bat2.distribution = 450
182+
```
183+
184+
* `1`: then `Bat2` will have 2x more power assigned then `Bat1`.
185+
``` python
186+
30 * x + 60 * x = 900
187+
x = 100
188+
Bat1.distribution = 300; Bat2.distribution = 600
189+
```
190+
191+
* `2`: then `Bat2` will have 4x more power assigned then `Bat1`.
192+
``` python
193+
30^2 * x + 60^2 * x = 900
194+
x = 0.2
195+
Bat1.distribution = 180; Bat2.distribution = 720
196+
```
197+
198+
* `3`: then `Bat2` will have 8x more power assigned then `Bat1`.
199+
``` python
200+
30^3 * x + 60^3 * x = 900
201+
x = 0,003703704
202+
Bat1.distribution = 100; Bat2.distribution = 800
203+
```
204+
205+
# Example 3
206+
207+
Let:
208+
209+
* `Bat1.soc = 44` and `Bat2.soc = 64`.
210+
* `Bat1.available_soc = 36 (80 - 44)`, `Bat2.available_soc = 16 (80 - 64)`
211+
212+
We need to distribute 900W.
213+
214+
If `distribution_exponent` is:
215+
216+
* `0`: distribution for each battery will be the equal.
217+
``` python
218+
Bat1.distribution = 450; Bat2.distribution = 450
219+
```
220+
221+
* `0.5`: then `Bat2` will have 6/4x more power assigned then `Bat1`.
222+
``` python
223+
sqrt(36) * x + sqrt(16) * x = 900
224+
x = 100
225+
Bat1.distribution = 600; Bat2.distribution = 400
226+
```
182227
183228
Raises:
184229
ValueError: If distributor_exponent < 0

0 commit comments

Comments
 (0)