Skip to content
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

Issue 376 facilitate saving feedback annotations #377

Merged
merged 11 commits into from Mar 3, 2022

Conversation

Flix6x
Copy link
Contributor

@Flix6x Flix6x commented Feb 25, 2022

This PR offers better support for saving and counting annotations on the level of generic assets. It also implements a Marshmallow validation field for generic asset ids.

closes #376

Signed-off-by: F.N. Claessen <felix@seita.nl>
…tion type, and support returning an annotation data frame

Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
@Flix6x Flix6x self-assigned this Feb 25, 2022
@coveralls
Copy link
Collaborator

coveralls commented Feb 25, 2022

Pull Request Test Coverage Report for Build 1928181827

  • 31 of 70 (44.29%) changed or added relevant lines in 5 files are covered.
  • 374 unchanged lines in 21 files lost coverage.
  • Overall coverage decreased (-1.5%) to 69.104%

Changes Missing Coverage Covered Lines Changed/Added Lines %
flexmeasures/data/queries/annotations.py 12 16 75.0%
flexmeasures/data/schemas/generic_assets.py 4 9 44.44%
flexmeasures/data/models/generic_assets.py 8 16 50.0%
flexmeasures/data/models/annotations.py 5 27 18.52%
Files with Coverage Reduction New Missed Lines %
flexmeasures/data/models/legacy_migration_utils.py 1 92.86%
flexmeasures/data/services/users.py 1 85.63%
flexmeasures/ui/charts/latest_state.py 1 79.31%
flexmeasures/ui/utils/plotting_utils.py 1 46.2%
flexmeasures/cli/data_delete.py 2 26.11%
flexmeasures/conftest.py 2 98.74%
flexmeasures/data/models/generic_assets.py 4 71.08%
flexmeasures/data/schemas/sensors.py 4 78.79%
flexmeasures/ui/views/analytics.py 5 44.35%
flexmeasures/data/services/asset_grouping.py 6 80.46%
Totals Coverage Status
Change from base Build 1900760815: -1.5%
Covered Lines: 6670
Relevant Lines: 9174

💛 - Coveralls

@Flix6x Flix6x requested a review from nhoening February 28, 2022 10:00
flexmeasures/data/schemas/generic_assets.py Show resolved Hide resolved
) -> List["Annotation"]:
"""Save a data frame with annotations.

Expects the following columns (or multi-index levels):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate why this function should expect a DataFrame and not, say, a dict?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I just happened to be handling a DataFrame with annotations in our GripOnGas plugin. There, the choice for a DataFrame makes sense because of the slicing and sorting functionality of the timing columns. So here, I designed just what I needed, a function to save annotations that accepts input in the form I already had.

Copy link
Contributor

Choose a reason for hiding this comment

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

My take after thinking about this again: These functions are not for saving finished Annotations (the best way then would be to pass Annotation objects), but to create and save multiple annotations from raw data (for which a data frame is a good representation).

There are method names to better represent this fact. I also looked up the similar method TimedBelief.add (which in similar fashion gets a BeliefsDataFrame).

I thus believe Annotation.add would be a better choice for a name here.

We can then (in this PR or in follow-ups, I'd add TODOs) also use similar parameters:

  • expunge_session
  • allow_overwrite
  • bulk_save_objects
  • commit_transaction (you have this, requires just a renaming)

@Flix6x Flix6x requested a review from nhoening March 3, 2022 09:55
Copy link
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

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

Unsurprisingly, I have a renaming request.

) -> List["Annotation"]:
"""Save a data frame with annotations.

Expects the following columns (or multi-index levels):
Copy link
Contributor

Choose a reason for hiding this comment

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

My take after thinking about this again: These functions are not for saving finished Annotations (the best way then would be to pass Annotation objects), but to create and save multiple annotations from raw data (for which a data frame is a good representation).

There are method names to better represent this fact. I also looked up the similar method TimedBelief.add (which in similar fashion gets a BeliefsDataFrame).

I thus believe Annotation.add would be a better choice for a name here.

We can then (in this PR or in follow-ups, I'd add TODOs) also use similar parameters:

  • expunge_session
  • allow_overwrite
  • bulk_save_objects
  • commit_transaction (you have this, requires just a renaming)

Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: F.N. Claessen <felix@seita.nl>
@Flix6x Flix6x requested a review from nhoening March 3, 2022 13:11
@Flix6x Flix6x merged commit 2092408 into main Mar 3, 2022
@Flix6x Flix6x deleted the Issue-376_Facilitate_saving_feedback_annotations branch March 3, 2022 17:55
@Flix6x Flix6x added this to the 0.9.0 milestone Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Facilitate saving feedback annotations
3 participants