Skip to content

Add data fetching wrapper - #305

Open
Mohammad-Tayyab-Frequenz wants to merge 2 commits into
frequenz-floss:v0.x.xfrom
Mohammad-Tayyab-Frequenz:add-data-fetching-wrapper
Open

Add data fetching wrapper#305
Mohammad-Tayyab-Frequenz wants to merge 2 commits into
frequenz-floss:v0.x.xfrom
Mohammad-Tayyab-Frequenz:add-data-fetching-wrapper

Conversation

@Mohammad-Tayyab-Frequenz

@Mohammad-Tayyab-Frequenz Mohammad-Tayyab-Frequenz commented May 8, 2026

Copy link
Copy Markdown
Contributor

The metric_data function has been extended from a direct power-only fetcher into a more flexible entry point that can now work in two modes: fetching active power directly or deriving power from cumulative energy data. With the new data_fetch_mode parameter, we can either keep the existing AC_POWER_ACTIVE path or fetch AC_ENERGY_ACTIVE_CONSUMED and AC_ENERGY_ACTIVE_DELIVERED in parallel.

The original functionality of metric_data is shifted to _fetch_metric_data function now.

@Mohammad-Tayyab-Frequenz
Mohammad-Tayyab-Frequenz requested a review from a team as a code owner May 8, 2026 17:23
@github-actions github-actions Bot added the part:docs Affects the documentation label May 8, 2026
Comment thread src/frequenz/data/microgrid/component_data.py Outdated
Comment thread src/frequenz/data/microgrid/component_data.py Outdated
Comment thread src/frequenz/data/microgrid/component_data.py Outdated
Comment thread src/frequenz/data/microgrid/component_data.py
@Mohammad-Tayyab-Frequenz
Mohammad-Tayyab-Frequenz force-pushed the add-data-fetching-wrapper branch 2 times, most recently from cad7ae1 to 8ebeeeb Compare May 21, 2026 19:28
@Mohammad-Tayyab-Frequenz

Copy link
Copy Markdown
Contributor Author

@cwasicki Can you please have a look at this PR again?
Thank you!

@Mohammad-Tayyab-Frequenz
Mohammad-Tayyab-Frequenz force-pushed the add-data-fetching-wrapper branch 2 times, most recently from c7d2f46 to f4cbd38 Compare July 2, 2026 14:36

# pylint: disable=too-many-locals
async def metric_data( # pylint: disable=too-many-arguments
async def _fetch_metric_data( # pylint: disable=too-many-arguments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is it made private? This can be used downstream to fetch arbitrary metrics. The docstring was wrong though.

splits: bool = False,
data_fetch_mode: Literal["power", "energy"] = "power",
) -> pd.DataFrame | None:
"""Return power data for component types of a microgrid.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it's returning ac active power it should go into the ac_active_power function.

keep_components=keep_components,
splits=splits,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't we just use the ac_active_energy_net method instead of the code from here onward?

df: pd.DataFrame, *, resampling_period: timedelta
) -> pd.DataFrame:
"""Convert cumulative energy meter readings into power values."""
return df.diff().shift(-1) * (timedelta(hours=1) / resampling_period)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This might need more care in case the cumulative energy contains zeroes (e.g. on meter restarts).

Signed-off-by: Mohammad Tayyab <Mohammad.Tayyab@neustrom.de>
Signed-off-by: Mohammad Tayyab <Mohammad.Tayyab@neustrom.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants