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

Determine resolution for plots from data first, then from session #49

Merged
merged 5 commits into from Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 22 additions & 17 deletions flexmeasures/ui/views/analytics.py
Expand Up @@ -536,16 +536,6 @@ def make_power_figure(
else:
title = "Electricity production from %s" % resource_display_name

resolution_str = "?"
if hasattr(data.index, "freq") and data.index.freq is not None:
resolution_str = time_utils.freq_label_to_human_readable_label(
data.index.freqstr
)
elif "resolution" in session:
resolution_str = time_utils.freq_label_to_human_readable_label(
session["resolution"]
)

return create_graph(
data,
unit="MW",
Expand All @@ -557,7 +547,7 @@ def make_power_figure(
schedules=schedule_data,
title=title,
x_range=shared_x_range,
x_label="Time (resolution of %s)" % resolution_str,
x_label="Time (resolution of %s)" % determine_resolution(data),
y_label="Power (in MW)",
show_y_floats=True,
tools=tools,
Expand All @@ -581,8 +571,7 @@ def make_prices_figure(
forecasts=forecast_data,
title=f"Prices for {selected_market.display_name}",
x_range=shared_x_range,
x_label="Time (resolution of %s)"
% time_utils.freq_label_to_human_readable_label(session["resolution"]),
x_label="Time (resolution of %s)" % determine_resolution(data),
y_label="Price (in %s)" % selected_market.unit,
show_y_floats=True,
tools=tools,
Expand Down Expand Up @@ -622,8 +611,7 @@ def make_weather_figure(
forecasts=forecast_data,
title=title,
x_range=shared_x_range,
x_label="Time (resolution of %s)"
% time_utils.freq_label_to_human_readable_label(session["resolution"]),
x_label="Time (resolution of %s)" % determine_resolution(data),
y_label=weather_axis_label,
legend_location="top_right",
show_y_floats=True,
Expand Down Expand Up @@ -657,8 +645,7 @@ def make_revenues_costs_figure(
forecasts=forecast_data,
title=f"{rev_cost_str} for {resource_display_name} (on {selected_market.display_name})",
x_range=shared_x_range,
x_label="Time (resolution of %s)"
% time_utils.freq_label_to_human_readable_label(session["resolution"]),
x_label="Time (resolution of %s)" % determine_resolution(data),
y_label="%s (in %s)" % (rev_cost_str, selected_market.unit[:3]),
show_y_floats=True,
tools=tools,
Expand All @@ -676,3 +663,21 @@ def revenue_unit_factor(quantity_unit: str, price_unit: str) -> float:
return 1000
else:
raise NotImplementedError


def determine_resolution(data: pd.DataFrame) -> str:
"""
Determine the resolution to be displayed under the plot.
We try to get it from the DataFrame's meta data, or guess from the actual data.
Lastly, we try the session.
If nothing can be found this way, the resulting string is "?"
"""
if hasattr(data.index, "freqstr") and data.index.freqstr is not None:
Flix6x marked this conversation as resolved.
Show resolved Hide resolved
freq_str = data.index.freqstr
elif hasattr(data.index, "inferred_freq") and data.index.inferred_freq is not None:
freq_str = data.index.inferred_freq
elif "resolution" in session:
freq_str = session["resolution"]
else:
return "?"
return time_utils.freq_label_to_human_readable_label(freq_str)
1 change: 1 addition & 0 deletions flexmeasures/ui/views/charts.py
Expand Up @@ -73,6 +73,7 @@ def get_power_chart(chart_request):
"resolution": "PT15M",
"consumption_as_positive": true
"resolution": "PT6H",
"show_individual_traces_for": "none" // can be power or schedules
}

On your webpage, you need to include the Bokeh libraries, e.g.:
Expand Down