@@ -78,7 +78,7 @@ def resultExists(self, result):
78
78
# Annotations
79
79
# ################################################################################
80
80
81
- def getAnnotations (self , type = None , codes = None , ids = None ):
81
+ def getAnnotations (self , type = None , codes = None , ids = None ):
82
82
"""
83
83
def getAnnotations(self, type=None, codes = None, ids = None):
84
84
@@ -279,21 +279,30 @@ def getVariables(self, ids=None, codes=None, sitecode=None, results= False):
279
279
280
280
if sitecode :
281
281
try :
282
- ids = [x [0 ] for x in
282
+ vars = [x [0 ] for x in
283
283
self ._session .query (distinct (Results .VariableID ))
284
284
.filter (Results .FeatureActionID == FeatureActions .FeatureActionID )
285
285
.filter (FeatureActions .SamplingFeatureID == SamplingFeatures .SamplingFeatureID )
286
286
.filter (SamplingFeatures .SamplingFeatureCode == sitecode ).all ()
287
287
]
288
+
289
+ if ids :
290
+ ids = list (set (ids ).intersection (vars ))
291
+ else :
292
+ ids = vars
288
293
except :
289
- ids = None
294
+ pass
290
295
291
296
292
297
if results :
293
298
try :
294
- ids = [x [0 ] for x in self ._session .query (distinct (Results .VariableID )).all ()]
299
+ vars = [x [0 ] for x in self ._session .query (distinct (Results .VariableID )).all ()]
300
+ if ids :
301
+ ids = list (set (ids ).intersection (vars ))
302
+ else :
303
+ ids = vars
295
304
except :
296
- ids = None
305
+ pass
297
306
298
307
query = self ._session .query (Variables )
299
308
if ids : query = query .filter (Variables .VariableID .in_ (ids ))
@@ -362,18 +371,20 @@ def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=N
362
371
* Pass a list of SamplingFeatureUUID - returns a single sampling feature object for the given UUID's
363
372
* Pass a SamplingFeatureType - returns a list of sampling feature objects of the type passed in
364
373
* Pass a SamplingFeature Well Known Text - return a list of sampling feature objects
365
- * Pass whether or not you want to return the sampling features that have results associated with them
374
+ * Pass whether or not you want to return only the sampling features that have results associated with them
366
375
"""
367
376
if results :
368
377
try :
369
378
fas = [x [0 ] for x in self ._session .query (distinct (Results .FeatureActionID )).all ()]
370
379
except :
371
380
return None
372
-
373
381
sf = [x [0 ] for x in self ._session .query (distinct (FeatureActions .SamplingFeatureID ))
374
- .filter (FeatureActions .FeatureActionID .in_ (fas )).all ()]
382
+ .filter (FeatureActions .FeatureActionID .in_ (fas )).all ()]
383
+ if ids :
384
+ ids = list (set (ids ).intersection (sf ))
385
+ else :
386
+ ids = sf
375
387
376
- ids = sf
377
388
q = self ._session .query (SamplingFeatures )
378
389
379
390
if type : q = q .filter_by (SamplingFeatureTypeCV = type )
@@ -391,7 +402,7 @@ def getRelatedSamplingFeatures(self, sfid=None, rfid = None, relationshiptype=No
391
402
#TODO: add functionality to filter by code
392
403
"""
393
404
getRelatedSamplingFeatures(self, sfid=None, rfid = None, relationshiptype=None):
394
- * Pass a SamplingFeatureID - get a list of sampling feature objects related to the input sampling feature along with the relationship type
405
+ * Pass a SamplingFeatureID - get a list of sampling feature objects related to the input sampling feature
395
406
* Pass a RelatedFeatureID - get a list of Sampling features objects through the related feature
396
407
* Pass a RelationshipTypeCV - get a list of sampling feature objects with the given type
397
408
@@ -400,19 +411,19 @@ def getRelatedSamplingFeatures(self, sfid=None, rfid = None, relationshiptype=No
400
411
# q = session.query(Address).select_from(User). \
401
412
# join(User.addresses). \
402
413
# filter(User.name == 'ed')
403
- #throws an error when joining entire samplingfeature, works fine when just getting an element. this is being caused by the sampling feature inheritance
414
+ #throws an error when joining entire samplingfeature, works fine when just getting an element. this is being
415
+ # caused by the sampling feature inheritance
404
416
405
417
sf = self ._session .query (distinct (SamplingFeatures .SamplingFeatureID ))\
406
- .select_from (RelatedFeatures )
407
-
418
+ .select_from (RelatedFeatures )
408
419
409
420
if sfid : sf = sf .join (RelatedFeatures .RelatedFeatureObj ).filter (RelatedFeatures .SamplingFeatureID == sfid )
410
421
if rfid : sf = sf .join (RelatedFeatures .SamplingFeatureObj ).filter (RelatedFeatures .RelatedFeatureID == rfid )
411
422
if relationshiptype : sf = sf .filter (RelatedFeatures .RelationshipTypeCV == relationshiptype )
412
423
try :
413
- sfids = [x [0 ] for x in sf .all ()]
414
- if len (sfids )> 0 :
415
- sflist = self .getSamplingFeatures (ids = sfids )
424
+ sfids = [x [0 ] for x in sf .all ()]
425
+ if len (sfids ) > 0 :
426
+ sflist = self .getSamplingFeatures (ids = sfids )
416
427
return sflist
417
428
418
429
except Exception as e :
@@ -577,7 +588,6 @@ def getResults(self, ids=None, type=None, uuids=None, actionid=None, simulationi
577
588
578
589
query = self ._session .query (Results )
579
590
580
-
581
591
if type : query = query .filter_by (ResultTypeCV = type )
582
592
if variableid : query = query .filter_by (VariableID = variableid )
583
593
if ids : query = query .filter (Results .ResultID .in_ (ids ))
@@ -624,7 +634,7 @@ def getDataSets(self, codes=None, uuids=None):
624
634
try :
625
635
return q .all ()
626
636
except Exception as e :
627
- print ("Error running Query %s" % e )
637
+ print ("Error running Query %s" % e )
628
638
return None
629
639
630
640
# ################################################################################
0 commit comments