Skip to content

Commit

Permalink
Update README with usage instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
cwasicki committed May 3, 2024
1 parent 05d7e05 commit 2ffddef
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,77 @@ The following platforms are officially supported (tested):

If you want to know how to build this project and contribute to it, please
check out the [Contributing Guide](CONTRIBUTING.md).


## Installation

```bash
# Choose the version to install
VERSION=0.2.0
pip install frequenz-client-reporting==$VERSION
```

## Usage

```python
from datetime import datetime

from frequenz.client.common.metric import Metric
from frequenz.client.reporting import ReportingApiClient

# Change server address
SERVICE_ADDRESS = "localhost:4711"
client = ReportingApiClient(service_address=SERVICE_ADDRESS)
```

### Query metrics for a single microgrid and component:
```python
data = [
sample async for sample in
client.iterate_single_component(
microgrid_id=1,
component_id=100,
metrics=[Metric.AC_ACTIVE_POWER, Metric.AC_REACTIVE_POWER],
start_dt=datetime.fromisoformat("2024-05-01T00:00:00"),
end_dt=datetime.fromisoformat("2024-05-02T00:00:00"),
page_size=10000,
)
]

# Optionally convert the data to a pandas DataFrame
import pandas as pd
df = pd.DataFrame(data)
print(df)
```


### Query metrics for multiple microgrids and components
```python
# Set the microgrid ID and the component IDs that belong to the microgrid
# Multiple microgrids and components can be queried at once
microgrid_id1 = 1
component_ids1 = [100, 101, 102]
microgrid_id2 = 2
component_ids2 = [200, 201, 202]
microgrid_components = [
(microgrid_id1, component_ids1),
(microgrid_id2, component_ids2),
]

# Query the data
data = [
sample async for sample in
client.list_microgrid_components_data(
microgrid_components=microgrid_components,
metrics=[Metric.AC_ACTIVE_POWER, Metric.AC_REACTIVE_POWER],
start_dt=datetime.fromisoformat("2024-05-01T00:00:00"),
end_dt=datetime.fromisoformat("2024-05-02T00:00:00"),
page_size=10000,
)
]

# Optionally convert the data to a pandas DataFrame
import pandas as pd
df = pd.DataFrame(data)
print(df)
```

0 comments on commit 2ffddef

Please sign in to comment.