Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions Examples/Sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,52 +40,52 @@
allVars = read.getVariables()

for x in allVars:
print x.VariableCode + ": " + x.VariableNameCV
print(x.VariableCode + ": " + x.VariableNameCV)



# Get all of the people from the database
allPeople = read.getPeople()

for x in allPeople:
print x.PersonFirstName + " " + x.PersonLastName
print(x.PersonFirstName + " " + x.PersonLastName)

try:
print "\n-------- Information about an Affiliation ---------"
print("\n-------- Information about an Affiliation ---------")
allaff = read.getAllAffiliations()
for x in allaff:
print x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID)
print(x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID))
except Exception as e:
print "Unable to demo getAllAffiliations", e
print("Unable to demo getAllAffiliations", e)

# Get all of the SamplingFeatures from the database that are Sites
try:
siteFeatures = read.getSamplingFeaturesByType('Site')
numSites = len(siteFeatures)

for x in siteFeatures:
print x.SamplingFeatureCode + ": " + x.SamplingFeatureName
print(x.SamplingFeatureCode + ": " + x.SamplingFeatureName)
except Exception as e:
print "Unable to demo getSamplingFeaturesByType", e
print("Unable to demo getSamplingFeaturesByType", e)


# Now get the SamplingFeature object for a SamplingFeature code
try:
sf = read.getSamplingFeatureByCode('USU-LBR-Mendon')
print sf
print "\n-------- Information about an individual SamplingFeature ---------"
print "The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n"
print "SamplingFeatureCode: " + sf.SamplingFeatureCode
print "SamplingFeatureName: " + sf.SamplingFeatureName
print "SamplingFeatureDescription: %s" % sf.SamplingFeatureDescription
print "SamplingFeatureGeotypeCV: %s" % sf.SamplingFeatureGeotypeCV
print "SamplingFeatureGeometry: %s" % sf.FeatureGeometry
print "Elevation_m: %s" % str(sf.Elevation_m)
print(sf)
print("\n-------- Information about an individual SamplingFeature ---------")
print("The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n")
print("SamplingFeatureCode: " + sf.SamplingFeatureCode)
print("SamplingFeatureName: " + sf.SamplingFeatureName)
print("SamplingFeatureDescription: %s" % sf.SamplingFeatureDescription)
print("SamplingFeatureGeotypeCV: %s" % sf.SamplingFeatureGeotypeCV)
print("SamplingFeatureGeometry: %s" % sf.FeatureGeometry)
print("Elevation_m: %s" % str(sf.Elevation_m))
except Exception as e:
print "Unable to demo getSamplingFeatureByCode: ", e
print("Unable to demo getSamplingFeatureByCode: ", e)

#add sampling feature
print "\n------------ Create Sampling Feature --------- \n",
print("\n------------ Create Sampling Feature --------- \n")
try:
from odm2api.ODM2.models import SamplingFeatures
newsf = SamplingFeatures()
Expand All @@ -100,19 +100,19 @@
newsf.SamplingFeatureUUID= sf.SamplingFeatureUUID+"2"
session.add(newsf)
#session.commit()
print "new sampling feature added to database", newsf
print("new sampling feature added to database", newsf)

except Exception as e :
print "error adding a sampling feature: " + str(e)
print("error adding a sampling feature: " + str(e))


# Drill down and get objects linked by foreign keys
print "\n------------ Foreign Key Example --------- \n",
print("\n------------ Foreign Key Example --------- \n",)
try:
# Call getResults, but return only the first result
firstResult = read.getResults()[0]
print "The FeatureAction object for the Result is: ", firstResult.FeatureActionObj
print "The Action object for the Result is: ", firstResult.FeatureActionObj.ActionObj
print("The FeatureAction object for the Result is: ", firstResult.FeatureActionObj)
print("The Action object for the Result is: ", firstResult.FeatureActionObj.ActionObj)
print ("\nThe following are some of the attributes for the Action that created the Result: \n" +
"ActionTypeCV: " + firstResult.FeatureActionObj.ActionObj.ActionTypeCV + "\n" +
"ActionDescription: " + firstResult.FeatureActionObj.ActionObj.ActionDescription + "\n" +
Expand All @@ -121,11 +121,11 @@
"MethodName: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodName + "\n" +
"MethodDescription: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodDescription)
except Exception as e:
print "Unable to demo Foreign Key Example: ", e
print("Unable to demo Foreign Key Example: ", e)


# Now get a particular Result using a ResultID
print "\n------- Example of Retrieving Attributes of a Time Series Result -------"
print("\n------- Example of Retrieving Attributes of a Time Series Result -------")
try:
tsResult = read.getTimeSeriesResultByResultId(1)
print (
Expand All @@ -142,19 +142,19 @@
"SamplingFeature: " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
except Exception as e:
print "Unable to demo Example of retrieving Attributes of a time Series Result: ", e
print("Unable to demo Example of retrieving Attributes of a time Series Result: ", e)

# Get the values for a particular TimeSeriesResult
print "\n-------- Example of Retrieving Time Series Result Values ---------"
print("\n-------- Example of Retrieving Time Series Result Values ---------")

tsValues = read.getTimeSeriesResultValuesByResultId(1) # Return type is a pandas dataframe

# Print a few Time Series Values to the console
# tsValues.set_index('ValueDateTime', inplace=True)
try:
print tsValues.head()
print(tsValues.head())
except Exception as e:
print e
print(e)

# Plot the time series

Expand All @@ -173,4 +173,4 @@
ax.grid(True)
plt.show()
except Exception as e:
print "Unable to demo plotting of tsValues: ", e
print("Unable to demo plotting of tsValues: ", e)
2 changes: 1 addition & 1 deletion odm2api/ODM1_1_1/services/edit_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def updateSeries(self, var=None, method=None, qcl=None, is_new_series=False):
print("Save existing series ID: %s" % str(series.id))
series = tseries
else:
print "Series doesn't exist (if you are not, you should be running SaveAs)"
print("Series doesn't exist (if you are not, you should be running SaveAs)")

if is_new_series:

Expand Down
2 changes: 1 addition & 1 deletion odm2api/ODM1_1_1/services/export_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def export_series_data(self, series_id, filename, utc=False, site=False, var=Fal
return False

writer = csv.writer(open(filename, 'wb'))
print "filename: ", filename
print("filename: ", filename)
self.write_data_header(writer, utc, site, var, offset, qual, src, qcl)
for dv in series.data_values:
self.write_data_row(writer, series, dv, utc, site, var, offset, qual, src, qcl)
Expand Down
2 changes: 1 addition & 1 deletion odm2api/ODM1_1_1/services/series_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def get_series_by_id(self, series_id):
try:
return self._session.query(ODM.Series).filter_by(id=series_id).first()
except Exception as e:
print e
print(e)
return None

def get_series_by_id_quint(self, site_id, var_id, method_id, source_id, qcl_id):
Expand Down
6 changes: 3 additions & 3 deletions odm2api/ODM2/services/createService.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def createAffiliation(self, personid, organizationid, email, phone=None, address
#self._session.flush()
# self._session.refresh(a)

print a.OrganizationID
print(a.OrganizationID)

return a

Expand Down Expand Up @@ -523,8 +523,8 @@ def createTimeSeriesResultValues(self, datavalues):


return datavalues
except Exception, e:
print e
except Exception as e:
print(e)
return None


Expand Down
30 changes: 15 additions & 15 deletions odm2api/ODM2/services/readService.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ def getProcessingLevelByCode(self, processingCode):
"""
try:
return self._session.query(ProcessingLevels).filter_by(ProcessingLevelCode=str(processingCode)).first()
except Exception, e:
print e
except Exception as e:
print(e)
return None

"""
Expand Down Expand Up @@ -387,7 +387,7 @@ def getSamplingFeaturesByType(self, samplingFeatureTypeCV):
try:
return self._session.query(SamplingFeatures).filter_by(SamplingFeatureTypeCV=samplingFeatureTypeCV).all()
except Exception as e:
print e
print(e)
return None

def getSamplingFeatureByGeometry(self, wkt_geometry):
Expand All @@ -396,17 +396,17 @@ def getSamplingFeatureByGeometry(self, wkt_geometry):
# ST_Equals(geometry, geometry)
return self._session.query(SamplingFeatures).filter(
func.ST_AsText(SamplingFeatures.FeatureGeometry) == func.ST_AsText(wkt_geometry)).first()
except Exception, e:
print e
except Exception as e:
print(e)
return None

def getGeometryTest(self, TestGeom):
Geom = self._session.query(SamplingFeatures).first()
print "Queried Geometry: ", self._session.query(Geom.FeatureGeometry.ST_AsText()).first()
print("Queried Geometry: ", self._session.query(Geom.FeatureGeometry.ST_AsText()).first())
GeomText = self._session.query(
func.ST_Union(Geom.FeatureGeometry, func.ST_GeomFromText(TestGeom)).ST_AsText()).first()

print GeomText
print(GeomText)

"""
Action
Expand Down Expand Up @@ -773,13 +773,13 @@ def getTimeSeriesResultValuesByResultId(self, resultId):
"""
try:
q = self._session.query(TimeSeriesResultValues).filter_by(ResultID=resultId).all()
print type(q[0]), q[0]
print(type(q[0]), q[0])
df = pd.DataFrame([dv.list_repr() for dv in q])
df.columns = q[0].get_columns()
return df
# return self._session.query(Timeseriesresultvalue).filter_by(ResultID=resultId).all()
except Exception as e:
print e
print(e)
return None

def getTimeSeriesResultValuesByCode(self, timeSeriesCode):
Expand Down Expand Up @@ -945,8 +945,8 @@ def getRelatedModelsByID(self, modelid):
"""
try:
return self._session.query(RelatedModels).filter_by(RelatedModelID=modelid).all()
except Exception, e:
print e
except Exception as e:
print(e)
return None

def getRelatedModelsByCode(self, modelcode):
Expand All @@ -958,8 +958,8 @@ def getRelatedModelsByCode(self, modelcode):
try:
return self._session.query(RelatedModels).join(Models, RelatedModels.RelatedModelID == Models.ModelID) \
.filter(Models.ModelCode == modelcode).all()
except Exception, e:
print e
except Exception as e:
print(e)
return None

def getResultsBySimulationID(self, simulationID):
Expand All @@ -969,8 +969,8 @@ def getResultsBySimulationID(self, simulationID):
.join(Actions) \
.join(Simulations) \
.filter(Simulations.SimulationID == simulationID).all()
except Exception, e:
print e
except Exception as e:
print(e)
return None

# ################################################################################
Expand Down
4 changes: 2 additions & 2 deletions odm2api/ODMconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def testEngine(self, connection_string, echo = False ):
s.test_Session().query(Variable2.VariableCode).limit(1).first()

except Exception as e:
print "Connection was unsuccessful ", e.message
print("Connection was unsuccessful ", e.message)
return False
return True

Expand All @@ -131,7 +131,7 @@ def testEngine1_1(self, connection_string, echo = False ):
s.test_Session().query(ODM.Variable.code).limit(1).first()

except Exception as e:
print "Connection was unsuccessful ", e.message
print("Connection was unsuccessful ", e.message)
return False
return True

Expand Down