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

Fix multi sourced belief charts #228

Merged
merged 4 commits into from Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 14 additions & 2 deletions flexmeasures/data/models/charts/belief_charts.py
@@ -1,4 +1,8 @@
from flexmeasures.data.models.charts.defaults import TIME_TITLE, TIME_TOOLTIP_TITLE
from flexmeasures.data.models.charts.defaults import (
SOURCE_TITLE,
TIME_TITLE,
TIME_TOOLTIP_TITLE,
)


def bar_chart(title: str, quantity: str = "unknown quantity", unit: str = "a.u."):
Expand All @@ -14,14 +18,22 @@ def bar_chart(title: str, quantity: str = "unknown quantity", unit: str = "a.u."
"field": "event_value",
"type": "quantitative",
"title": quantity + " (" + unit + ")",
"stack": None,
},
"color": {
"field": "source",
"type": "ordinal",
"title": SOURCE_TITLE,
},
"opacity": {"value": 0.7},
"tooltip": [
{"field": "full_date", "title": TIME_TOOLTIP_TITLE, "type": "nominal"},
{
"field": "event_value",
"title": quantity + " (" + unit + ")",
"type": "quantitative",
},
{"field": "full_date", "title": TIME_TOOLTIP_TITLE, "type": "nominal"},
{"field": "source", "title": SOURCE_TITLE, "type": "ordinal"},
],
},
}
1 change: 1 addition & 0 deletions flexmeasures/data/models/charts/defaults.py
Expand Up @@ -8,6 +8,7 @@
WIDTH = 600
REDUCED_HEIGHT = REDUCED_WIDTH = 60
SELECTOR_COLOR = "darkred"
SOURCE_TITLE = "Source"
Flix6x marked this conversation as resolved.
Show resolved Hide resolved
TIME_FORMAT = "%I:%M %p on %A %b %e, %Y"
TIME_TOOLTIP_TITLE = "Time and date"
TIME_TITLE = None
Expand Down
2 changes: 1 addition & 1 deletion flexmeasures/data/models/time_series.py
Expand Up @@ -97,7 +97,7 @@ def search_beliefs(
)
if as_json:
df = bdf.reset_index()
df["source"] = df["source"].apply(lambda x: x.name)
df["source"] = df["source"].astype(str)
return df.to_json(orient="records")
return bdf

Expand Down