From bec987265a849f9bc6ba5d84ff9a606fdcba9da3 Mon Sep 17 00:00:00 2001 From: "zoiszogop@gmail.com" Date: Thu, 10 Oct 2024 16:35:29 +0200 Subject: [PATCH 1/3] station - update station fetch query and get() --- icoscp/src/icoscp/sparql/sparqls.py | 6 ++++-- icoscp/src/icoscp/station/station.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/icoscp/src/icoscp/sparql/sparqls.py b/icoscp/src/icoscp/sparql/sparqls.py index 414c433..50c47ba 100644 --- a/icoscp/src/icoscp/sparql/sparqls.py +++ b/icoscp/src/icoscp/sparql/sparqls.py @@ -460,8 +460,10 @@ def station_query(filter: dict = None, return_filter: bool = False) -> str or (s {theme_filter} ?uri a ?stationTheme . OPTIONAL{{ - ?memb cpmeta:atOrganization ?uri ; cpmeta:hasRole . - filter not exists {{?memb cpmeta:hasEndTime []}} + ?memb cpmeta:atOrganization ?uri . + optional {{?memb cpmeta:hasEndTime ?membEnd}} + filter(!bound(?membEnd) || ?membEnd > now()) + ?memb cpmeta:hasRole . ?pers cpmeta:hasMembership ?memb }} }} diff --git a/icoscp/src/icoscp/station/station.py b/icoscp/src/icoscp/station/station.py index e2ccc0a..89ffed7 100644 --- a/icoscp/src/icoscp/station/station.py +++ b/icoscp/src/icoscp/station/station.py @@ -568,7 +568,7 @@ def get(stationId: str = None, except: stn = None - if not (isinstance(stn, pd.DataFrame) and not stn.empty): + if not isinstance(stn, pd.DataFrame) or stn.empty: my_stn.stationId = stationId my_stn.valid = False return my_stn @@ -715,6 +715,7 @@ def _get_id_list(filter: dict = {'project': 'ICOS', 'theme': ['AS', 'ES', 'OS']} query = sparqls.station_query(filter=filter) stn_df = RunSparql(query, 'pandas').run() + stn_df.drop_duplicates(inplace=True) if not isinstance(stn_df, pd.DataFrame): return stn_df From 316df99adae0a16d280d84e91843f1f63edbad59 Mon Sep 17 00:00:00 2001 From: Oleg Mirzov Date: Fri, 11 Oct 2024 10:57:42 +0200 Subject: [PATCH 2/3] station - make the station list query change minimal --- icoscp/src/icoscp/sparql/sparqls.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/icoscp/src/icoscp/sparql/sparqls.py b/icoscp/src/icoscp/sparql/sparqls.py index 50c47ba..8747fd1 100644 --- a/icoscp/src/icoscp/sparql/sparqls.py +++ b/icoscp/src/icoscp/sparql/sparqls.py @@ -460,10 +460,9 @@ def station_query(filter: dict = None, return_filter: bool = False) -> str or (s {theme_filter} ?uri a ?stationTheme . OPTIONAL{{ - ?memb cpmeta:atOrganization ?uri . + ?memb cpmeta:atOrganization ?uri ; cpmeta:hasRole . optional {{?memb cpmeta:hasEndTime ?membEnd}} filter(!bound(?membEnd) || ?membEnd > now()) - ?memb cpmeta:hasRole . ?pers cpmeta:hasMembership ?memb }} }} From c79dd26aa2512d08089c2209f161166a17ae3109 Mon Sep 17 00:00:00 2001 From: "zoiszogop@gmail.com" Date: Fri, 11 Oct 2024 13:30:34 +0200 Subject: [PATCH 3/3] sparqls - add distinct to getIdList's query --- icoscp/src/icoscp/sparql/sparqls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/icoscp/src/icoscp/sparql/sparqls.py b/icoscp/src/icoscp/sparql/sparqls.py index 8747fd1..2359785 100644 --- a/icoscp/src/icoscp/sparql/sparqls.py +++ b/icoscp/src/icoscp/sparql/sparqls.py @@ -446,7 +446,7 @@ def station_query(filter: dict = None, return_filter: bool = False) -> str or (s prefix xsd: prefix cpmeta: prefix cpst: - select ?uri ?id ?name ?icosClass ?country ?lat ?lon ?elevation ?stationTheme ?firstName ?lastName ?email ?siteType + select distinct ?uri ?id ?name ?icosClass ?country ?lat ?lon ?elevation ?stationTheme ?firstName ?lastName ?email ?siteType from from from