Skip to content

Commit 8ef2822

Browse files
author
Stephanie Reeder
committed
merging changes from master
2 parents 5d32e11 + 9ed1c1c commit 8ef2822

18 files changed

+1903
-56
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ sudo: required
55
python:
66
# - "2.6"
77
- "2.7"
8-
# - "3.2"
9-
# - "3.3"
10-
# - "3.4"
8+
- "3.2"
9+
- "3.3"
10+
- "3.4"
1111
# - "3.5"
1212
# - "3.5-dev" # 3.5 development branch
1313
# - "nightly" # currently points to 3.6-dev
@@ -46,13 +46,13 @@ before_install:
4646
# python -m pip makes the install go into the virtualenv
4747
- python -m pip install pandas
4848
- export PYMSSQL_BUILD_WITH_BUNDLED_FREETDS=1;python -m pip install pymssql
49-
- python -m pip install mysql-python
49+
# - python -m pip install mysql-python
5050
install: # now just our code
5151
- pip install git+https://github.com/ODM2/geoalchemy.git@odm2#egg=geoalchemy-0.7.3
5252
- pip install .
5353
- pip install -r requirements_tests.txt --allow-external pyodbc --allow-unverified pyodbc
5454
# pysqlite
55-
- pip install pysqlite
55+
# - pip install pysqlite
5656
- pip list
5757

5858
# don't forget to open up the azure mssql server to these addreses

Examples/Sample.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@
3535
allVars = read.getVariables()
3636
print "\n-------- Information about Variables ---------"
3737
for x in allVars:
38-
print x.VariableCode + ": " + x.VariableNameCV
38+
print(x.VariableCode + ": " + x.VariableNameCV)
3939

4040

4141

4242
# Get all of the people from the database
4343
allPeople = read.getPeople()
4444
print "\n-------- Information about People ---------"
4545
for x in allPeople:
46-
print x.PersonFirstName + " " + x.PersonLastName
46+
print(x.PersonFirstName + " " + x.PersonLastName)
4747

4848
try:
49-
print "\n-------- Information about an Affiliation ---------"
49+
print("\n-------- Information about an Affiliation ---------")
5050
allaff = read.getAffiliations()
5151
for x in allaff:
52-
print x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID)
52+
print(x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID))
5353
except Exception as e:
54-
print "Unable to demo getAllAffiliations", e
54+
print("Unable to demo getAllAffiliations", e)
5555

5656
# Get all of the SamplingFeatures from the database that are Sites
5757
try:
@@ -60,27 +60,28 @@
6060
numSites = len(siteFeatures)
6161

6262
for x in siteFeatures:
63-
print x.SamplingFeatureCode + ": " + str(x.SamplingFeatureName) + ", " + x.SamplingFeatureTypeCV
63+
print(x.SamplingFeatureCode + ": " + x.SamplingFeatureName)
6464
except Exception as e:
65-
print "Unable to demo getSamplingFeaturesByType", e
65+
print("Unable to demo getSamplingFeaturesByType", e)
6666

6767

6868
# Now get the SamplingFeature object for a SamplingFeature code
6969
try:
7070
sf = read.getSamplingFeatures(code=['USU-LBR-Mendon'])[0]
71-
print "\n-------- Information about an individual SamplingFeature ---------"
72-
print "The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeature(code = x): \n"
73-
print "SamplingFeatureCode: " + sf.SamplingFeatureCode
74-
print "SamplingFeatureName: " + sf.SamplingFeatureName
75-
print "SamplingFeatureDescription: %s" % sf.SamplingFeatureDescription
76-
print "SamplingFeatureGeotypeCV: %s" % sf.SamplingFeatureGeotypeCV
77-
print "SamplingFeatureGeometry: %s" % sf.FeatureGeometryWKT
78-
print "Elevation_m: %s" % str(sf.Elevation_m)
71+
print(sf)
72+
print("\n-------- Information about an individual SamplingFeature ---------")
73+
print("The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n")
74+
print("SamplingFeatureCode: " + sf.SamplingFeatureCode)
75+
print("SamplingFeatureName: " + sf.SamplingFeatureName)
76+
print("SamplingFeatureDescription: %s" % sf.SamplingFeatureDescription)
77+
print("SamplingFeatureGeotypeCV: %s" % sf.SamplingFeatureGeotypeCV)
78+
print("SamplingFeatureGeometry: %s" % sf.FeatureGeometry)
79+
print("Elevation_m: %s" % str(sf.Elevation_m))
7980
except Exception as e:
80-
print "Unable to demo getSamplingFeatureByCode: ", e
81+
print("Unable to demo getSamplingFeatureByCode: ", e)
8182

8283
#add sampling feature
83-
print "\n------------ Create Sampling Feature --------- \n",
84+
print("\n------------ Create Sampling Feature --------- \n")
8485
try:
8586
# from odm2api.ODM2.models import SamplingFeatures
8687
session = session_factory.getSession()
@@ -91,19 +92,19 @@
9192

9293
create.createSamplingFeature(newsf)
9394
#session.commit()
94-
print "new sampling feature added to database", newsf
95+
print("new sampling feature added to database", newsf)
9596

9697
except Exception as e :
97-
print "error adding a sampling feature: " + str(e)
98+
print("error adding a sampling feature: " + str(e))
9899

99100

100101
# Drill down and get objects linked by foreign keys
101-
print "\n------------ Foreign Key Example --------- \n",
102+
print("\n------------ Foreign Key Example --------- \n",)
102103
try:
103104
# Call getResults, but return only the first result
104105
firstResult = read.getResults()[0]
105-
print "The FeatureAction object for the Result is: ", firstResult.FeatureActionObj
106-
print "The Action object for the Result is: ", firstResult.FeatureActionObj.ActionObj
106+
print("The FeatureAction object for the Result is: ", firstResult.FeatureActionObj)
107+
print("The Action object for the Result is: ", firstResult.FeatureActionObj.ActionObj)
107108
print ("\nThe following are some of the attributes for the Action that created the Result: \n" +
108109
"ActionTypeCV: " + firstResult.FeatureActionObj.ActionObj.ActionTypeCV + "\n" +
109110
"ActionDescription: " + firstResult.FeatureActionObj.ActionObj.ActionDescription + "\n" +
@@ -112,11 +113,11 @@
112113
"MethodName: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodName + "\n" +
113114
"MethodDescription: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodDescription)
114115
except Exception as e:
115-
print "Unable to demo Foreign Key Example: ", e
116+
print("Unable to demo Foreign Key Example: ", e)
116117

117118

118119
# Now get a particular Result using a ResultID
119-
print "\n------- Example of Retrieving Attributes of a Time Series Result -------"
120+
print("\n------- Example of Retrieving Attributes of a Time Series Result -------")
120121
try:
121122
tsResult = read.getResults(ids = [1])[0]
122123
print (
@@ -133,20 +134,19 @@
133134
"SamplingFeature: " + tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
134135
tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
135136
except Exception as e:
136-
print "Unable to demo Example of retrieving Attributes of a time Series Result: ", e
137+
print("Unable to demo Example of retrieving Attributes of a time Series Result: ", e)
137138

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

141142
tsValues = read.getResultValues(resultid = 1) # Return type is a pandas datafram
142143

143144
# Print a few Time Series Values to the console
144145
# tsValues.set_index('ValueDateTime', inplace=True)
145146
try:
146-
print "tsValues "
147-
print tsValues.head()
147+
print(tsValues.head())
148148
except Exception as e:
149-
print e
149+
print(e)
150150

151151
# Plot the time series
152152

@@ -156,4 +156,4 @@
156156

157157
plt.show()
158158
except Exception as e:
159-
print "Unable to demo plotting of tsValues: ", e
159+
print("Unable to demo plotting of tsValues: ", e)

Examples/Sample.py.orig

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
__author__ = 'stephanie'
2+
3+
4+
5+
import matplotlib.pyplot as plt
6+
from matplotlib import dates
7+
8+
9+
10+
from odm2api.ODMconnection import dbconnection
11+
from odm2api.ODM2.services.readService import *
12+
from odm2api.ODM2.services import CreateODM2
13+
# Create a connection to the ODM2 database
14+
# ----------------------------------------
15+
16+
17+
#connect to database
18+
# createconnection (dbtype, servername, dbname, username, password)
19+
# session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)#sqlite
20+
# session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')#mysql
21+
# session_factory= dbconnection.createConnection('mssql', "(local)", "LBRODM2", "ODM", "odm")#win MSSQL
22+
session_factory= dbconnection.createConnection('mssql', "arroyoodm2", "", "ODM", "odm")#mac/linux MSSQL
23+
24+
25+
26+
#_session = session_factory.getSession()
27+
read = ReadODM2(session_factory)
28+
create =CreateODM2(session_factory)
29+
30+
31+
32+
# Run some basic sample queries.
33+
# ------------------------------
34+
# Get all of the variables from the database and print their names to the console
35+
allVars = read.getVariables()
36+
print "\n-------- Information about Variables ---------"
37+
for x in allVars:
38+
print(x.VariableCode + ": " + x.VariableNameCV)
39+
40+
41+
42+
# Get all of the people from the database
43+
allPeople = read.getPeople()
44+
print "\n-------- Information about People ---------"
45+
for x in allPeople:
46+
print(x.PersonFirstName + " " + x.PersonLastName)
47+
48+
try:
49+
50+
print "\n-------- Information about an Affiliation ---------"
51+
allaff = read.getAffiliations()
52+
53+
for x in allaff:
54+
print(x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID))
55+
except Exception as e:
56+
print("Unable to demo getAllAffiliations", e)
57+
58+
# Get all of the SamplingFeatures from the database that are Sites
59+
try:
60+
print "\n-------- Information about Sites ---------"
61+
siteFeatures = read.getSamplingFeatures(type='Site')
62+
numSites = len(siteFeatures)
63+
64+
for x in siteFeatures:
65+
66+
print x.SamplingFeatureCode + ": " + str(x.SamplingFeatureName) + ", " + x.SamplingFeatureTypeCV
67+
68+
except Exception as e:
69+
print("Unable to demo getSamplingFeaturesByType", e)
70+
71+
72+
# Now get the SamplingFeature object for a SamplingFeature code
73+
try:
74+
75+
sf = read.getSamplingFeatures(code=['USU-LBR-Mendon'])[0]
76+
print "\n-------- Information about an individual SamplingFeature ---------"
77+
print "The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeature(code = x): \n"
78+
print "SamplingFeatureCode: " + sf.SamplingFeatureCode
79+
print "SamplingFeatureName: " + sf.SamplingFeatureName
80+
print "SamplingFeatureDescription: %s" % sf.SamplingFeatureDescription
81+
print "SamplingFeatureGeotypeCV: %s" % sf.SamplingFeatureGeotypeCV
82+
print "SamplingFeatureGeometry: %s" % sf.FeatureGeometryWKT
83+
print "Elevation_m: %s" % str(sf.Elevation_m)
84+
85+
except Exception as e:
86+
print("Unable to demo getSamplingFeatureByCode: ", e)
87+
88+
#add sampling feature
89+
print("\n------------ Create Sampling Feature --------- \n")
90+
try:
91+
# from odm2api.ODM2.models import SamplingFeatures
92+
session = session_factory.getSession()
93+
newsf = Sites(FeatureGeometryWKT = "POINT(-111.946 41.718)", Elevation_m=100, ElevationDatumCV=sf.ElevationDatumCV,
94+
SamplingFeatureCode= "TestSF",SamplingFeatureDescription = "this is a test to add Feature Geomotry",
95+
SamplingFeatureGeotypeCV= "Point", SamplingFeatureTypeCV=sf.SamplingFeatureTypeCV,SamplingFeatureUUID= sf.SamplingFeatureUUID+"2",
96+
SiteTypeCV="cave", Latitude= "100", Longitude= "-100", SpatialReferenceID= 0)
97+
98+
create.createSamplingFeature(newsf)
99+
#session.commit()
100+
print("new sampling feature added to database", newsf)
101+
102+
except Exception as e :
103+
print("error adding a sampling feature: " + str(e))
104+
105+
106+
# Drill down and get objects linked by foreign keys
107+
print("\n------------ Foreign Key Example --------- \n",)
108+
try:
109+
# Call getResults, but return only the first result
110+
firstResult = read.getResults()[0]
111+
print("The FeatureAction object for the Result is: ", firstResult.FeatureActionObj)
112+
print("The Action object for the Result is: ", firstResult.FeatureActionObj.ActionObj)
113+
print ("\nThe following are some of the attributes for the Action that created the Result: \n" +
114+
"ActionTypeCV: " + firstResult.FeatureActionObj.ActionObj.ActionTypeCV + "\n" +
115+
"ActionDescription: " + firstResult.FeatureActionObj.ActionObj.ActionDescription + "\n" +
116+
"BeginDateTime: " + str(firstResult.FeatureActionObj.ActionObj.BeginDateTime) + "\n" +
117+
"EndDateTime: " + str(firstResult.FeatureActionObj.ActionObj.EndDateTime) + "\n" +
118+
"MethodName: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodName + "\n" +
119+
"MethodDescription: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodDescription)
120+
except Exception as e:
121+
print("Unable to demo Foreign Key Example: ", e)
122+
123+
124+
# Now get a particular Result using a ResultID
125+
print("\n------- Example of Retrieving Attributes of a Time Series Result -------")
126+
try:
127+
tsResult = read.getResults(ids = [1])[0]
128+
print (
129+
"The following are some of the attributes for the TimeSeriesResult retrieved using getTimeSeriesResultByResultID(): \n" +
130+
"ResultTypeCV: " + tsResult.ResultTypeCV + "\n" +
131+
# Get the ProcessingLevel from the TimeSeriesResult's ProcessingLevel object
132+
"ProcessingLevel: " + tsResult.ProcessingLevelObj.Definition + "\n" +
133+
"SampledMedium: " + tsResult.SampledMediumCV + "\n" +
134+
# Get the variable information from the TimeSeriesResult's Variable object
135+
"Variable: " + tsResult.VariableObj.VariableCode + ": " + tsResult.VariableObj.VariableNameCV + "\n"
136+
"AggregationStatistic: " + tsResult.AggregationStatisticCV + "\n" +
137+
"Elevation_m: " + str(sf.Elevation_m) + "\n" +
138+
# Get the site information by drilling down
139+
"SamplingFeature: " + tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
140+
tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
141+
except Exception as e:
142+
print("Unable to demo Example of retrieving Attributes of a time Series Result: ", e)
143+
144+
# Get the values for a particular TimeSeriesResult
145+
print("\n-------- Example of Retrieving Time Series Result Values ---------")
146+
147+
tsValues = read.getResultValues(resultid = 1) # Return type is a pandas datafram
148+
149+
# Print a few Time Series Values to the console
150+
# tsValues.set_index('ValueDateTime', inplace=True)
151+
try:
152+
print(tsValues.head())
153+
154+
except Exception as e:
155+
print(e)
156+
157+
# Plot the time series
158+
159+
try:
160+
plt.figure()
161+
ax=tsValues.plot(x='ValueDateTime', y='DataValue')
162+
163+
plt.show()
164+
except Exception as e:
165+
print("Unable to demo plotting of tsValues: ", e)

odm2api/ODM1_1_1/services/edit_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def updateSeries(self, var=None, method=None, qcl=None, is_new_series=False):
457457
print("Save existing series ID: %s" % str(series.id))
458458
series = tseries
459459
else:
460-
print "Series doesn't exist (if you are not, you should be running SaveAs)"
460+
print("Series doesn't exist (if you are not, you should be running SaveAs)")
461461

462462
if is_new_series:
463463

odm2api/ODM1_1_1/services/export_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def export_series_data(self, series_id, filename, utc=False, site=False, var=Fal
1919
return False
2020

2121
writer = csv.writer(open(filename, 'wb'))
22-
print "filename: ", filename
22+
print("filename: ", filename)
2323
self.write_data_header(writer, utc, site, var, offset, qual, src, qcl)
2424
for dv in series.data_values:
2525
self.write_data_row(writer, series, dv, utc, site, var, offset, qual, src, qcl)

odm2api/ODM1_1_1/services/series_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def get_series_by_id(self, series_id):
286286
try:
287287
return self._session.query(ODM.Series).filter_by(id=series_id).first()
288288
except Exception as e:
289-
print e
289+
print(e)
290290
return None
291291

292292
def get_series_by_id_quint(self, site_id, var_id, method_id, source_id, qcl_id):

odm2api/ODM2/services/createService.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def createTimeSeriesResultValues(self, datavalues):
110110
self._session.commit()
111111

112112
return datavalues
113-
except Exception, e:
114-
print e
113+
except Exception as e:
114+
print(e)
115115
return None
116116

117117

0 commit comments

Comments
 (0)