Commit b1202662 authored by ALVISET's avatar ALVISET
Browse files

Fixed few predicates issues

parent 7a29e5f4
......@@ -53,7 +53,7 @@ def append_cycle_date_triples(g, profgrp, cycle, prefix):
g.add((cycle, prefix.date, Literal("{}T{}:{}:00".format(offset, hours, minutes), datatype=XSD.datetime)))
def calculate_age(timestamp):
fdate = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.000+0000")
fdate = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.000+00:00")
timedelta = (datetime.now() - datetime.fromtimestamp(time.mktime(fdate.timetuple())))
age = None
if timedelta != None:
......@@ -265,10 +265,11 @@ def map_file_to_prov(file, file_uri, cycle_uri, wrapper, files_info, dac_uri):
def retrieve_cycle_basins(cycleId):
basins = []
cycleInfo = requests.get("https://dataselection.euro-argo.eu/api/find-by-id/" + str(cycleId))
if cycleInfo != None and cycleInfo.text != None:
if cycleInfo != None and cycleInfo.text != None and cycleInfo.text != "":
cycleInfo = json.loads(cycleInfo.text)
for basin in cycleInfo["basins"]:
basins.append(basin)
if "basins" in cycleInfo.keys():
for basin in cycleInfo["basins"]:
basins.append(basin)
return basins
......@@ -299,8 +300,8 @@ if __name__ == "__main__":
("foaf", FOAF),
("dcat", DCAT),
("dct", DCTERMS),
("sosa", SOSA),
("ssn", SSN),
("sosa", SSN), #RDFLib reverse SOSA and SSN...
("ssn", SOSA),
("geo", GEO),
("prov", PROV)
)
......@@ -483,14 +484,21 @@ if __name__ == "__main__":
groups = []
# Fetch the basin of the first and last cycles. If it is different, then make a search on each cycle.
first_basin = retrieve_cycle_basins(cycleIds[1])
last_basin = retrieve_cycle_basins(cycleIds[float_info["latestCycle"]["id"]])
print(first_basin)
print(last_basin)
fetch_basins = False
first_basin = []
last_basin = []
first = 0
for i in range(0, len(cycleIds.keys())):
if first not in cycleIds.keys():
first += 1
first_basin = retrieve_cycle_basins(cycleIds[first])
last_basin = retrieve_cycle_basins(cycleIds[float_info["latestCycle"]["id"]])
# print(first_basin)
# print(last_basin)
if set(first_basin) == len(set(first_basin).symmetric_difference(set(last_basin))) != 0:
fetch_basins = True
cycleInfo = requests.get("https://dataselection.euro-argo.eu/api/find-by-id/" + str(cycleIds[1]))
cycleInfo = requests.get("https://dataselection.euro-argo.eu/api/find-by-id/" + str(cycleIds[first ]))
# if cycleInfo != None and cycleInfo.text != None:
# cycleInfo = json.loads(cycleInfo.text)
# for basin in cycleInfo["basins"]:
......@@ -522,6 +530,7 @@ if __name__ == "__main__":
argo_graph.add_triple(cycle_uri, ARGO.basin, Literal(basin))
argo_graph.add_triple(afloat_uri, ARGO.cycle, cycle_uri)
argo_graph.add_triple(cycle_uri, DCTERMS.identifier, Literal(nb))
argo_graph.add_triples({
cycle_uri: [
(RDF.type, ARGO.Cycle),
......@@ -541,7 +550,7 @@ if __name__ == "__main__":
argo_graph.add_triple(file_uri, DCTERMS.created, Literal(prov["created"], datatype=XSD.datetime))
if files_info["infos"][file]["datamode"] != "R":
groupId = compare_prov_infos(prov, groups, afloat)
argo_graph.add_triple(file_uri, PROV.influencedBy, groups[groupId]["uri"])
argo_graph.add_triple(file_uri, PROV.wasInfluencedBy, groups[groupId]["uri"])
else:
argo_graph.add_triple(file_uri, ARGO.handbookVersion, prov["handbook"])
......@@ -553,6 +562,7 @@ if __name__ == "__main__":
adjusted_Params = {} # Keep profile params in memory to avoid duplicates
for group in groups:
# argo_graph.add_triple(group["uri"], ARGO.handbookVersion, group["handbook"])
# argo_graph.add_triple(group)
for step in group["steps"]:
argo_graph.add_triple(group["uri"], ARGO.historyStep, (NERC, "R12/current/", step))
for datastate in group["datastate"]:
......@@ -566,21 +576,23 @@ if __name__ == "__main__":
duo = "{};{}".format(param,group["paramsqc"][param])
if duo not in adjusted_Params.keys():
adjusted_Params[duo] = ARGO["{}profparam{}{}".format(afloat, param, group["paramsqc"][param])]
print(group["paramsqc"])
# print(group["paramsqc"])
argo_graph.add_triple(adjusted_Params[duo], ARGO.param, (NERC, "R03/current/", param))
argo_graph.add_triple(adjusted_Params[duo], ARGO.qc, (NERC, "RP2/current/", group["paramsqc"][param]))
argo_graph.add_triple(group["uri"], ARGO.profileParam, adjusted_Params[duo])
if group["dmqc"] != None:
dmqc_infos = group["dmqc"].split("|")
dmqc_name = dmqc_infos[2].split(",")[0].lower().strip()
if dmqc_name.lower() not in dmqc_ops.keys():
dmqc_uri = GraphWrapper.create_uri(ARGO, "dmqc", dmqc_name)
print(dmqc_uri)
dmqc_ops[dmqc_name] = dmqc_uri
argo_graph.add_triple(dmqc_uri, RDF.type, PROV.Agent)
argo_graph.add_triple(dmqc_uri, RDF.type, FOAF.Person)
argo_graph.add_triple(dmqc_uri, DCTERMS.identifier, dmqc_infos[1].strip())
argo_graph.add_triple(group["uri"], PROV.wasAttributedTo, dmqc_ops[dmqc_name])
print(dmqc_infos)
if len(dmqc_infos) > 1:
dmqc_name = dmqc_infos[2].split(",")[0].lower().strip()
if dmqc_name.lower() not in dmqc_ops.keys():
dmqc_uri = GraphWrapper.create_uri(ARGO, "dmqc", dmqc_name)
# print(dmqc_uri)
dmqc_ops[dmqc_name] = dmqc_uri
argo_graph.add_triple(dmqc_uri, RDF.type, PROV.Agent)
argo_graph.add_triple(dmqc_uri, RDF.type, FOAF.Person)
argo_graph.add_triple(dmqc_uri, DCTERMS.identifier, dmqc_infos[1].strip())
argo_graph.add_triple(group["uri"], PROV.wasAttributedTo, dmqc_ops[dmqc_name])
print("Number of groups: " + str(len(groups)))
print("Number of files: " + str(len(cycle_files)))
a += 1
......
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