Added refresh button
Browse files- app.py +26 -42
- components.py +54 -1
app.py
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
-
from components import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
import utils
|
5 |
|
6 |
st.set_page_config(page_title="Electricity Demand Dashboard", layout="wide")
|
@@ -16,59 +25,34 @@ PAGES = [
|
|
16 |
@st.cache_data(ttl=86400)
|
17 |
def fetch_data():
|
18 |
return utils.get_wandb_data(
|
19 |
-
st.secrets["wandb_entity"],
|
20 |
-
"enfobench-electricity-demand",
|
21 |
-
st.secrets["wandb_api_key"],
|
22 |
job_type="metrics",
|
23 |
)
|
24 |
|
25 |
|
|
|
26 |
data = fetch_data()
|
27 |
-
models = sorted(data["model"].unique().tolist())
|
28 |
-
models_to_plot = set()
|
29 |
-
model_groups: dict[str, list[str]] = {}
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
if group not in model_groups:
|
34 |
-
model_groups[group] = []
|
35 |
-
model_groups[group].append(model_name)
|
36 |
|
37 |
|
38 |
with st.sidebar:
|
39 |
-
|
40 |
-
2
|
41 |
-
) # Create two columns within the right column for side-by-side images
|
42 |
-
with left:
|
43 |
-
st.image("./images/ku_leuven_logo.png")
|
44 |
-
with right:
|
45 |
-
st.image("./images/energyville_logo.png")
|
46 |
-
|
47 |
view = st.selectbox("View", PAGES, index=0)
|
48 |
-
|
49 |
-
st.
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
with right:
|
57 |
-
select_all = st.button("Select All", use_container_width=True)
|
58 |
-
if select_all:
|
59 |
-
for model in models:
|
60 |
-
st.session_state[model] = True
|
61 |
-
|
62 |
-
for model_group, models in model_groups.items():
|
63 |
-
st.text(model_group)
|
64 |
-
for model_name in models:
|
65 |
-
to_plot = st.checkbox(model_name, value=True, key=f"{model_group}.{model_name}")
|
66 |
-
if to_plot:
|
67 |
-
models_to_plot.add(f"{model_group}.{model_name}")
|
68 |
|
69 |
|
70 |
-
|
71 |
-
st.divider()
|
72 |
|
73 |
if view == "Buildings":
|
74 |
buildings_view(data)
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
from components import (
|
4 |
+
buildings_view,
|
5 |
+
models_view,
|
6 |
+
performance_view,
|
7 |
+
computation_view,
|
8 |
+
logos,
|
9 |
+
model_selector,
|
10 |
+
header,
|
11 |
+
overview_view,
|
12 |
+
)
|
13 |
import utils
|
14 |
|
15 |
st.set_page_config(page_title="Electricity Demand Dashboard", layout="wide")
|
|
|
25 |
@st.cache_data(ttl=86400)
|
26 |
def fetch_data():
|
27 |
return utils.get_wandb_data(
|
28 |
+
entity=st.secrets["wandb_entity"],
|
29 |
+
project="enfobench-electricity-demand",
|
30 |
+
api_key=st.secrets["wandb_api_key"],
|
31 |
job_type="metrics",
|
32 |
)
|
33 |
|
34 |
|
35 |
+
# Load data
|
36 |
data = fetch_data()
|
|
|
|
|
|
|
37 |
|
38 |
+
# Extract models
|
39 |
+
models = sorted(data["model"].unique().tolist())
|
|
|
|
|
|
|
40 |
|
41 |
|
42 |
with st.sidebar:
|
43 |
+
logos()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
view = st.selectbox("View", PAGES, index=0)
|
45 |
+
models_to_plot = model_selector(models)
|
46 |
+
st.subheader("Refresh data")
|
47 |
+
refresh = st.button(
|
48 |
+
"Refresh", use_container_width=True, help="Fetch the latest data from W&B"
|
49 |
+
)
|
50 |
+
if refresh:
|
51 |
+
fetch_data.clear()
|
52 |
+
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
|
55 |
+
header()
|
|
|
56 |
|
57 |
if view == "Buildings":
|
58 |
buildings_view(data)
|
components.py
CHANGED
@@ -2,6 +2,59 @@ import pandas as pd
|
|
2 |
import streamlit as st
|
3 |
import plotly.express as px
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def buildings_view(data):
|
7 |
buildings = (
|
@@ -41,7 +94,7 @@ def buildings_view(data):
|
|
41 |
help="Available training data during the first prediction.",
|
42 |
format="%f",
|
43 |
min_value=0,
|
44 |
-
max_value=float(buildings[
|
45 |
),
|
46 |
},
|
47 |
)
|
|
|
2 |
import streamlit as st
|
3 |
import plotly.express as px
|
4 |
|
5 |
+
def header() -> None:
|
6 |
+
st.title("EnFoBench - Electricity Demand")
|
7 |
+
st.divider()
|
8 |
+
|
9 |
+
|
10 |
+
def logos() -> None:
|
11 |
+
left, right = st.columns(2)
|
12 |
+
with left:
|
13 |
+
st.image("./images/ku_leuven_logo.png")
|
14 |
+
with right:
|
15 |
+
st.image("./images/energyville_logo.png")
|
16 |
+
|
17 |
+
|
18 |
+
def model_selector(models: list[str]) -> set[str]:
|
19 |
+
# Group models by their prefix
|
20 |
+
model_groups: dict[str, list[str]] = {}
|
21 |
+
for model in models:
|
22 |
+
group, model_name = model.split(".", maxsplit=1)
|
23 |
+
if group not in model_groups:
|
24 |
+
model_groups[group] = []
|
25 |
+
model_groups[group].append(model_name)
|
26 |
+
|
27 |
+
models_to_plot = set()
|
28 |
+
|
29 |
+
st.header("Models to include")
|
30 |
+
left, right = st.columns(2)
|
31 |
+
with left:
|
32 |
+
select_none = st.button("Select None", use_container_width=True)
|
33 |
+
if select_none:
|
34 |
+
for model in models:
|
35 |
+
st.session_state[model] = False
|
36 |
+
with right:
|
37 |
+
select_all = st.button("Select All", use_container_width=True)
|
38 |
+
if select_all:
|
39 |
+
for model in models:
|
40 |
+
st.session_state[model] = True
|
41 |
+
|
42 |
+
for model_group, models in model_groups.items():
|
43 |
+
st.text(model_group)
|
44 |
+
for model_name in models:
|
45 |
+
to_plot = st.checkbox(
|
46 |
+
model_name, value=True, key=f"{model_group}.{model_name}"
|
47 |
+
)
|
48 |
+
if to_plot:
|
49 |
+
models_to_plot.add(f"{model_group}.{model_name}")
|
50 |
+
return models_to_plot
|
51 |
+
|
52 |
+
|
53 |
+
def overview_view(data):
|
54 |
+
st.markdown("""
|
55 |
+
EnFoBench is a benchmarking framework for energy forecasting models. This dashboard provides an overview of the.
|
56 |
+
""")
|
57 |
+
|
58 |
|
59 |
def buildings_view(data):
|
60 |
buildings = (
|
|
|
94 |
help="Available training data during the first prediction.",
|
95 |
format="%f",
|
96 |
min_value=0,
|
97 |
+
max_value=float(buildings["Available history (days)"].max()),
|
98 |
),
|
99 |
},
|
100 |
)
|