Commit 9b33bb9f authored by Samuël Weber's avatar Samuël Weber
Browse files

cleaning

parent a1abc295
......@@ -12,7 +12,6 @@ import pandas as pd
from app_main import app
import apps.app_components as ac
import settings
import pyOPestimator
NCLICKED = 0
......
......@@ -18,25 +18,24 @@ from dateutil.relativedelta import relativedelta
from app_main import app
import apps.app_components as ac
import settings
# BDD connexion ===============================================================
# RELATIVE TO index !!!
DBPATH = os.path.abspath("./data/deconvolOP.db")
conn = sqlite3.connect(DBPATH)
OPi = pd.read_sql(
"SELECT * FROM OPi;", con=conn, index_col=["Station", "Factor"]
)
conn.close()
# =============================================================================
STATIONS = OPi.index.get_level_values("Station").unique()
STATION_ORDER = [
"MRS-5av", "PdB", "AIX", "NIC", "TAL", "NGT", "GRE-fr_2013", "GRE-fr_2017",
"GRE-cb", "VIF", "CHAM", "MNZ", "PAS", "RBX", "STG-cle"
]
STATIONS = STATION_ORDER.copy()
BASE_VAR_SP = ["Date", "Station"]
BASE_VAR_SRC = ["Date", "Station"]
carboneous = ["OC*", "EC"]
ions = ["Cl-", "NO3-", "SO42-", "Na+", "NH4+", "K+", "Mg2+", "Ca2+"]
organics = [
......@@ -50,10 +49,6 @@ ops = ["DTTv", "AAv", "DCFHv", "SD_DTTv", "SD_AAv", "SD_DCFHv"]
SPECIES_ORDER_WO_OP = ["PM10"] + carboneous + ions + organics + metals
SPECIES_ORDER = ["PM10"] + carboneous + ions + organics + metals + ops
# BUTTONS = [
# "rd_ts", "rd_monthly", "rd_seasonal", "pmf_profiles", "pmf_deltatool",
# "pmf_unc", "pmf_sr", "op_beta", "op_obsvsmodel", "op_contrib", "op_contrib_ts", "help",
# ]
COMPONENTS = collections.OrderedDict({})
COMPONENTS["rd_ts"] = ac.get_rawdata_timeserie_component()
......@@ -198,7 +193,7 @@ layout = dbc.Container(
# this callback uses the current pathname to set the active state of the
# corresponding nav link to true, allowing users to tell see page they are on
# corresponding nav link to true, allowing users to see page they are on
@app.callback(
[Output(f"item-{i}", "active") for i in PAGES],
[Input("master-url", "search")],
......@@ -222,7 +217,7 @@ def toggle_items_collapse(n, is_open):
@app.callback(Output('source-dropdown', 'options'),
[Input('station-dropdown', 'value')])
def set_source_option(stations_dd):
"""Set the possible source dropdown"""
"""Set the possible source dropdown based on the selection station"""
conn = sqlite3.connect(DBPATH)
query = "SELECT * FROM SRC WHERE station IN ('{stations}')".format(
stations="', '".join(stations_dd)
......@@ -251,10 +246,11 @@ def set_source_option(stations_dd):
State('source-dropdown', 'options')
]
)
def select_all_source(select_time, clear_time, current_values):
def select_all_or_clear_source(select_time, clear_time, current_values):
"""Buttons to select all or clear the sources dropdown"""
if all([x is None for x in [select_time, clear_time]]):
return [option["value"] for option in current_values]
# select all
if clear_time is None or (select_time is not None and (select_time > clear_time)):
values = [option["value"] for option in current_values]
......@@ -273,11 +269,15 @@ def select_all_source(select_time, clear_time, current_values):
State('station-dropdown', 'value')
]
)
def select_all_station(select_time, clear_time, current_values):
def select_all_or_clear_station(select_time, clear_time, current_values):
"""Buttons to select all or clear the station dropdown"""
if all([x is None for x in [select_time, clear_time]]):
return current_values
# select all
if clear_time is None or (select_time is not None and (select_time > clear_time)):
values = [i for i in settings.STATION_ORDER]
values = [i for i in STATION_ORDER]
# clear all
elif select_time is None or (clear_time is not None and (clear_time > select_time)):
values = []
return values
......@@ -285,25 +285,21 @@ def select_all_station(select_time, clear_time, current_values):
@app.callback(Output('specie-dropdown', 'options'),
[Input('station-dropdown', 'value')])
def set_specie_option(stations):
"""Set the possible specie dropdown"""
"""Set the possible specie dropdown based on the selection station"""
options = [{}]
# if (stations is None) or (selectedTab is None):
# raise PreventUpdate
if len(stations) == 0 or stations is None:
raise PreventUpdate
conn = sqlite3.connect(DBPATH)
# query = "SELECT * FROM OPi WHERE station IN ('{stations}')".format(
# stations="', '".join(stations)
# )
# species = list(pd.read_sql(query, con=conn).columns.unique())
query = "SELECT specie FROM profiles_constrained WHERE Station IN ('{stations}')".format(
stations="', '".join(stations)
)
species = list(pd.read_sql(query, con=conn)["Specie"].unique())
conn.close()
# species = profile.loc[profile["station"].isin(stations), "specie"].unique()
species = set(species) - set(BASE_VAR_SP)
species = list(species)
# specie to plot
species_order = SPECIES_ORDER.copy()
for sp in SPECIES_ORDER:
......@@ -667,7 +663,7 @@ def get_grouped_box_options(plots_options, temporality, groupby_var, stations):
hue_var_list = stations
elif x_var == "site":
x_var_col = "Station"
x_var_list = [s for s in settings.STATION_ORDER if s in stations]
x_var_list = [s for s in STATION_ORDER if s in stations]
hue_var_col = "season" if temporality == "seasonal" else "month"
hue_var_list = date_var_list
xticklabels = x_var_list
......@@ -1182,7 +1178,7 @@ def update_uncertainty_graph_conc(sources, species, stations):
yaxis={"title": "µg.m⁻³"},
xaxis={
'categoryorder': 'array',
'categoryarray': settings.STATION_ORDER
'categoryarray': STATION_ORDER
},
boxmode='group',
legend=dict(orientation="h", y=1.17),
......@@ -1310,7 +1306,7 @@ def update_uncertainty_graph_norm(sources, species, stations):
},
xaxis={
'categoryorder': 'array',
'categoryarray': settings.STATION_ORDER
'categoryarray': STATION_ORDER
},
boxmode='group',
legend=dict(orientation="h", y=1.17),
......@@ -1870,7 +1866,7 @@ def update_op_contribution_ts_graph(stations, species, plot_type, estimator):
color_discrete_map=colors,
facet_row="Station",
opacity=1,
category_orders={"Station": settings.STATION_ORDER},
category_orders={"Station": STATION_ORDER},
height=150+200*len(stations),
)
......@@ -1910,7 +1906,7 @@ def update_op_contribution_ts_graph(stations, species, plot_type, estimator):
color_discrete_map=colors,
facet_row="Station",
opacity=1,
category_orders={"Station": settings.STATION_ORDER},
category_orders={"Station": STATION_ORDER},
hover_data=['Station', 'Factor', 'hoverdata'],
labels={"hoverdata": hoverlabel},
height=150+200*len(stations),
......@@ -1918,9 +1914,8 @@ def update_op_contribution_ts_graph(stations, species, plot_type, estimator):
# Add measured OP and uncertainties
i = 0
for station in settings.STATION_ORDER:
if station not in settings.STATION_ORDER\
or station not in stations:
for station in STATION_ORDER:
if station not in STATION_ORDER or station not in stations:
continue
if plot_type == "daily":
data = OP.loc[station, ["SD_"+species[0], species[0]]]
......
......@@ -28,7 +28,7 @@
/* } */
.help-component {
max-width: 800px;
max-width: 1000px;
}
.text {
......
STATION_ORDER = [
"MRS-5av", "PdB", "AIX", "NIC", "TAL", "NGT", "GRE-fr_2013", "GRE-fr_2017",
"GRE-cb", "VIF", "CHAM", "MNZ", "PAS", "RBX", "STG-cle"
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment