Skip to content

Commit a4febb4

Browse files
author
sreeder
committed
fix issue with getSamplingFeatureDatasets
1 parent 9624cc5 commit a4febb4

File tree

3 files changed

+48
-21
lines changed

3 files changed

+48
-21
lines changed

odm2api/ODM2/services/readService.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,8 @@ def getResults(self, ids=None, type=None, uuids=None, actionid=None, simulationi
632632
simulationid (int, optional): SimulationID.
633633
sfid (int, optional): SamplingFeatureID.
634634
variableid (int, optional): VariableID.
635-
siteid (int, optional): SiteID.
635+
siteid (int, optional): SiteID. - goes through related features table and finds all of the measurement
636+
values recorded at the given site
636637
637638
Returns:
638639
list: List of Result objects
@@ -829,8 +830,9 @@ def getSamplingFeatureDatasets(self, ids=None, codes=None, uuids=None, dstype=No
829830
sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureCode.in_(codes))
830831
if uuids:
831832
sf_query = sf_query.filter(SamplingFeatures.SamplingFeatureUUID.in_(uuids))
832-
sf_list = sf_query.all()
833-
833+
sf_list = []
834+
for sf in sf_query.all():
835+
sf_list.append(sf[0])
834836

835837
q = self._session.query(DataSetsResults)\
836838
.join(Results)\

tests/test_odm2/data/populated.sql

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11568,20 +11568,20 @@ INSERT INTO "TimeSeriesResultValues" VALUES(10009,1,315.0,'2013-05-27 00:00:00',
1156811568
INSERT INTO "TimeSeriesResultValues" VALUES(10010,1,316.0,'2013-05-12 00:00:00',-6,'nc','provisional',0.0,204);
1156911569
INSERT INTO "TimeSeriesResultValues" VALUES(10011,1,317.0,'2013-05-29 00:00:00',-6,'nc','provisional',0.0,204);
1157011570
INSERT INTO "TimeSeriesResultValues" VALUES(10012,1,320.0,'2013-05-25 00:00:00',-6,'nc','provisional',0.0,204);
11571-
INSERT INTO "TimeSeriesResultValues" VALUES(10013,1,321.0,'2013-05-28 00:00:00',-6,'nc','provisional',0.0,204);
11572-
INSERT INTO "TimeSeriesResultValues" VALUES(10014,1,322.0,'2013-05-26 00:00:00',-6,'nc','provisional',0.0,204);
11573-
INSERT INTO "TimeSeriesResultValues" VALUES(10015,1,338.0,'2013-05-24 00:00:00',-6,'nc','provisional',0.0,204);
11574-
INSERT INTO "TimeSeriesResultValues" VALUES(10016,1,341.0,'2013-05-22 00:00:00',-6,'nc','provisional',0.0,204);
11575-
INSERT INTO "TimeSeriesResultValues" VALUES(10017,1,346.0,'2013-05-21 00:00:00',-6,'nc','provisional',0.0,204);
11576-
INSERT INTO "TimeSeriesResultValues" VALUES(10018,1,347.0,'2013-05-23 00:00:00',-6,'nc','provisional',0.0,204);
11577-
INSERT INTO "TimeSeriesResultValues" VALUES(10019,1,358.0,'2013-05-13 00:00:00',-6,'nc','provisional',0.0,204);
11578-
INSERT INTO "TimeSeriesResultValues" VALUES(10020,1,367.0,'2013-05-20 00:00:00',-6,'nc','provisional',0.0,204);
11579-
INSERT INTO "TimeSeriesResultValues" VALUES(10021,1,393.0,'2013-05-19 00:00:00',-6,'nc','provisional',0.0,204);
11580-
INSERT INTO "TimeSeriesResultValues" VALUES(10022,1,422.0,'2013-05-14 00:00:00',-6,'nc','provisional',0.0,204);
11581-
INSERT INTO "TimeSeriesResultValues" VALUES(10023,1,453.0,'2013-05-18 00:00:00',-6,'nc','provisional',0.0,204);
11582-
INSERT INTO "TimeSeriesResultValues" VALUES(10024,1,458.0,'2013-05-15 00:00:00',-6,'nc','provisional',0.0,204);
11583-
INSERT INTO "TimeSeriesResultValues" VALUES(10025,1,478.0,'2013-05-16 00:00:00',-6,'nc','provisional',0.0,204);
11584-
INSERT INTO "TimeSeriesResultValues" VALUES(10026,1,480.0,'2013-05-17 00:00:00',-6,'nc','provisional',0.0,204);
11571+
INSERT INTO "TimeSeriesResultValues" VALUES(10013,1,321.0,'2013-05-28',-6,'nc','provisional',0.0,204);
11572+
INSERT INTO "TimeSeriesResultValues" VALUES(10014,1,322.0,'2013-05-26',-6,'nc','provisional',0.0,204);
11573+
INSERT INTO "TimeSeriesResultValues" VALUES(10015,1,338.0,'2013-05-24',-6,'nc','provisional',0.0,204);
11574+
INSERT INTO "TimeSeriesResultValues" VALUES(10016,1,341.0,'2013-05-22',-6,'nc','provisional',0.0,204);
11575+
INSERT INTO "TimeSeriesResultValues" VALUES(10017,1,346.0,'2013-05-21',-6,'nc','provisional',0.0,204);
11576+
INSERT INTO "TimeSeriesResultValues" VALUES(10018,1,347.0,'2013-05-23',-6,'nc','provisional',0.0,204);
11577+
INSERT INTO "TimeSeriesResultValues" VALUES(10019,1,358.0,'2013-05-13',-6,'nc','provisional',0.0,204);
11578+
INSERT INTO "TimeSeriesResultValues" VALUES(10020,1,367.0,'2013-05-20',-6,'nc','provisional',0.0,204);
11579+
INSERT INTO "TimeSeriesResultValues" VALUES(10021,1,393.0,'2013-05-19',-6,'nc','provisional',0.0,204);
11580+
INSERT INTO "TimeSeriesResultValues" VALUES(10022,1,422.0,'2013-05-14',-6,'nc','provisional',0.0,204);
11581+
INSERT INTO "TimeSeriesResultValues" VALUES(10023,1,453.0,'2013-05-18',-6,'nc','provisional',0.0,204);
11582+
INSERT INTO "TimeSeriesResultValues" VALUES(10024,1,458.0,'2013-05-15',-6,'nc','provisional',0.0,204);
11583+
INSERT INTO "TimeSeriesResultValues" VALUES(10025,1,478.0,'2013-05-16',-6,'nc','provisional',0.0,204);
11584+
INSERT INTO "TimeSeriesResultValues" VALUES(10026,1,480.0,'2013-05-17',-6,'nc','provisional',0.0,204);
1158511585
INSERT INTO "TimeSeriesResultValues" VALUES(10027,2,0.0,'02/07/2013 00:00:00',-5,'nc','provisional',1.0,206);
1158611586
INSERT INTO "TimeSeriesResultValues" VALUES(10028,2,0.254,'02/07/2013 00:01:00',-5,'nc','provisional',1.0,206);
1158711587
INSERT INTO "TimeSeriesResultValues" VALUES(10029,2,0.254,'02/07/2013 00:02:00',-5,'nc','provisional',1.0,206);

tests/test_odm2/test_readservice.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,32 @@ def test_getDataSetsValues(self):
124124

125125
#ToDo figure out how to actually test this function
126126
def test_getSamplingFeatureDataSets(self):
127-
assert True
127+
128+
#find a sampling feature that is associated with a dataset
129+
sf = self.engine.execute(
130+
'SELECT * from SamplingFeatures as sf '
131+
'inner join FeatureActions as fa on fa.SamplingFeatureID == sf.SamplingFeatureID '
132+
'inner join Results as r on fa.FeatureActionID == r.FeatureActionID '
133+
'inner join DataSetsResults as ds on r.ResultID == ds.ResultID '
134+
).fetchone()
135+
assert len(sf) > 0
136+
137+
#get the dataset associated with the sampling feature
138+
ds = self.engine.execute(
139+
'SELECT * from DataSetsResults as ds '
140+
'inner join Results as r on r.ResultID == ds.ResultID '
141+
'inner join FeatureActions as fa on fa.FeatureActionID == r.FeatureActionID '
142+
'where fa.SamplingFeatureID = ' + str(sf[0])
143+
).fetchone()
144+
assert len(ds) > 0
145+
146+
print (sf[0])
147+
# get the dataset associated with the sampling feature using hte api
148+
dsapi = self.reader.getSamplingFeatureDatasets(ids=[sf[0]])
149+
150+
assert dsapi is not None
151+
assert len(dsapi) > 0
152+
assert ds[1] == dsapi[0].DataSetID
128153

129154

130155
# Models
@@ -178,7 +203,7 @@ def test_getRelatedModelsByCode(self):
178203
resapi = self.reader.getRelatedModels(code='swat')
179204
assert resapi is not None
180205
assert len(resapi) > 0
181-
print(resapi[0].ModelCode)
206+
# print(resapi[0].ModelCode)
182207
assert resapi[0].ModelCode == 'swat'
183208
# test converter code that doesn't exist
184209
resapi = self.reader.getRelatedModels(code='None')
@@ -213,7 +238,7 @@ def test_getRelatedModelsByCode(self):
213238
def test_getAllResults(self):
214239
# get all results from the database
215240
res = self.engine.execute('SELECT * FROM Results').fetchall()
216-
print(res)
241+
# print(res)
217242
# get all results using the api
218243
resapi = self.reader.getResults()
219244
assert len(res) == len(resapi)
@@ -281,7 +306,7 @@ def test_getResultsBySimulationID(self):
281306
).first()
282307
assert len(res) > 0
283308
res = rawSql2Alchemy(res, models.Results)
284-
print(res)
309+
# print(res)
285310

286311
# get simulation by id using the api
287312
# resapi = self.reader.getResultsBySimulationID(simulation.SimulationID)

0 commit comments

Comments
 (0)