Skip to content

Commit 4ec5c26

Browse files
authored
Update README with usage instructions (#53)
Simple usage example to query multiple metrics from single and multiple microgrids and components.
2 parents 213338a + 1eb71b3 commit 4ec5c26

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,88 @@ The following platforms are officially supported (tested):
2020

2121
If you want to know how to build this project and contribute to it, please
2222
check out the [Contributing Guide](CONTRIBUTING.md).
23+
24+
25+
## Usage
26+
27+
Please also refer to [examples](https://github.com/frequenz-floss/frequenz-client-reporting-python/tree/HEAD/examples) for more detailed usage.
28+
29+
### Installation
30+
31+
```bash
32+
# Choose the version to install
33+
VERSION=0.2.0
34+
pip install frequenz-client-reporting==$VERSION
35+
```
36+
37+
38+
### Initialize the client
39+
40+
```python
41+
from datetime import datetime
42+
43+
from frequenz.client.common.metric import Metric
44+
from frequenz.client.reporting import ReportingApiClient
45+
46+
# Change server address
47+
SERVICE_ADDRESS = "localhost:4711"
48+
client = ReportingApiClient(service_address=SERVICE_ADDRESS)
49+
```
50+
51+
### Query metrics for a single microgrid and component:
52+
53+
```python
54+
data = [
55+
sample async for sample in
56+
client.list_single_component_data(
57+
microgrid_id=1,
58+
component_id=100,
59+
metrics=[Metric.AC_ACTIVE_POWER, Metric.AC_REACTIVE_POWER],
60+
start_dt=datetime.fromisoformat("2024-05-01T00:00:00"),
61+
end_dt=datetime.fromisoformat("2024-05-02T00:00:00"),
62+
page_size=10000,
63+
)
64+
]
65+
```
66+
67+
68+
### Query metrics for multiple microgrids and components
69+
70+
```python
71+
# Set the microgrid ID and the component IDs that belong to the microgrid
72+
# Multiple microgrids and components can be queried at once
73+
microgrid_id1 = 1
74+
component_ids1 = [100, 101, 102]
75+
microgrid_id2 = 2
76+
component_ids2 = [200, 201, 202]
77+
microgrid_components = [
78+
(microgrid_id1, component_ids1),
79+
(microgrid_id2, component_ids2),
80+
]
81+
82+
data = [
83+
sample async for sample in
84+
client.list_microgrid_components_data(
85+
microgrid_components=microgrid_components,
86+
metrics=[Metric.AC_ACTIVE_POWER, Metric.AC_REACTIVE_POWER],
87+
start_dt=datetime.fromisoformat("2024-05-01T00:00:00"),
88+
end_dt=datetime.fromisoformat("2024-05-02T00:00:00"),
89+
page_size=10000,
90+
)
91+
]
92+
```
93+
94+
### Optionally convert the data to a pandas DataFrame
95+
96+
```python
97+
import pandas as pd
98+
df = pd.DataFrame(data)
99+
print(df)
100+
```
101+
102+
## Command line client example
103+
104+
The example folder contains a simple client that can be used to query the reporting API from the command line:
105+
```bash
106+
python examples/client.py --url localhost:4711 --mid 42 --cid 23 --metrics AC_ACTIVE_POWER AC_REACTIVE_POWER --start 2024-05-01T00:00:00 --end 2024-05-02T00:00:00
107+
```

0 commit comments

Comments
 (0)