Spaces:
Sleeping
Sleeping
Added refresh button
Browse files- app.py +25 -41
- components.py +50 -2
app.py
CHANGED
|
@@ -1,10 +1,16 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
from components import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import utils
|
| 5 |
|
| 6 |
-
st.set_page_config(page_title="Pv Generation Dashboard", layout="wide")
|
| 7 |
-
|
| 8 |
PAGES = [
|
| 9 |
"Buildings",
|
| 10 |
"Models",
|
|
@@ -13,6 +19,9 @@ PAGES = [
|
|
| 13 |
]
|
| 14 |
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
@st.cache_data(ttl=86400)
|
| 17 |
def fetch_data():
|
| 18 |
return utils.get_wandb_data(
|
|
@@ -23,52 +32,27 @@ def fetch_data():
|
|
| 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 |
+
)
|
| 12 |
import utils
|
| 13 |
|
|
|
|
|
|
|
| 14 |
PAGES = [
|
| 15 |
"Buildings",
|
| 16 |
"Models",
|
|
|
|
| 19 |
]
|
| 20 |
|
| 21 |
|
| 22 |
+
st.set_page_config(page_title="Pv Generation Dashboard", layout="wide")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
@st.cache_data(ttl=86400)
|
| 26 |
def fetch_data():
|
| 27 |
return utils.get_wandb_data(
|
|
|
|
| 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
|
@@ -3,6 +3,54 @@ import streamlit as st
|
|
| 3 |
import plotly.express as px
|
| 4 |
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
def buildings_view(data):
|
| 7 |
buildings = (
|
| 8 |
data[
|
|
@@ -39,14 +87,14 @@ def buildings_view(data):
|
|
| 39 |
help="Available training data during the first prediction.",
|
| 40 |
format="%f",
|
| 41 |
min_value=0,
|
| 42 |
-
max_value=float(buildings[
|
| 43 |
),
|
| 44 |
"Capacity (kW)": st.column_config.ProgressColumn(
|
| 45 |
"Capacity (kW)",
|
| 46 |
help="Available training data during the first prediction.",
|
| 47 |
format="%f",
|
| 48 |
min_value=0,
|
| 49 |
-
max_value=float(buildings[
|
| 50 |
),
|
| 51 |
},
|
| 52 |
)
|
|
|
|
| 3 |
import plotly.express as px
|
| 4 |
|
| 5 |
|
| 6 |
+
def header() -> None:
|
| 7 |
+
st.title("EnFoBench - PV Generation")
|
| 8 |
+
st.divider()
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def logos() -> None:
|
| 12 |
+
left, right = st.columns(2)
|
| 13 |
+
with left:
|
| 14 |
+
st.image("./images/ku_leuven_logo.png")
|
| 15 |
+
with right:
|
| 16 |
+
st.image("./images/energyville_logo.png")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def model_selector(models: list[str]) -> set[str]:
|
| 20 |
+
# Group models by their prefix
|
| 21 |
+
model_groups: dict[str, list[str]] = {}
|
| 22 |
+
for model in models:
|
| 23 |
+
group, model_name = model.split(".", maxsplit=1)
|
| 24 |
+
if group not in model_groups:
|
| 25 |
+
model_groups[group] = []
|
| 26 |
+
model_groups[group].append(model_name)
|
| 27 |
+
|
| 28 |
+
models_to_plot = set()
|
| 29 |
+
|
| 30 |
+
st.header("Models to include")
|
| 31 |
+
left, right = st.columns(2)
|
| 32 |
+
with left:
|
| 33 |
+
select_none = st.button("Select None", use_container_width=True)
|
| 34 |
+
if select_none:
|
| 35 |
+
for model in models:
|
| 36 |
+
st.session_state[model] = False
|
| 37 |
+
with right:
|
| 38 |
+
select_all = st.button("Select All", use_container_width=True)
|
| 39 |
+
if select_all:
|
| 40 |
+
for model in models:
|
| 41 |
+
st.session_state[model] = True
|
| 42 |
+
|
| 43 |
+
for model_group, models in model_groups.items():
|
| 44 |
+
st.text(model_group)
|
| 45 |
+
for model_name in models:
|
| 46 |
+
to_plot = st.checkbox(
|
| 47 |
+
model_name, value=True, key=f"{model_group}.{model_name}"
|
| 48 |
+
)
|
| 49 |
+
if to_plot:
|
| 50 |
+
models_to_plot.add(f"{model_group}.{model_name}")
|
| 51 |
+
return models_to_plot
|
| 52 |
+
|
| 53 |
+
|
| 54 |
def buildings_view(data):
|
| 55 |
buildings = (
|
| 56 |
data[
|
|
|
|
| 87 |
help="Available training data during the first prediction.",
|
| 88 |
format="%f",
|
| 89 |
min_value=0,
|
| 90 |
+
max_value=float(buildings["Available history (days)"].max()),
|
| 91 |
),
|
| 92 |
"Capacity (kW)": st.column_config.ProgressColumn(
|
| 93 |
"Capacity (kW)",
|
| 94 |
help="Available training data during the first prediction.",
|
| 95 |
format="%f",
|
| 96 |
min_value=0,
|
| 97 |
+
max_value=float(buildings["Capacity (kW)"].max()),
|
| 98 |
),
|
| 99 |
},
|
| 100 |
)
|