Skip to content

Commit 5bbaa9d

Browse files
committed
Address review: move plotting section, remove repeated fetch, add optional comment
Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
1 parent 906ca90 commit 5bbaa9d

1 file changed

Lines changed: 26 additions & 34 deletions

File tree

README.md

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -200,59 +200,51 @@ df = pd.DataFrame(data)
200200
print(df)
201201
```
202202

203-
## Command line client tool
204-
205-
The package contains a command-line tool that can be used to request
206-
microgrid component data from the reporting API.
207-
208-
```bash
209-
reporting-cli \
210-
--url localhost:4711 \
211-
--auth_key=$AUTH_KEY
212-
--sign_secret=$SIGN_SECRET
213-
--mid 42 \
214-
--cid 23 \
215-
--metrics AC_ACTIVE_POWER AC_REACTIVE_POWER \
216-
--start 2024-05-01T00:00:00 \
217-
--end 2024-05-02T00:00:00 \
218-
--format csv \
219-
--states \
220-
--bounds
221-
```
222-
In addition to the default CSV format, individual samples can also be output using the `--format iter` option.
223-
224203
## Plotting data with matplotlib
225204

226205
```bash
227206
pip install matplotlib
228207
```
229208

209+
Using the `data` variable from any of the examples above:
210+
230211
```python
231212
import matplotlib.pyplot as plt
232213
import matplotlib.dates as mdates
233214

234-
# Fetch data (see examples above)
235-
data = [
236-
sample async for sample in
237-
client.receive_single_component_data(
238-
microgrid_id=1,
239-
component_id=100,
240-
metrics=[Metric.AC_ACTIVE_POWER],
241-
start_time=datetime.fromisoformat("2024-05-01T00:00:00"),
242-
end_time=datetime.fromisoformat("2024-05-02T00:00:00"),
243-
resampling_period=timedelta(seconds=60),
244-
)
245-
]
246-
247215
timestamps = [s.timestamp for s in data]
248216
values = [s.value for s in data]
249217

250218
fig, ax = plt.subplots(figsize=(14, 5))
251219
ax.plot(timestamps, values)
220+
221+
# Optional: customize the plot
252222
ax.set_title("AC Active Power")
253223
ax.set_ylabel("Power (W)")
254224
ax.xaxis.set_major_formatter(mdates.DateFormatter("%H:%M"))
255225
ax.grid(True)
256226
fig.tight_layout()
227+
257228
plt.show()
258229
```
230+
231+
## Command line client tool
232+
233+
The package contains a command-line tool that can be used to request
234+
microgrid component data from the reporting API.
235+
236+
```bash
237+
reporting-cli \
238+
--url localhost:4711 \
239+
--auth_key=$AUTH_KEY
240+
--sign_secret=$SIGN_SECRET
241+
--mid 42 \
242+
--cid 23 \
243+
--metrics AC_ACTIVE_POWER AC_REACTIVE_POWER \
244+
--start 2024-05-01T00:00:00 \
245+
--end 2024-05-02T00:00:00 \
246+
--format csv \
247+
--states \
248+
--bounds
249+
```
250+
In addition to the default CSV format, individual samples can also be output using the `--format iter` option.

0 commit comments

Comments
 (0)