Spaces:
Sleeping
Sleeping
[FIX] tab6: filter hidden Other resources, apply CRRA chart style, register chart data, fix tab name
Browse files- tabs/tab6_scenarios.py +9 -4
tabs/tab6_scenarios.py
CHANGED
|
@@ -2,10 +2,10 @@ import json
|
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
import streamlit as st
|
| 5 |
-
from config.config import CO2_UNIT
|
| 6 |
from utils.data_utils import is_valid_scenario
|
| 7 |
from tabs.tab4_optimization import parse_zip_scenario
|
| 8 |
-
from utils.ui_helpers import show_bar
|
| 9 |
|
| 10 |
|
| 11 |
def panel_load_scenario():
|
|
@@ -61,6 +61,7 @@ def prepare_comparison_data(selected):
|
|
| 61 |
all_resources = sorted({
|
| 62 |
r for name in selected
|
| 63 |
for r in st.session_state.scenarios[name].get("resource_caps", {})
|
|
|
|
| 64 |
})
|
| 65 |
|
| 66 |
summary_rows, method_alloc_rows, resource_usage_rows = [], [], []
|
|
@@ -115,9 +116,10 @@ def show_method_allocations(df):
|
|
| 115 |
st.markdown("""<p class="crra-sub-heading">Method Allocations</p>""", unsafe_allow_html=True)
|
| 116 |
fig = px.bar(df, x="Method", y=f"{CO2_UNIT}", color="Scenario", barmode="group")
|
| 117 |
fig.update_layout(xaxis_tickangle=-45)
|
|
|
|
| 118 |
st.plotly_chart(fig, width='stretch')
|
|
|
|
| 119 |
|
| 120 |
-
|
| 121 |
|
| 122 |
|
| 123 |
def show_resource_usage(df):
|
|
@@ -138,13 +140,16 @@ def show_resource_usage(df):
|
|
| 138 |
df_m = df[df["Method"] == method]
|
| 139 |
fig = px.bar(df_m, x="Resource", y="Used", color="Scenario", barmode="group", title=method)
|
| 140 |
fig.update_layout(xaxis_tickangle=-45)
|
|
|
|
| 141 |
st.plotly_chart(fig, width='stretch')
|
| 142 |
|
| 143 |
st.markdown("""<p class="crra-sub-heading">Total Resource Use per Scenario</p>""", unsafe_allow_html=True)
|
| 144 |
df_total = df.groupby(["Scenario", "Resource"]).sum(numeric_only=True).reset_index()
|
| 145 |
fig = px.bar(df_total, x="Scenario", y="Used", color="Resource", barmode="group")
|
| 146 |
fig.update_layout(xaxis_tickangle=-45)
|
|
|
|
| 147 |
st.plotly_chart(fig, width='stretch')
|
|
|
|
| 148 |
|
| 149 |
|
| 150 |
|
|
@@ -162,7 +167,7 @@ def render_tab():
|
|
| 162 |
panel_load_scenario()
|
| 163 |
|
| 164 |
if not st.session_state.scenarios:
|
| 165 |
-
st.info("No scenarios saved yet. Run an optimization in **Portfolio
|
| 166 |
return
|
| 167 |
|
| 168 |
# Select & manage scenarios
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
import streamlit as st
|
| 5 |
+
from config.config import CO2_UNIT, hidden_resource_names
|
| 6 |
from utils.data_utils import is_valid_scenario
|
| 7 |
from tabs.tab4_optimization import parse_zip_scenario
|
| 8 |
+
from utils.ui_helpers import apply_chart_style, register_chart_data, show_bar
|
| 9 |
|
| 10 |
|
| 11 |
def panel_load_scenario():
|
|
|
|
| 61 |
all_resources = sorted({
|
| 62 |
r for name in selected
|
| 63 |
for r in st.session_state.scenarios[name].get("resource_caps", {})
|
| 64 |
+
if r not in hidden_resource_names
|
| 65 |
})
|
| 66 |
|
| 67 |
summary_rows, method_alloc_rows, resource_usage_rows = [], [], []
|
|
|
|
| 116 |
st.markdown("""<p class="crra-sub-heading">Method Allocations</p>""", unsafe_allow_html=True)
|
| 117 |
fig = px.bar(df, x="Method", y=f"{CO2_UNIT}", color="Scenario", barmode="group")
|
| 118 |
fig.update_layout(xaxis_tickangle=-45)
|
| 119 |
+
apply_chart_style(fig)
|
| 120 |
st.plotly_chart(fig, width='stretch')
|
| 121 |
+
register_chart_data("Scenario comparison — method allocations", df)
|
| 122 |
|
|
|
|
| 123 |
|
| 124 |
|
| 125 |
def show_resource_usage(df):
|
|
|
|
| 140 |
df_m = df[df["Method"] == method]
|
| 141 |
fig = px.bar(df_m, x="Resource", y="Used", color="Scenario", barmode="group", title=method)
|
| 142 |
fig.update_layout(xaxis_tickangle=-45)
|
| 143 |
+
apply_chart_style(fig)
|
| 144 |
st.plotly_chart(fig, width='stretch')
|
| 145 |
|
| 146 |
st.markdown("""<p class="crra-sub-heading">Total Resource Use per Scenario</p>""", unsafe_allow_html=True)
|
| 147 |
df_total = df.groupby(["Scenario", "Resource"]).sum(numeric_only=True).reset_index()
|
| 148 |
fig = px.bar(df_total, x="Scenario", y="Used", color="Resource", barmode="group")
|
| 149 |
fig.update_layout(xaxis_tickangle=-45)
|
| 150 |
+
apply_chart_style(fig)
|
| 151 |
st.plotly_chart(fig, width='stretch')
|
| 152 |
+
register_chart_data("Scenario comparison — resource usage", df_total)
|
| 153 |
|
| 154 |
|
| 155 |
|
|
|
|
| 167 |
panel_load_scenario()
|
| 168 |
|
| 169 |
if not st.session_state.scenarios:
|
| 170 |
+
st.info("No scenarios saved yet. Run an optimization in **Portfolio generation** tab or load a file above.", icon=":material/info:")
|
| 171 |
return
|
| 172 |
|
| 173 |
# Select & manage scenarios
|