Skip to content

Commit

Permalink
Backport PR #493: Remove latest state plot from asset page (#493)
Browse files Browse the repository at this point in the history
Stop letting the server create an obsolete bokeh plot of the latest state on the asset page.

* Remove latest state plot from asset page

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Flix6x committed Sep 5, 2022
1 parent 05d2936 commit 8bec4f7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
2 changes: 1 addition & 1 deletion documentation/changelog.rst
Expand Up @@ -7,7 +7,7 @@ v0.11.1 | September XX, 2022

Bugfixes
-----------

* Do not fail asset page if none of the sensors has any data [see `PR #492 <http://www.github.com/FlexMeasures/flexmeasures/pull/492>`_]


v0.11.0 | August 28, 2022
Expand Down
29 changes: 0 additions & 29 deletions flexmeasures/ui/crud/assets.py
Expand Up @@ -20,10 +20,8 @@
)
from flexmeasures.data.models.user import Account
from flexmeasures.data.models.time_series import Sensor
from flexmeasures.ui.charts.latest_state import get_latest_power_as_plot
from flexmeasures.ui.utils.view_utils import render_flexmeasures_template
from flexmeasures.ui.crud.api_wrapper import InternalApi
from flexmeasures.utils.unit_utils import is_power_unit


"""
Expand Down Expand Up @@ -259,14 +257,11 @@ def get(self, id: str):
asset = process_internal_api_response(asset_dict, int(id), make_obj=True)
asset_form.process(data=process_internal_api_response(asset_dict))

latest_measurement_time_str, asset_plot_html = _get_latest_power_plot(asset)
return render_flexmeasures_template(
"crud/asset.html",
asset=asset,
asset_form=asset_form,
msg="",
latest_measurement_time_str=latest_measurement_time_str,
asset_plot_html=asset_plot_html,
mapboxAccessToken=current_app.config.get("MAPBOX_ACCESS_TOKEN", ""),
user_can_create_assets=user_can_create_assets(),
user_can_delete_asset=user_can_delete(asset),
Expand Down Expand Up @@ -337,9 +332,6 @@ def post(self, id: str):
asset_form = with_options(AssetForm())
if not asset_form.validate_on_submit():
asset = GenericAsset.query.get(id)
latest_measurement_time_str, asset_plot_html = _get_latest_power_plot(
asset
)
# Display the form data, but set some extra data which the page wants to show.
asset_info = asset_form.to_json()
asset_info["id"] = id
Expand All @@ -352,8 +344,6 @@ def post(self, id: str):
asset_form=asset_form,
asset=asset,
msg="Cannot edit asset.",
latest_measurement_time_str=latest_measurement_time_str,
asset_plot_html=asset_plot_html,
mapboxAccessToken=current_app.config.get("MAPBOX_ACCESS_TOKEN", ""),
user_can_create_assets=user_can_create_assets(),
user_can_delete_asset=user_can_delete(asset),
Expand All @@ -379,14 +369,11 @@ def post(self, id: str):
)
asset = GenericAsset.query.get(id)

latest_measurement_time_str, asset_plot_html = _get_latest_power_plot(asset)
return render_flexmeasures_template(
"crud/asset.html",
asset=asset,
asset_form=asset_form,
msg=msg,
latest_measurement_time_str=latest_measurement_time_str,
asset_plot_html=asset_plot_html,
mapboxAccessToken=current_app.config.get("MAPBOX_ACCESS_TOKEN", ""),
user_can_create_assets=user_can_create_assets(),
user_can_delete_asset=user_can_delete(asset),
Expand Down Expand Up @@ -441,19 +428,3 @@ def _set_asset_type(
else:
current_app.logger.error(asset_type_error)
return asset_type, asset_type_error


def _get_latest_power_plot(asset: GenericAsset) -> Tuple[str, str]:
power_sensor: Optional[Sensor] = None
if asset._sa_instance_state.transient:
sensors = Sensor.query.filter(Sensor.generic_asset_id == asset.id).all()
else:
sensors = asset.sensors
for sensor in sensors:
if is_power_unit(sensor.unit):
power_sensor = sensor
break
if power_sensor is None:
return "", ""
else:
return get_latest_power_as_plot(power_sensor)

0 comments on commit 8bec4f7

Please sign in to comment.