Skip to content

Add helper function to calculate energy metric #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

flora-hofmann-frequenz
Copy link
Contributor

Cumulative energy calculation with all its comments from this PR in new repo.

@flora-hofmann-frequenz flora-hofmann-frequenz requested a review from a team as a code owner September 12, 2024 10:23
@github-actions github-actions bot added part:docs Affects the documentation part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) labels Sep 12, 2024
m1.value * (m2.timestamp - m1.timestamp).total_seconds()
for m1, m2 in zip(metric_samples, metric_samples[1:])
if m1.value > 0
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize we are missing on the last value of the list. But we don't know the sampling period between the last sample in the list and the one that would follow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just discussed: For the last value we know the sampling period from the end time, i.e. metric_samples[-1].value * (end_time - metric_samples[-1].timestamp) should be added to the sum.

consumption = sum(
m2.value - m1.value
for m1, m2 in zip(metric_samples, metric_samples[1:])
if m1.value > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be m2.value - m1.value > 0 (similar below).

end_time=end_time,
consumption=consumption,
production=production,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be test cases for this function. For that you could mock the list... method of the client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, test cases will be added in a follow up PR. I have added Issue #8.

cwasicki
cwasicki previously approved these changes Sep 25, 2024
Copy link
Contributor

@cwasicki cwasicki left a comment

Choose a reason for hiding this comment

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

Just a comment about the sign, otherwise LGTM

If None, no resampling is applied.
Returns:
EnergyMetric: A named tuple with start_time, end_time, consumption, and production
in Wh.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should mention what sign production and consumption have.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's included :-)

@flora-hofmann-frequenz flora-hofmann-frequenz added this pull request to the merge queue Sep 25, 2024
Merged via the queue into frequenz-floss:v0.x.x with commit 44aa6e2 Sep 25, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:docs Affects the documentation part:tooling Affects the development tooling (CI, deployment, dependency management, etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants