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

Remove latest state plot from asset page #493

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion documentation/changelog.rst
Expand Up @@ -23,7 +23,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)