Skip to content

Commit

Permalink
Remove bokeh dependency and obsolete UI views (#476)
Browse files Browse the repository at this point in the history
* Remove bokeh dependency, latest state plot, and the analytics and portfolio pages

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

* black

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

* flake8

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

* better placement for button in asset popup

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* changelog entry

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
  • Loading branch information
Flix6x and nhoening committed Aug 31, 2022
1 parent 61fcf56 commit f024c29
Show file tree
Hide file tree
Showing 22 changed files with 14 additions and 3,176 deletions.
2 changes: 2 additions & 0 deletions documentation/changelog.rst
Expand Up @@ -16,6 +16,8 @@ Bugfixes
Infrastructure / Support
----------------------

* Remove bokeh dependency and obsolete UI views [see `PR #476 <http://www.github.com/FlexMeasures/flexmeasures/pull/476>`_]



v0.11.1 | September XX, 2022
Expand Down
17 changes: 0 additions & 17 deletions flexmeasures/ui/__init__.py
@@ -1,7 +1,6 @@
import os

from flask import current_app, Flask, Blueprint
from flask.blueprints import BlueprintSetupState
from flask import send_from_directory
from flask_security import login_required, roles_accepted
import pandas as pd
Expand All @@ -22,7 +21,6 @@
parse_config_entry_by_account_roles,
find_first_applicable_config_entry,
)
from flexmeasures.api.v2_0 import flexmeasures_api as flexmeasures_api_v2_0

# The ui blueprint. It is registered with the Flask app (see app.py)
flexmeasures_ui = Blueprint(
Expand Down Expand Up @@ -67,21 +65,6 @@ def favicon():
add_jinja_filters(app)
add_jinja_variables(app)

# Add our chart endpoint to the Api 2.0 blueprint.
# This lets it show up in the API list twice, but that seems to be the best way for now (see below).
# Also, we'll reconsider where these charts endpoints should really live when we make more.
from flexmeasures.ui.views.charts import get_power_chart

# We cannot call this directly on the blueprint, as that only defers to registration.
# Re-registering the blueprint leads to all endpoints being listed twice.
blueprint_state = BlueprintSetupState(
flexmeasures_api_v2_0,
app,
{"url_prefix": "/api/v2_0"},
first_registration=False,
)
blueprint_state.add_url_rule("/charts/power", None, get_power_chart)


def register_rq_dashboard(app):
app.config.update(
Expand Down
119 changes: 0 additions & 119 deletions flexmeasures/ui/charts/latest_state.py

This file was deleted.

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)
6 changes: 1 addition & 5 deletions flexmeasures/ui/templates/base.html
Expand Up @@ -35,10 +35,6 @@
rel="stylesheet" />
<!-- Custom CSS -->
<link href="{{ url_for('flexmeasures_ui.static', filename='css/flexmeasures.css') }}" rel="stylesheet" />
{% if contains_plots %}
{{ bokeh_css_resources|indent(4)|safe }}
{{ bokeh_js_resources|indent(4)|safe }}
{% endif %}
{% if active_page == "tasks" %}
<link href="{{ url_for('flexmeasures_ui.static', filename='css/external/rq-dashboard-bootstrap.min.css') }}"
rel="stylesheet" />
Expand Down Expand Up @@ -232,7 +228,7 @@
{% block attributions %}
<div id="att-text" style="display: none;">
<ul>
<li>Plots made with <a href="https://bokeh.pydata.org">Bokeh</a>.</li>
<li>Plots made with <a href="https://vega.github.io/vega-lite/">Vega-Lite</a>.</li>
<li>Icons made by <a href="https://freepik.com">Freepik</a>, <a
href="https://www.flaticon.com/authors/tomas-knop" title="Tomas Knop">Tomas Knop</a>, <a
href="https://www.flaticon.com/authors/gregor-cresnar" title="Gregor Cresnar">Gregor Cresnar</a> and
Expand Down
2 changes: 0 additions & 2 deletions flexmeasures/ui/templates/defaults.jinja
Expand Up @@ -12,8 +12,6 @@
"dashboard": dict(title="Dashboard", icon="dashboard"),
"assets": dict(title="Assets", icon="list-ul"),
"users": dict(title="Users", icon="users"),
"portfolio": dict(title="Portfolio overview", icon="briefcase"),
"analytics": dict(title="Analytics", icon="bar-chart"),
"upload": dict(title="Upload data", icon="cloud-upload"),
"control": dict(title="Flexibility actions", icon="wrench")
}
Expand Down

0 comments on commit f024c29

Please sign in to comment.