Skip to content

Commit

Permalink
move cost comparison to dashboard (closes #131)
Browse files Browse the repository at this point in the history
  • Loading branch information
joAschauer committed Nov 23, 2023
1 parent 96bc380 commit 47f5970
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 66 deletions.
52 changes: 0 additions & 52 deletions app/tab_compare_costs.py

This file was deleted.

37 changes: 33 additions & 4 deletions app/tab_dashboard.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# -*- coding: utf-8 -*-
"""Content of dashboard tab."""
import pandas as pd
import streamlit as st
from plotly.subplots import make_subplots

from app.layout_elements import display_costs
from app.plot_functions import (
create_bar_chart_costs,
create_box_plot,
plot_costs_on_map,
)
from app.ptxboa_functions import remove_subregions
from ptxboa.api import PtxboaAPI


def _create_infobox(context_data: dict):
Expand All @@ -30,7 +34,14 @@ def write_info(info):
write_info(info4)


def content_dashboard(api, res_costs: dict, context_data: dict):
def content_dashboard(
api: PtxboaAPI,
costs_per_region: pd.DataFrame,
costs_per_scenario: pd.DataFrame,
costs_per_res_gen: pd.DataFrame,
costs_per_chain: pd.DataFrame,
context_data: dict,
):
with st.expander("What is this?"):
st.markdown(
"""
Expand All @@ -39,6 +50,8 @@ def content_dashboard(api, res_costs: dict, context_data: dict):
regional distribution of total costs across supply regions
- a split-up of costs by category for your chosen supply region
- key information on your chosen demand country.
- total cost and cost components for different supply countries, scenarios,
renewable electricity sources and process chains.
Switch to other tabs to explore data and results in more detail!
"""
Expand All @@ -48,14 +61,16 @@ def content_dashboard(api, res_costs: dict, context_data: dict):

with c_1:
fig_map = plot_costs_on_map(
api, res_costs, scope="world", cost_component="Total"
api, costs_per_region, scope="world", cost_component="Total"
)
st.plotly_chart(fig_map, use_container_width=True)

with c_2:
# create box plot and bar plot:
fig1 = create_box_plot(res_costs)
filtered_data = res_costs[res_costs.index == st.session_state["region"]]
fig1 = create_box_plot(costs_per_region)
filtered_data = costs_per_region[
costs_per_region.index == st.session_state["region"]
]
fig2 = create_bar_chart_costs(filtered_data)
doublefig = make_subplots(rows=1, cols=2, shared_yaxes=True)

Expand All @@ -70,3 +85,17 @@ def content_dashboard(api, res_costs: dict, context_data: dict):
st.plotly_chart(doublefig, use_container_width=True)

_create_infobox(context_data)

display_costs(
remove_subregions(api, costs_per_region, st.session_state["country"]),
"region",
"Costs by region:",
)

display_costs(costs_per_scenario, "scenario", "Costs by data scenario:")

display_costs(
costs_per_res_gen, "res_gen", "Costs by renewable electricity source:"
)

display_costs(costs_per_chain, "chain", "Costs by supply chain:")
15 changes: 5 additions & 10 deletions ptxboa_streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from app.context_data import load_context_data
from app.sidebar import make_sidebar
from app.tab_certification_schemes import content_certification_schemes
from app.tab_compare_costs import content_compare_costs
from app.tab_country_fact_sheets import content_country_fact_sheets
from app.tab_dashboard import content_dashboard
from app.tab_deep_dive_countries import content_deep_dive_countries
Expand Down Expand Up @@ -62,7 +61,6 @@
(
t_dashboard,
t_market_scanning,
t_compare_costs,
t_input_data,
t_deep_dive_countries,
t_country_fact_sheets,
Expand All @@ -74,7 +72,6 @@
[
"Dashboard",
"Market scanning",
"Compare costs",
"Input data",
"Deep-dive countries",
"Country fact sheets",
Expand Down Expand Up @@ -130,20 +127,18 @@

# dashboard:
with t_dashboard:
content_dashboard(api, costs_per_region, cd)

with t_market_scanning:
content_market_scanning(api, costs_per_region)

with t_compare_costs:
content_compare_costs(
content_dashboard(
api,
costs_per_region=costs_per_region,
costs_per_scenario=costs_per_scenario,
costs_per_res_gen=costs_per_res_gen,
costs_per_chain=costs_per_chain,
context_data=cd,
)

with t_market_scanning:
content_market_scanning(api, costs_per_region)

with t_input_data:
content_input_data(api)

Expand Down

0 comments on commit 47f5970

Please sign in to comment.