Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pmall
apli_pmall
Commits
8b55bf87
Commit
8b55bf87
authored
Jul 22, 2021
by
Samuël Weber
Browse files
prevent apostroph catastrophic failure
parent
b8f1d9e4
Changes
3
Hide whitespace changes
Inline
Side-by-side
dashApp/app_components.py
View file @
8b55bf87
...
...
@@ -148,8 +148,8 @@ class SharedComponent():
"""
con
=
sqlite3
.
connect
(
settings
.
BDDPM
)
dfmap
=
pd
.
read_sql
(
"
SELECT * FROM metadata_station WHERE abbrv in (
'
{stations}
'
) OR name IN (
'
{stations}
'
);
"
.
format
(
stations
=
"', '"
.
join
(
stations
)
'
SELECT * FROM metadata_station WHERE abbrv in (
"
{stations}
"
) OR name IN (
"
{stations}
"
);
'
.
format
(
stations
=
'", "'
.
join
(
stations
)
),
con
=
con
)
...
...
@@ -277,8 +277,8 @@ class SharedComponent():
def
get_map_figure
(
self
,
stations
,
selected
=
None
):
con
=
sqlite3
.
connect
(
settings
.
BDDPM
)
dfmap
=
pd
.
read_sql
(
"
SELECT * FROM metadata_station WHERE abbrv in (
'
{stations}
'
) OR name in (
'
{stations}
'
);
"
.
format
(
stations
=
"', '"
.
join
(
stations
)
'
SELECT * FROM metadata_station WHERE abbrv in (
"
{stations}
"
) OR name in (
"
{stations}
"
);
'
.
format
(
stations
=
'", "'
.
join
(
stations
)
),
con
=
con
)
...
...
@@ -623,8 +623,8 @@ class SOURCESComponents():
"""
con
=
sqlite3
.
connect
(
settings
.
BDDSOURCES
)
dfmap
=
pd
.
read_sql
(
"
SELECT * FROM metadata_station WHERE abbrv in (
'
{stations}
'
) OR name in (
'
{stations}
'
);
"
.
format
(
stations
=
"', '"
.
join
(
stations
)
'
SELECT * FROM metadata_station WHERE abbrv in (
"
{stations}
"
) OR name in (
"
{stations}
"
);
'
.
format
(
stations
=
'", "'
.
join
(
stations
)
),
con
=
con
)
...
...
dashApp/callbacks.py
View file @
8b55bf87
...
...
@@ -146,9 +146,9 @@ def register_callbacks(app):
"""Get all possible source given the stations
"""
sources
=
[]
sql
=
"
SELECT * FROM PMF_contributions WHERE station IN (
'
{stations}
')"
sql
=
'
SELECT * FROM PMF_contributions WHERE station IN (
"
{stations}
")'
stations_mapped
=
[
STATIONS_LONG2SHORT
.
get
(
s
,
s
)
for
s
in
stations
]
sql
=
sql
.
format
(
stations
=
"', '"
.
join
(
stations_mapped
))
sql
=
sql
.
format
(
stations
=
'", "'
.
join
(
stations_mapped
))
dftmp
=
pd
.
read_sql
(
sql
,
con
=
sqlite3
.
connect
(
settings
.
BDDPM
))
\
.
dropna
(
axis
=
1
,
how
=
"all"
)
sources
=
list
(
set
(
dftmp
.
columns
)
-
set
(
BASE_VAR_SRC
)
-
set
([
"index"
])
)
...
...
dashApp/utilities.py
View file @
8b55bf87
...
...
@@ -34,18 +34,22 @@ def get_contribution(sources, species, stations):
if
len
(
sources
)
>
0
:
conn
=
sqlite3
.
connect
(
settings
.
BDDSOURCES
)
contrib
=
pd
.
read_sql
(
"SELECT * FROM contributions_constrained
\
WHERE station in ('{stations}');"
.
format
(
stations
=
"', '"
.
join
(
stations
)
"""
SELECT * FROM contributions_constrained
\
WHERE station in ("{stations}");
"""
.
format
(
stations
=
'", "'
.
join
(
stations
)
),
con
=
conn
,
parse_dates
=
[
"Date"
],
index_col
=
[
"Station"
,
"Date"
]
).
drop
(
"index"
,
axis
=
1
)
profile
=
pd
.
read_sql
(
"SELECT * FROM profiles_constrained
\
WHERE station in ('{stations}');"
.
format
(
stations
=
"', '"
.
join
(
stations
)
"""
SELECT * FROM profiles_constrained
WHERE station in ("{stations}");
"""
.
format
(
stations
=
'", "'
.
join
(
stations
)
),
con
=
conn
,
index_col
=
[
"Station"
,
"Specie"
],
...
...
@@ -279,14 +283,18 @@ def get_values(table, cols, where=None, isin=None, base_var=None, DBpath=None):
var_values
+=
base_var
if
where
and
isin
:
sqlquery
=
"SELECT
\"
{cols}
\"
FROM {table} WHERE {where} IN ('{isin}')"
.
format
(
sqlquery
=
"""
SELECT
\"
{cols}
\"
FROM {table} WHERE {where} IN ("{isin}")
"""
.
format
(
cols
=
'
\"
,
\"
'
.
join
(
var_values
),
table
=
table
,
where
=
where
,
isin
=
"', '"
.
join
(
isin
)
isin
=
'", "'
.
join
(
isin
)
)
else
:
sqlquery
=
"SELECT
\"
{cols}
\"
FROM {table}"
.
format
(
sqlquery
=
"""
SELECT
\"
{cols}
\"
FROM {table}
"""
.
format
(
cols
=
'
\"
,
\"
'
.
join
(
var_values
),
table
=
table
,
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment