Skip to content

Commit 3eb9b86

Browse files
author
Stephanie Reeder
committed
update sample to work with inheritance
1 parent d01a8f0 commit 3eb9b86

File tree

3 files changed

+17
-36
lines changed

3 files changed

+17
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ log
4242
.idea
4343

4444
.DS_Store
45+
.ipynb_checkpoints

Examples/Sample.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
numSites = len(siteFeatures)
6565

6666
for x in siteFeatures:
67-
print x.SamplingFeatureCode + ": " + x.SamplingFeatureName + ", " + x.SamplingFeatureTypeCV
67+
print x.SamplingFeatureCode + ": " + str(x.SamplingFeatureName) + ", " + x.SamplingFeatureTypeCV
6868
except Exception as e:
6969
print "Unable to demo getSamplingFeaturesByType", e
7070

@@ -127,20 +127,20 @@
127127
# Now get a particular Result using a ResultID
128128
print "\n------- Example of Retrieving Attributes of a Time Series Result -------"
129129
try:
130-
tsResult = read.getResults(id = 1)
130+
tsResult = read.getResults(id = 1)[0]
131131
print (
132132
"The following are some of the attributes for the TimeSeriesResult retrieved using getTimeSeriesResultByResultID(): \n" +
133-
"ResultTypeCV: " + tsResult.ResultObj.ResultTypeCV + "\n" +
133+
"ResultTypeCV: " + tsResult.ResultTypeCV + "\n" +
134134
# Get the ProcessingLevel from the TimeSeriesResult's ProcessingLevel object
135-
"ProcessingLevel: " + tsResult.ResultObj.ProcessingLevelObj.Definition + "\n" +
136-
"SampledMedium: " + tsResult.ResultObj.SampledMediumCV + "\n" +
135+
"ProcessingLevel: " + tsResult.ProcessingLevelObj.Definition + "\n" +
136+
"SampledMedium: " + tsResult.SampledMediumCV + "\n" +
137137
# Get the variable information from the TimeSeriesResult's Variable object
138-
"Variable: " + tsResult.ResultObj.VariableObj.VariableCode + ": " + tsResult.ResultObj.VariableObj.VariableNameCV + "\n"
138+
"Variable: " + tsResult.VariableObj.VariableCode + ": " + tsResult.VariableObj.VariableNameCV + "\n"
139139
"AggregationStatistic: " + tsResult.AggregationStatisticCV + "\n" +
140140
"Elevation_m: " + str(sf.Elevation_m) + "\n" +
141141
# Get the site information by drilling down
142-
"SamplingFeature: " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
143-
tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
142+
"SamplingFeature: " + tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
143+
tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
144144
except Exception as e:
145145
print "Unable to demo Example of retrieving Attributes of a time Series Result: ", e
146146

odm2api/ODM2/services/readService.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def getPeople(self, id=None, firstname=None, lastname=None):
381381
except:
382382
return None
383383

384-
def getAffiliations(self, id, personfirst=None, personlast=None, orgcode=None):
384+
def getAffiliations(self, id=None, personfirst=None, personlast=None, orgcode=None):
385385
"""
386386
Select all affiliation of person
387387
:param personfirst: first name of person
@@ -644,7 +644,7 @@ def getResultDerivationEquations(self):
644644
ResultValues
645645
"""
646646

647-
def getResultValues(self, resultid=None, starttime=None, endtime=None):
647+
def getResultValues(self, resultid, starttime=None, endtime=None):
648648

649649
"""Select all on TimeSeriesResults
650650
getResultValues()
@@ -656,33 +656,13 @@ def getResultValues(self, resultid=None, starttime=None, endtime=None):
656656
657657
658658
"""
659-
type = self._session.query(Results).filter_by(ResultID=resultid).first().ResultTypeCV
660-
Result = TimeSeriesResults
661-
662-
if "categorical" in type.lower():
663-
Result = CategoricalResultValues
664-
elif "measurement" in type.lower():
665-
Result = MeasurementResultValues
666-
elif "coverage" in type.lower():
667-
Result = PointCoverageResultValues
668-
elif "profile" in type.lower():
669-
Result = ProfileResultValues
670-
elif "section" in type.lower():
671-
Result = SectionResults
672-
elif "spectra" in type.lower():
673-
Result = SpectraResultValues
674-
elif "time" in type.lower():
675-
Result = TimeSeriesResultValues
676-
elif "trajectory" in type.lower():
677-
Result = TrajectoryResultValues
678-
elif "transect" in type.lower():
679-
Result = TransectResultValues
680-
681-
q = self._session.query(Result).filter_by(ResultID=id)
682-
if starttime: q = q.filter(Result.ValueDateTime >= starttime)
683-
if endtime: q = q.filter(Result.ValueDateTime <= endtime)
659+
660+
661+
q = self._session.query(Results).filter_by(ResultID=id)
662+
if starttime: q = q.filter(Results.ValueDateTime >= starttime)
663+
if endtime: q = q.filter(Results.ValueDateTime <= endtime)
684664
try:
685-
q = q.order_by(Result.ValueDateTime).all()
665+
q = q.order_by(Results.ValueDateTime).all()
686666
df = pd.DataFrame([dv.list_repr() for dv in q.all()])
687667
df.columns = q[0].get_columns()
688668
return df

0 commit comments

Comments
 (0)