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 bokeh dependency and obsolete UI views #476

Merged
merged 6 commits into from Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
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 @@ -18,10 +18,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 @@ -231,14 +229,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", ""),
)

Expand Down Expand Up @@ -304,9 +299,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 @@ -319,8 +311,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", ""),
)
patch_asset_response = InternalApi().patch(
Expand All @@ -342,14 +332,11 @@ def post(self, id: str):
asset_form.process_api_validation_errors(patch_asset_response.json())
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", ""),
)

Expand Down Expand Up @@ -402,19 +389,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