flexmeasures.ui.utils.view_utils
Utilities for views
Functions
- flexmeasures.ui.utils.view_utils.asset_icon_name(asset_type_name: str) str
Icon name for this asset type.
This can be used for UI html templates made with Jinja. ui.__init__ makes this function available as the filter “asset_icon”.
- For example:
<i class={{ asset_type.name | asset_icon }}></i>
- becomes (for a battery):
<i class=”icon-battery”></i>
- flexmeasures.ui.utils.view_utils.clear_session()
- flexmeasures.ui.utils.view_utils.ensure_timing_vars_are_set(time_window: tuple[datetime | None, datetime | None], resolution: str | None) tuple[tuple[datetime, datetime], str]
Ensure that time window and resolution variables are set, even if we don’t have them available ― in that case, get them from the session.
- flexmeasures.ui.utils.view_utils.get_git_description() tuple[str, int, str]
Get information about the SCM (git) state if possible (if a .git directory exists).
Returns the latest git version (tag) as a string, the number of commits since then as an int and the current commit hash as string.
- flexmeasures.ui.utils.view_utils.render_flexmeasures_template(html_filename: str, **variables)
Render template and add all expected template variables, plus the ones given as **variables.
- flexmeasures.ui.utils.view_utils.set_individual_traces_for_session()
Set session[“showing_individual_traces_for”] to a value (“none”, “power”, “schedules”).
- flexmeasures.ui.utils.view_utils.set_session_market(resource: Resource) Market
Set session[“market”] to something, based on the available markets or the request. Returns the selected market, or None.
- flexmeasures.ui.utils.view_utils.set_session_resource(assets: list[Asset], groups_with_assets: list[str]) Resource | None
Set session[“resource”] to something, based on the available asset groups or the request.
Returns the selected resource instance, or None.
- flexmeasures.ui.utils.view_utils.set_session_sensor_type(accepted_sensor_types: list[flexmeasures.data.models.weather.WeatherSensorType]) WeatherSensorType
Set session[“sensor_type”] to something, based on the available sensor types or the request. Returns the selected sensor type, or None.
- flexmeasures.ui.utils.view_utils.set_time_range_for_session()
Set period on session if they are not yet set. The daterangepicker sends times as tz-aware UTC strings. We re-interpret them as being in the server’s timezone. Also set the forecast horizon, if given.
- TODO: event_[stars|ends]_before are used on the new asset and sensor pages.
We simply store the UTC strings. It might be that the other settings & logic can be deprecated when we clean house. Tip: grep for timerangeEnd, where end_time is used in our base template,
and then used in the daterangepicker. We seem to use litepicker now.