Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 0dc11a0d authored by Samuel's avatar Samuel
Browse files

speed optimization

parent 0d5d4efd
......@@ -24,7 +24,7 @@ sc = SharedComponent()
# =============================================================================
conn = sqlite3.connect(settings.BDDPM) # BDDPM must be defined in local_settings.py
df = pd.read_sql('SELECT * FROM `values_all`;', conn)
df = pd.read_sql('SELECT Date FROM `values_all`;', conn, parse_dates=["Date"])
dfmap = pd.read_sql('SELECT * FROM metadata_station;', conn)
conn.close()
# ========================================s=====================================
......@@ -37,8 +37,8 @@ map_station = {
"TAL": "Talence", "ROU": "Rouen", "NGT": "Nogent"
}
df["Labels"].replace({"nan": np.nan, "None": np.nan}, inplace=True)
df["Date"] = pd.to_datetime(df["Date"])
# df["Labels"].replace({"nan": np.nan, "None": np.nan}, inplace=True)
# df["Date"] = pd.to_datetime(df["Date"])
# replace_QL(df)
# ==== STATION LIST ===========================================================
......@@ -93,7 +93,7 @@ app.layout = dbc.Container(
id="station-dropdown",
options=[{"label": l, "value": l} for l in
list_station],
default=["GRE-fr"]
default=[]
),
sc.dropdown_component(
label="Specie",
......@@ -194,12 +194,22 @@ def set_station_option(nbsample, options):
nbsample = 0
else:
nbsample = int(nbsample)
sql_query = """
SELECT Station, Particle_size, COUNT(*) AS nsamples
FROM values_all
GROUP BY Station, Particle_size;
"""
conn = sqlite3.connect(settings.BDDPM)
df = pd.read_sql(sql_query, con=conn)
conn.close()
df = df.loc[df["nsamples"] > nbsample]
df = df.loc[df["Particle_size"].isin(PMfraction)]
station_dropdown = [
{'label': s, 'value': s}
for s in stations_tmp
if df[df["Station"] == s].shape[0] > nbsample
and df.loc[df["Station"] == s, "Particle_size"].isin(PMfraction).sum() > 0
for s in stations_tmp if df["Station"].isin([s]).any()
]
return station_dropdown
......@@ -207,12 +217,28 @@ def set_station_option(nbsample, options):
@app.callback(Output('specie-dropdown', 'options'),
[Input('station-dropdown', 'value')])
def set_specie_option(stations):
species=[]
species = []
if len(stations) == 0:
return [{'label': '', 'value': ''}]
conn = sqlite3.connect(settings.BDDPM)
sql_query = """
SELECT * FROM values_all WHERE Station IN ("{stations}")
""".format(
stations='", "'.join(stations)
)
df = pd.read_sql(sql_query, con=conn).dropna(axis=1, how="all")
conn.close()
for station in stations:
species = species + [i for i in
df[df["Station"]==station].dropna(axis=1,
how="all").columns
if i not in species]
species = species + [
i for i in df[df["Station"]==station]\
.dropna(axis=1, how="all")\
.columns
if i not in species
]
species = set(species) - set(BASE_VAR_SP)
species = list(species)
species.sort()
......
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