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

Allow editing asset attributes in the UI #474

Merged
merged 13 commits into from Aug 25, 2022

Conversation

Flix6x
Copy link
Contributor

@Flix6x Flix6x commented Aug 11, 2022

This PR adds an editable text field that can be used to update the asset's attributes by editing the full JSON string.

…tes column on the generic_asset table)

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 Aug 11, 2022
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 added this to the 0.11.0 milestone Aug 11, 2022
@coveralls
Copy link
Collaborator

coveralls commented Aug 11, 2022

Pull Request Test Coverage Report for Build 2926558069

  • 13 of 18 (72.22%) changed or added relevant lines in 2 files are covered.
  • 149 unchanged lines in 9 files lost coverage.
  • Overall coverage increased (+0.2%) to 67.73%

Changes Missing Coverage Covered Lines Changed/Added Lines %
flexmeasures/ui/crud/assets.py 3 8 37.5%
Files with Coverage Reduction New Missed Lines %
flexmeasures/ui/crud/assets.py 1 74.18%
flexmeasures/data/models/planning/battery.py 2 94.19%
flexmeasures/data/services/scheduling.py 2 91.03%
flexmeasures/data/models/planning/solver.py 3 86.89%
flexmeasures/conftest.py 4 98.19%
flexmeasures/data/models/planning/charging_station.py 5 85.37%
flexmeasures/data/models/planning/utils.py 10 83.33%
flexmeasures/api/v3_0/sensors.py 28 70.26%
flexmeasures/cli/data_add.py 94 31.11%
Totals Coverage Status
Change from base Build 2825554854: 0.2%
Covered Lines: 7259
Relevant Lines: 10147

💛 - Coveralls

@Flix6x Flix6x marked this pull request as ready for review August 11, 2022 12:47
@Flix6x Flix6x requested a review from nhoening August 11, 2022 12:47
@Flix6x Flix6x added this to In progress in Update UI views for Sensors and Assets via automation Aug 13, 2022
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.

I think this needs a fix for validating the input.

Ideally, I'd ask for amending the test test_post_an_asset_with_invalid_data in api/v3_0/tests/test_assets_api.py to make sure this validation is working.

try:
return json.loads(value)
except ValueError:
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this not raise a validation error, if content is non empty?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this line is a problem. I edited asset attributes with invalid JSON, which got accepted.

In the database, the asset's attributes are actually null now. Maybe this is due to this line, giving None if the input is not valid.

Now, loading the asset page fails:

  File "/home/nicolas/workspace/seita/flexmeasures/flexmeasures/ui/charts/latest_state.py", line 57, in get_latest_power_as_plot
    capacity_in_mw = sensor.get_attribute("capacity_in_mw", latest_power_value)
  File "/home/nicolas/workspace/seita/flexmeasures/flexmeasures/data/models/time_series.py", line 168, in get_attribute
    if attribute in self.generic_asset.attributes:
TypeError: argument of type 'NoneType' is not iterable

The CLI also fails to show the asset now:

  File "/home/nicolas/workspace/seita/flexmeasures/flexmeasures/cli/data_show.py", line 170, in show_generic_asset
    "".join([f"{k}:{v}\n" for k, v in asset.attributes.items()]),
AttributeError: 'NoneType' object has no attribute 'items'

flexmeasures/ui/crud/assets.py Outdated Show resolved Hide resolved
Update UI views for Sensors and Assets automation moved this from In progress to Review in progress Aug 21, 2022
@nhoening
Copy link
Contributor

With this PR, we could add a note to the asset page's documentation, noting that one can now edit sensors_to_show and thus create a custom asset view.

Definitely right now a feature for more professional users. But it's there.

Wouldn't that tie together changes made for 0.11 nicely?

@Flix6x
Copy link
Contributor Author

Flix6x commented Aug 24, 2022

It would definitely be nice to include. I'm on it.

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 requested a review from nhoening August 24, 2022 19:42
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Update UI views for Sensors and Assets automation moved this from Review in progress to Reviewer approved Aug 25, 2022
@nhoening nhoening merged commit 643e4d5 into main Aug 25, 2022
Update UI views for Sensors and Assets automation moved this from Reviewer approved to Done Aug 25, 2022
@nhoening nhoening deleted the allow_editing_asset_attributes_in_the_UI branch August 25, 2022 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants