Skip to content

Commit

Permalink
Added option to filter each sector by use and fixed several backend bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
camiloramirezgo committed Sep 24, 2019
1 parent ec0f7cf commit 14f9614
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions dashboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ def get_general_graph(df, year_slider, variable, layout, title, units = None):
{'label': 'MMboe', 'value': 'MMboe'},
],
value='Mtoe',
clearable=False,
),
html.P(
[
Expand All @@ -435,6 +436,7 @@ def get_general_graph(df, year_slider, variable, layout, title, units = None):
{'label': 'TWh', 'value': 'TWh'},
],
value='TWh',
clearable=False,
),
],
className="container",
Expand Down Expand Up @@ -529,7 +531,8 @@ def get_general_graph(df, year_slider, variable, layout, title, units = None):
dcc.Dropdown(
id='tfec_scenario',
options=[{'label': i, 'value': i} for i in scenarios],
value='BAU'
value='BAU',
clearable = False,
),
html.P(
'Select the range of years to visualize:',
Expand Down Expand Up @@ -603,7 +606,8 @@ def get_general_graph(df, year_slider, variable, layout, title, units = None):
{'label': 'Annual investment required', 'value': 'el_inv'},
{'label': 'Annual discounted cost', 'value': 'el_cost'},
],
value='el_demand'
value='el_demand',
clearable = False,
),

html.P(
Expand Down Expand Up @@ -883,16 +887,13 @@ def update_elec_value(value):
def update_elec_type(visualization, scenario):
if scenario == 'All':
options = [
{'label': 'Source', 'value': 'Source'},
{'label': 'Sector', 'value': 'Sector'},
{'label': 'Type', 'value': 'Use'},
{'label': 'Select...', 'value': 'Select', 'disabled': True},
]
else:
if visualization == 'el_prod':
options = [
{'label': 'Source', 'value': 'Source'},
{'label': 'Type', 'value': 'Use'},
{'label': 'Type', 'value': 'Type'},
{'label': 'Select...', 'value': 'Select', 'disabled': True},
]
elif visualization == 'el_demand':
Expand All @@ -904,7 +905,7 @@ def update_elec_type(visualization, scenario):
elif visualization == 'el_co2':
options = [
{'label': 'Source', 'value': 'Source'},
{'label': 'Type', 'value': 'Use'},
{'label': 'Type', 'value': 'Type'},
{'label': 'Select...', 'value': 'Select', 'disabled': True},
]
elif (visualization == 'el_inv') or (visualization == 'el_cost'):
Expand Down Expand Up @@ -952,6 +953,8 @@ def set_state(value, scenario, year_slider):
dff = df_elec_demand.loc[
(df_elec_demand['Scenario'] == scenario) & (
(df_elec_demand['y'] >= year_slider[0]) & (df_elec_demand['y'] <= year_slider[1]))]
# options = [{'label': 'Select...', 'value': 'Select'}]
options = ''
if value == 'Use':
options = [{'label': 'All', 'value': 'All'}] + [{'label': i, 'value': i} for i in dff['Sector'].unique()]
return options
Expand Down Expand Up @@ -1026,12 +1029,12 @@ def update_tfec(scenario, year_slider, filter, units):
)
def update_supply(scenario, year_slider, visualization, type, units, sector):
layout_supply = copy.deepcopy(layout)

data = ''
if visualization == 'el_demand':
if scenario == 'All':
data, layout_supply = get_general_graph(df_elec_demand, year_slider, elec_demand_variable, layout,
"Electricity demand ({})".format(units), units)
else:
elif scenario != 'Select':
dff = df_elec_demand.loc[
(df_elec_demand['Scenario'] == scenario) & ((df_elec_demand['y'] >= year_slider[0]) & (df_elec_demand['y'] <= year_slider[1]))]
dff.loc[:, elec_demand_variable] *= units_dict[units]
Expand All @@ -1050,7 +1053,7 @@ def update_supply(scenario, year_slider, visualization, type, units, sector):

layout_supply["title"] = "Electricity demand in the {} sector ({})".format(sector, units)
layout_supply["barmode"] = 'stack'
else:
elif (sector != 'Select') & (type != 'Select'):
data = [
dict(
type="bar",
Expand All @@ -1070,7 +1073,7 @@ def update_supply(scenario, year_slider, visualization, type, units, sector):
if scenario == 'All':
data, layout_supply = get_general_graph(df_supply, year_slider, supply_variable, layout,
"Electricity production ({})".format(units), units)
else:
elif (sector != 'Select') & (type != 'Select'):
dff = df_supply.loc[
(df_supply['Scenario'] == scenario) & ((df_supply['y'] >= year_slider[0]) & (df_supply['y'] <= year_slider[1]))]
dff.loc[:, supply_variable] *= units_dict[units]
Expand All @@ -1094,7 +1097,7 @@ def update_supply(scenario, year_slider, visualization, type, units, sector):
data, layout_supply = get_general_graph(df_emissions, year_slider, emissions_variable, layout,
"Total CO2 Emissions (Mton)")

else:
elif (sector != 'Select') & (type != 'Select'):
dff = df_emissions.loc[
(df_emissions['Scenario'] == scenario) & (
(df_emissions['y'] >= year_slider[0]) & (df_emissions['y'] <= year_slider[1]))]
Expand Down

0 comments on commit 14f9614

Please sign in to comment.