Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ check out the [Contributing Guide](CONTRIBUTING.md).

## Usage

Please also refer to [examples](https://github.com/frequenz-floss/frequenz-client-reporting-python/tree/HEAD/examples) for more detailed usage.
Please also refer to source of the [CLI tool](https://github.com/frequenz-floss/frequenz-client-reporting-python/blob/v0.x.x/src/frequenz/client/reporting/cli/__main__.py)
for a practical example of how to use the client.

### Installation

Expand All @@ -43,6 +44,7 @@ pip install frequenz-client-reporting==$VERSION

To use the Reporting API client, you need to initialize it with the server URL and authentication credentials.
The server URL should point to your Frequenz Reporting API instance, and you will need an authentication key and a signing secret.
See [this documentation](https://github.com/frequenz-floss/frequenz-client-base-python/blob/v0.x.x/README.md#authorization-and-signing) for further details.

> **Security Note**
> Always keep your authentication key and signing secret secure. Do not hard-code them in your source code or share them publicly.
Expand All @@ -66,10 +68,10 @@ client = ReportingApiClient(server_url=SERVER_URL, auth_key=AUTH_KEY, sign_secre
### Query metrics for a single microgrid and component

This method supports:
- Selecting specific `microgrid_id` and `component_id`
- Choosing one or more `metrics` to retrieve
- Defining a time range with `start_time` and `end_time`
- Optional downsampling using `resampling_period` (e.g., `timedelta(minutes=15)`)
- Selecting specific `microgrid_id` and `component_id`.
- Choosing one or more `metrics` to retrieve. Available metrics are listed [here](https://github.com/frequenz-floss/frequenz-api-common/blob/v0.8.0/proto/frequenz/api/common/v1alpha8/metrics/metrics.proto).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it is much better, but you could also point to the generated docs:

In a near future, we should probably use client-common and that should have a nice Python doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea: #209

- Defining a time range with `start_time` and `end_time`.
- Optional downsampling using `resampling_period` (e.g., `timedelta(minutes=15)`).

```python
# Asynchronously collect metric data samples into a list
Expand Down Expand Up @@ -168,7 +170,29 @@ data = [
]
```

### Optionally convert the data to a pandas DataFrame
## Usage of formulas

Formulas can be used to calculate a metric aggregated over multiple components or sensors.
Note that this endpoint must be used with a `resampling_period`.
Details on the formula syntax can be found [here](https://github.com/frequenz-floss/frequenz-microgrid-formula-engine-rs/tree/v0.x.x?tab=readme-ov-file#formula-syntax-overview).

```python
# Example formula to sum the values of two components.
formula = "#1 + #2"
data = [
sample async for sample in
client.receive_aggregated_data(
microgrid_id=microgrid_id,
metric=Metric.AC_ACTIVE_POWER,
aggregation_formula=formula,
start_time=datetime.fromisoformat("2024-05-01T00:00:00"),
end_time=datetime.fromisoformat("2024-05-02T00:00:00"),
resampling_period=resampling_period,
)
]
```

## Optionally convert the data to a pandas DataFrame

For easier data manipulation and analysis, you can convert the collected data into a pandas DataFrame.

Expand Down
Loading