@@ -200,59 +200,51 @@ df = pd.DataFrame(data)
200200print (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
227206pip install matplotlib
228207```
229208
209+ Using the ` data ` variable from any of the examples above:
210+
230211``` python
231212import matplotlib.pyplot as plt
232213import 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-
247215timestamps = [s.timestamp for s in data]
248216values = [s.value for s in data]
249217
250218fig, ax = plt.subplots(figsize = (14 , 5 ))
251219ax.plot(timestamps, values)
220+
221+ # Optional: customize the plot
252222ax.set_title(" AC Active Power" )
253223ax.set_ylabel(" Power (W)" )
254224ax.xaxis.set_major_formatter(mdates.DateFormatter(" %H:%M" ))
255225ax.grid(True )
256226fig.tight_layout()
227+
257228plt.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