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

Add endpoint for getting asset annotations #1113

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Ahmad-Wahid
Copy link
Contributor

In this PR, I have add an AssetAPI endpoint in the dev module to fetch annotations data. Also I have refactored annotations query to be to get data for both asset and sensor annotations.

@Ahmad-Wahid Ahmad-Wahid requested a review from Flix6x June 25, 2024 10:10
@Ahmad-Wahid Ahmad-Wahid self-assigned this Jun 25, 2024
Copy link
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

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

Thanks for fixing these endpoints. It looks as if the endpoint for getting sensor annotations was also actually returning the annotations on the sensor's asset rather than on the sensor itself.

flexmeasures/data/queries/annotations.py Outdated Show resolved Hide resolved
flexmeasures/data/models/generic_assets.py Outdated Show resolved Hide resolved
@Flix6x
Copy link
Contributor

Flix6x commented Jul 17, 2024

Also, please check GH Actions, which is reporting a mypy issue on this PR.

@nhoening nhoening added this to the 0.24.0 milestone Sep 16, 2024
@@ -355,6 +359,8 @@ def search_annotations(
annotation_type: str = None,
include_account_annotations: bool = False,
as_frame: bool = False,
sensor_id: int = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be named asset_id (or asset_or_sensor_id)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I don't think we need it. See my comment about using calling this method on the instance rather than the class.

"""
event_starts_after = kwargs.get("event_starts_after", None)
event_ends_before = kwargs.get("event_ends_before", None)
if asset_or_sensor is GenericAsset:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is always False, because this compares an Asset or Sensor instance (in asset_or_sensor) to an Asset class.



def get_annotations_data(
sensor_id: int | None,
Copy link
Contributor

Choose a reason for hiding this comment

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

This parameter seems redundant, since we are already passing the sensor or asset instance itself.

Comment on lines +232 to +235
if asset_or_sensor is GenericAsset:
asset_or_sensor_class = asset_or_sensor.generic_asset
else:
asset_or_sensor_class = asset_or_sensor
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if asset_or_sensor is GenericAsset:
asset_or_sensor_class = asset_or_sensor.generic_asset
else:
asset_or_sensor_class = asset_or_sensor
asset_or_sensor_class = asset_or_sensor.__class__

else:
asset_or_sensor_class = asset_or_sensor

df = asset_or_sensor_class.search_annotations(
Copy link
Contributor

@Flix6x Flix6x Sep 23, 2024

Choose a reason for hiding this comment

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

Why do we need the class, actually? Isn't search_annotations a method we can call on the instance rather than the class? Its function signature does suggest so, because its first parameter is self rather than cls.

Suggested change
df = asset_or_sensor_class.search_annotations(
df = asset_or_sensor.search_annotations(

)
from flexmeasures.data.models.data_sources import DataSource


def query_asset_annotations(
asset_id: int,
asset_or_sensor_id: int,
relationship_module,
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing type annotation, possibly an Enum with the 3 relationship choices we currently have (with Accounts, GenericAssets and Sensors).

flexmeasures/data/queries/annotations.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants