Skip to content

Commit 07875b2

Browse files
author
sreeder
committed
move higher level into basic get functions
1 parent d1fb40e commit 07875b2

1 file changed

Lines changed: 32 additions & 52 deletions

File tree

odm2api/ODM2/services/readService.py

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -50,56 +50,6 @@ def __init__(self, session):
5050
self._session = session
5151
'''
5252

53-
# ################################################################################
54-
# Higher level functions
55-
# ################################################################################
56-
def getUsedSites(self):
57-
"""
58-
Return a list of all sites that are being referenced in the Series Catalog Table
59-
:return: List[Sites]
60-
"""
61-
try:
62-
fas = [x[0] for x in self._session.query(distinct(Results.FeatureActionID)).all()]
63-
except:
64-
return None
65-
66-
sf = [x[0] for x in self._session.query(distinct(FeatureActions.SamplingFeatureID))
67-
.filter(FeatureActions.FeatureActionID.in_(fas)).all()]
68-
69-
sites = self.read.getSamplingFeatures(type="site", ids=sf)
70-
return sites
71-
72-
def getUsedVariables(self):
73-
"""
74-
#get list of used variable ids
75-
:return: List[Variables]
76-
"""
77-
try:
78-
ids= [x[0] for x in self._session.query(distinct(Results.VariableID)).all()]
79-
except:
80-
return None
81-
82-
vars= self.read.getVariables(ids = ids)
83-
return vars
84-
85-
def getVariablesBySiteCode(self, site_code):
86-
"""
87-
Finds all of variables at a site
88-
:param site_code: str
89-
:return: List[Variables]
90-
"""
91-
try:
92-
var_ids = [x[0] for x in
93-
self._session.query(distinct(Results.VariableID))
94-
.filter(Results.FeatureActionID == FeatureActions.FeatureActionID)
95-
.filter(FeatureActions.SamplingFeatureID == SamplingFeatures.SamplingFeatureID)
96-
.filter(SamplingFeatures.SamplingFeatureCode == site_code).all()
97-
]
98-
except:
99-
var_ids = None
100-
101-
q = self._session.query(Variables).filter(Variables.VariableID.in_(var_ids))
102-
return q.all()
10353

10454
# ################################################################################
10555
# Exists functions
@@ -293,14 +243,34 @@ def getTaxonomicClassifiers(self):
293243
Variable
294244
"""
295245

296-
def getVariables(self, ids=None, codes=None):
246+
def getVariables(self, ids=None, codes=None, sitecode=None, results= False):
297247
"""
298248
getVariables()
299249
* Pass nothing - returns full list of variable objects
300250
* Pass a list of VariableID - returns a single variable object
301251
* Pass a list of VariableCode - returns a single variable object
252+
* Pass a SiteCode - returns a list of Variable objects that are collected at the given site.
253+
* Pass whether or not you want to return the sampling features that have results associated with them
302254
"""
303255

256+
if sitecode:
257+
try:
258+
ids = [x[0] for x in
259+
self._session.query(distinct(Results.VariableID))
260+
.filter(Results.FeatureActionID == FeatureActions.FeatureActionID)
261+
.filter(FeatureActions.SamplingFeatureID == SamplingFeatures.SamplingFeatureID)
262+
.filter(SamplingFeatures.SamplingFeatureCode == sitecode).all()
263+
]
264+
except:
265+
ids = None
266+
267+
268+
if results:
269+
try:
270+
ids = [x[0] for x in self._session.query(distinct(Results.VariableID)).all()]
271+
except:
272+
ids = None
273+
304274
query = self._session.query(Variables)
305275
if ids: query = query.filter(Variables.VariableID.in_(ids))
306276
if codes: query = query.filter(Variables.VariableCode.in_(codes))
@@ -359,16 +329,26 @@ def getProcessingLevels(self, ids=None, codes=None):
359329
Sampling Feature
360330
"""
361331

362-
def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=None):
332+
def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=None, results=False):
363333
"""
364334
getSamplingFeatures
365335
* Pass nothing - returns a list of all sampling feature objects with each object of type specific to that sampling feature
366336
* Pass a list of SamplingFeatureID - returns a single sampling feature object
367337
* Pass a list of SamplingFeatureCode - returns a single sampling feature object
368338
* Pass a SamplingFeatureType - returns a list of sampling feature objects of the type passed in
369339
* Pass a SamplingFeatureGeometry(TYPE????) - return a list of sampling feature objects
340+
* Pass whether or not you want to return the sampling features that have results associated with them
370341
"""
342+
if results:
343+
try:
344+
fas = [x[0] for x in self._session.query(distinct(Results.FeatureActionID)).all()]
345+
except:
346+
return None
347+
348+
sf = [x[0] for x in self._session.query(distinct(FeatureActions.SamplingFeatureID))
349+
.filter(FeatureActions.FeatureActionID.in_(fas)).all()]
371350

351+
ids = sf
372352
q = self._session.query(SamplingFeatures)
373353

374354
if type: q = q.filter_by(SamplingFeatureTypeCV=type)

0 commit comments

Comments
 (0)