Skip to content

Commit 13b664b

Browse files
author
Stephanie Reeder
committed
fix sample file so that it is not throwing an error when plotting
1 parent 3eb9b86 commit 13b664b

File tree

3 files changed

+26
-36
lines changed

3 files changed

+26
-36
lines changed

Examples/Sample.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
__author__ = 'stephanie'
2-
import sys
3-
import os
2+
43

54

65
import matplotlib.pyplot as plt
76
from matplotlib import dates
87

98

10-
#this will be removed when we can installthe api
11-
# this_file = os.path.realpath(__file__)
12-
# directory = os.path.dirname(os.path.dirname(this_file))
13-
# print directory
14-
# sys.path.insert(0, directory)
159

1610
from odm2api.ODMconnection import dbconnection
1711
from odm2api.ODM2.services.readService import *
@@ -20,16 +14,15 @@
2014

2115

2216
#connect to database
23-
#createconnection (dbtype, servername, dbname, username, password)
17+
# createconnection (dbtype, servername, dbname, username, password)
18+
# session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)#sqlite
2419
# session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')#mysql
25-
#session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)#sqlite
2620
# session_factory= dbconnection.createConnection('mssql', "(local)", "LBRODM2", "ODM", "odm")#win MSSQL
2721
session_factory= dbconnection.createConnection('mssql', "arroyoodm2", "", "ODM", "odm")#mac/linux MSSQL
2822

2923

3024

3125
#_session = session_factory.getSession()
32-
3326
read = ReadODM2(session_factory)
3427

3528

@@ -152,25 +145,17 @@
152145
# Print a few Time Series Values to the console
153146
# tsValues.set_index('ValueDateTime', inplace=True)
154147
try:
148+
print "tsValues "
155149
print tsValues.head()
156150
except Exception as e:
157151
print e
158152

159153
# Plot the time series
160154

161155
try:
162-
fig = plt.figure()
163-
ax = fig.add_subplot(111)
164-
tsValues.plot(x='ValueDateTime', y='DataValue', kind='line',
165-
title=tsResult.ResultObj.VariableObj.VariableNameCV + " at " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName,
166-
ax=ax)
167-
ax.set_ylabel(tsResult.ResultObj.VariableObj.VariableNameCV + " (" + tsResult.ResultObj.UnitsObj.UnitsAbbreviation + ")")
168-
ax.set_xlabel("Date/Time")
169-
ax.xaxis.set_minor_locator(dates.MonthLocator())
170-
ax.xaxis.set_minor_formatter(dates.DateFormatter('%b'))
171-
ax.xaxis.set_major_locator(dates.YearLocator())
172-
ax.xaxis.set_major_formatter(dates.DateFormatter('\n%Y'))
173-
ax.grid(True)
156+
plt.figure()
157+
ax=tsValues.plot(x='ValueDateTime', y='DataValue')
158+
174159
plt.show()
175160
except Exception as e:
176161
print "Unable to demo plotting of tsValues: ", e

odm2api/ODM2/models.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,6 @@ def __repr__(self):
480480
# ################################################################################
481481

482482

483-
484-
485-
486-
487483
class DataLoggerProgramFiles(Base):
488484
__tablename__ = u'dataloggerprogramfiles'
489485
__table_args__ = {u'schema': 'odm2'}
@@ -510,8 +506,6 @@ class DataLoggerFiles(Base):
510506
ProgramObj = relationship(DataLoggerProgramFiles)
511507

512508

513-
514-
515509
class EquipmentModels(Base):
516510
__tablename__ = u'equipmentmodels'
517511
__table_args__ = {u'schema': 'odm2'}

odm2api/ODM2/services/readService.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,15 +656,26 @@ def getResultValues(self, resultid, starttime=None, endtime=None):
656656
657657
658658
"""
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)
659+
type= self._session.query(Results).filter_by(ResultID=resultid).first().ResultTypeCV
660+
Result = TimeSeriesResults
661+
if "categorical" in type.lower():Result = CategoricalResultValues
662+
elif "measurement" in type.lower():Result = MeasurementResultValues
663+
elif "point" in type.lower():Result = PointCoverageResultValues
664+
elif "profile" in type.lower():Result = ProfileResultValues
665+
elif "section" in type.lower():Result = SectionResults
666+
elif "spectra" in type.lower():Result = SpectraResultValues
667+
elif "time" in type.lower():Result = TimeSeriesResultValues
668+
elif "trajectory" in type.lower():Result = TrajectoryResultValues
669+
elif "transect" in type.lower():Result = TransectResultValues
670+
671+
672+
q = self._session.query(Result).filter_by(ResultID=resultid)
673+
if starttime: q = q.filter(Result.ValueDateTime >= starttime)
674+
if endtime: q = q.filter(Result.ValueDateTime <= endtime)
664675
try:
665-
q = q.order_by(Results.ValueDateTime).all()
666-
df = pd.DataFrame([dv.list_repr() for dv in q.all()])
667-
df.columns = q[0].get_columns()
676+
vals = q.order_by(Result.ValueDateTime)
677+
df = pd.DataFrame([dv.list_repr() for dv in vals.all()])
678+
df.columns = vals[0].get_columns()
668679
return df
669680
except:
670681
return None

0 commit comments

Comments
 (0)