Skip to content

Commit b9fd611

Browse files
Merge pull request #53 from DataIntegrationGroup/dev/jab
0.9.5: NMED DWB fix
2 parents ea7903a + 063b1b9 commit b9fd611

3 files changed

Lines changed: 33 additions & 16 deletions

File tree

backend/connectors/nmenv/source.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,24 @@ def get_records(self, *args, **kw):
8484

8585
q = q.filter(" and ".join(fs))
8686
q = q.expand("Thing/Locations")
87-
return [di.thing.locations.entities[0] for di in q.list()]
87+
88+
# NM ENV has multiple datastreams per parameter per location (e.g. id 8 and arsenic)
89+
# because of this duplicative site information is retrieved (we operated under the assumption one datastream per location per parameter)
90+
# so we need to filter out duplicates, otherwise there will be multiple site records and duplicative parameter records
91+
all_sites = [di.thing.locations.entities[0] for di in q.list()]
92+
93+
# can't do list(set(all_sites)) because the Location entities are not hashable
94+
site_dictionary = {}
95+
for site in all_sites:
96+
site_id = site.id
97+
if site_id not in site_dictionary.keys():
98+
site_dictionary[site_id] = site
99+
100+
distinct_sites = list(site_dictionary.values())
101+
# print(
102+
# f"Found {len(all_sites)} datastreams for {analyte} and {len(distinct_sites)} distinct sites."
103+
# )
104+
return distinct_sites
88105

89106

90107
class DWBAnalyteSource(STAnalyteSource):
@@ -120,16 +137,20 @@ def get_records(self, site, *args, **kw):
120137
f"Thing/Locations/id eq {site.id} and ObservedProperty/id eq {analyte}"
121138
)
122139

123-
ds = q.list().entities[0]
140+
# NMED DWB has multiple datastreams per parameter per location (e.g. id 8 and arsenic)
141+
# print(
142+
# f"Found {len(q.list().entities)} datastreams for {site.id} and {analyte}."
143+
# )
124144
rs = []
125-
for obs in ds.get_observations().query().list():
126-
rs.append(
127-
{
128-
"location": site,
129-
"datastream": ds,
130-
"observation": obs,
131-
}
132-
)
145+
for datastream in q.list().entities:
146+
for obs in datastream.get_observations().query().list():
147+
rs.append(
148+
{
149+
"location": site,
150+
"datastream": datastream,
151+
"observation": obs,
152+
}
153+
)
133154

134155
return rs
135156

backend/transformer.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,7 @@ def do_transform(
530530
if warning_msg != "":
531531
msg = f"{warning_msg} for {klassed_record.id}"
532532
self.warn(msg)
533-
except TypeError:
534-
msg = f"Keeping {source_result} for {klassed_record.id} on {klassed_record.date_measured} for time series data"
535-
self.warn(msg)
536-
converted_result = source_result
537-
except ValueError:
533+
except (TypeError, ValueError):
538534
msg = f"Keeping {source_result} for {klassed_record.id} on {klassed_record.date_measured} for time series data"
539535
self.warn(msg)
540536
converted_result = source_result

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
setup(
2424
name="nmuwd",
25-
version="0.9.4",
25+
version="0.9.5",
2626
author="Jake Ross",
2727
description="New Mexico Water Data Integration Engine",
2828
long_description=long_description,

0 commit comments

Comments
 (0)