Skip to content

Commit 2321ab4

Browse files
committed
Merge branch 'master' into fixRelated
Conflicts: odm2api/ODM2/services/readService.py
2 parents 236c9bc + 4acec1f commit 2321ab4

15 files changed

+64
-67
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -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

+30-30
Original file line numberDiff line numberDiff line change
@@ -40,52 +40,52 @@
4040
allVars = read.getVariables()
4141

4242
for x in allVars:
43-
print x.VariableCode + ": " + x.VariableNameCV
43+
print(x.VariableCode + ": " + x.VariableNameCV)
4444

4545

4646

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

5050
for x in allPeople:
51-
print x.PersonFirstName + " " + x.PersonLastName
51+
print(x.PersonFirstName + " " + x.PersonLastName)
5252

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

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

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

7171

7272
# Now get the SamplingFeature object for a SamplingFeature code
7373
try:
7474
sf = read.getSamplingFeatureByCode('USU-LBR-Mendon')
75-
print sf
76-
print "\n-------- Information about an individual SamplingFeature ---------"
77-
print "The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \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.FeatureGeometry
83-
print "Elevation_m: %s" % str(sf.Elevation_m)
75+
print(sf)
76+
print("\n-------- Information about an individual SamplingFeature ---------")
77+
print("The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \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.FeatureGeometry)
83+
print("Elevation_m: %s" % str(sf.Elevation_m))
8484
except Exception as e:
85-
print "Unable to demo getSamplingFeatureByCode: ", e
85+
print("Unable to demo getSamplingFeatureByCode: ", e)
8686

8787
#add sampling feature
88-
print "\n------------ Create Sampling Feature --------- \n",
88+
print("\n------------ Create Sampling Feature --------- \n")
8989
try:
9090
from odm2api.ODM2.models import SamplingFeatures
9191
newsf = SamplingFeatures()
@@ -100,19 +100,19 @@
100100
newsf.SamplingFeatureUUID= sf.SamplingFeatureUUID+"2"
101101
session.add(newsf)
102102
#session.commit()
103-
print "new sampling feature added to database", newsf
103+
print("new sampling feature added to database", newsf)
104104

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

108108

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

126126

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

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

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

152152
# Print a few Time Series Values to the console
153153
# tsValues.set_index('ValueDateTime', inplace=True)
154154
try:
155-
print tsValues.head()
155+
print(tsValues.head())
156156
except Exception as e:
157-
print e
157+
print(e)
158158

159159
# Plot the time series
160160

@@ -173,4 +173,4 @@
173173
ax.grid(True)
174174
plt.show()
175175
except Exception as e:
176-
print "Unable to demo plotting of tsValues: ", e
176+
print("Unable to demo plotting of tsValues: ", e)

odm2api/ODM1_1_1/services/edit_service.py

+1-1
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

+1-1
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

+1-1
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def createAffiliation(self, personid, organizationid, email, phone=None, address
262262
#self._session.flush()
263263
# self._session.refresh(a)
264264

265-
print a.OrganizationID
265+
print(a.OrganizationID)
266266

267267
return a
268268

@@ -523,8 +523,8 @@ def createTimeSeriesResultValues(self, datavalues):
523523

524524

525525
return datavalues
526-
except Exception, e:
527-
print e
526+
except Exception as e:
527+
print(e)
528528
return None
529529

530530

odm2api/ODM2/services/readService.py

+15-19
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ def getProcessingLevelByCode(self, processingCode):
331331
"""
332332
try:
333333
return self._session.query(ProcessingLevels).filter_by(ProcessingLevelCode=str(processingCode)).first()
334-
except Exception, e:
335-
print e
334+
except Exception as e:
335+
print(e)
336336
return None
337337

338338
"""
@@ -387,7 +387,7 @@ def getSamplingFeaturesByType(self, samplingFeatureTypeCV):
387387
try:
388388
return self._session.query(SamplingFeatures).filter_by(SamplingFeatureTypeCV=samplingFeatureTypeCV).all()
389389
except Exception as e:
390-
print e
390+
print(e)
391391
return None
392392

393393
def getSamplingFeatureByGeometry(self, wkt_geometry):
@@ -396,17 +396,17 @@ def getSamplingFeatureByGeometry(self, wkt_geometry):
396396
# ST_Equals(geometry, geometry)
397397
return self._session.query(SamplingFeatures).filter(
398398
func.ST_AsText(SamplingFeatures.FeatureGeometry) == func.ST_AsText(wkt_geometry)).first()
399-
except Exception, e:
400-
print e
399+
except Exception as e:
400+
print(e)
401401
return None
402402

403403
def getGeometryTest(self, TestGeom):
404404
Geom = self._session.query(SamplingFeatures).first()
405-
print "Queried Geometry: ", self._session.query(Geom.FeatureGeometry.ST_AsText()).first()
405+
print("Queried Geometry: ", self._session.query(Geom.FeatureGeometry.ST_AsText()).first())
406406
GeomText = self._session.query(
407407
func.ST_Union(Geom.FeatureGeometry, func.ST_GeomFromText(TestGeom)).ST_AsText()).first()
408408

409-
print GeomText
409+
print(GeomText)
410410

411411
"""
412412
Action
@@ -773,13 +773,13 @@ def getTimeSeriesResultValuesByResultId(self, resultId):
773773
"""
774774
try:
775775
q = self._session.query(TimeSeriesResultValues).filter_by(ResultID=resultId).all()
776-
print type(q[0]), q[0]
776+
print(type(q[0]), q[0])
777777
df = pd.DataFrame([dv.list_repr() for dv in q])
778778
df.columns = q[0].get_columns()
779779
return df
780780
# return self._session.query(Timeseriesresultvalue).filter_by(ResultID=resultId).all()
781781
except Exception as e:
782-
print e
782+
print(e)
783783
return None
784784

785785
def getTimeSeriesResultValuesByCode(self, timeSeriesCode):
@@ -944,10 +944,8 @@ def getRelatedModelsByID(self, modelid):
944944
:return: all models related to the specified id
945945
"""
946946
try:
947-
# note this was RelatedModelID = modelid which would return all Parent models of RelatedModelID
948-
return self._session.query(RelatedModels).filter_by(ModelID=modelid).all()
949-
except Exception, e:
950-
print e
947+
except Exception as e:
948+
print(e)
951949
return None
952950

953951
def getRelatedModelsByCode(self, modelcode):
@@ -957,11 +955,9 @@ def getRelatedModelsByCode(self, modelcode):
957955
:return: all models related to the provided model code
958956
"""
959957
try:
960-
# note this was RelatedModels.RelatedModelID == Models.ModelID which would return all Parent models of RelatedModelID
961-
return self._session.query(RelatedModels).join(Models, RelatedModels.ModelID == Models.ModelID) \
962958
.filter(Models.ModelCode == modelcode).all()
963-
except Exception, e:
964-
print e
959+
except Exception as e:
960+
print(e)
965961
return None
966962

967963
def getResultsBySimulationID(self, simulationID):
@@ -971,8 +967,8 @@ def getResultsBySimulationID(self, simulationID):
971967
.join(Actions) \
972968
.join(Simulations) \
973969
.filter(Simulations.SimulationID == simulationID).all()
974-
except Exception, e:
975-
print e
970+
except Exception as e:
971+
print(e)
976972
return None
977973

978974
# ################################################################################

odm2api/ODMconnection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def testEngine(self, connection_string, echo = False ):
119119
s.test_Session().query(Variable2.VariableCode).limit(1).first()
120120

121121
except Exception as e:
122-
print "Connection was unsuccessful ", e.message
122+
print("Connection was unsuccessful ", e.message)
123123
return False
124124
return True
125125

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

133133
except Exception as e:
134-
print "Connection was unsuccessful ", e.message
134+
print("Connection was unsuccessful ", e.message)
135135
return False
136136
return True
137137

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pyodbc
22
six
33
sqlalchemy
4-
-e git+https://github.com/ODM2/geoalchemy.git@odm2#egg=geoalchemy-0.7.3
4+
-e git+https://github.com/ODM2/geoalchemy.git@v0.7.4#egg=geoalchemy-0.7.4
55
shapely
66
pandas
77
#psycopg2 # Commented out because I could not pip install it.

requirements_tests.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ pytest-cov
44
mock
55
#db support
66
pymysql
7-
pysqlite
7+
#pysqlite
8+
#sqlite
89
pymssql
910
psycopg2
1011
#pyspatialite
11-
mysql-python
12+
#mysql-python
1213

1314

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
# ],
9999
# dependency_links- geoalchemy from the ODM repository
100100
dependency_links=[
101-
"git+https://github.com/ODM2/[email protected].3#egg=geoalchemy-0.7.3"
101+
"git+https://github.com/ODM2/[email protected].4#egg=geoalchemy-0.7.4"
102102
],
103103

104104
# List additional groups of dependencies here (e.g. development

tests/test_SessionFactory.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
['mysql"root@Localhost/', 'mysql', 'mysql+pymysql://root@localhost/'],
1313
['mysql:ODM@Localhost/odm2', 'mysql', 'mysql+pymysql://ODM:odm@localhost/odm2'],
1414
['mysql"root@Localhost/odm2', 'mysql', 'mysql+pymysql://root@localhost/odm2'],
15-
[' mysql + mysqldb:', 'mysql', 'mysql+mysqldb://root@localhost/odm2'],
15+
# [' mysql + mysqldb:', 'mysql', 'mysql+mysqldb://root@localhost/odm2'],
1616
#'mysql+pymysql://ODM:[email protected]/odm2'
1717
['postgresql_marchantariats_none', 'postgresql', 'postgresql+psycopg2://postgres:None@localhost/marchantariats', 'marchantariats', 'postgres', None],
1818
['postgresql_marchantariats_empty', 'postgresql', 'postgresql+psycopg2://postgres@localhost/marchantariats', 'marchantariats', 'postgres', None],

tests/test_odm1/test_odmdata/test_memory_db_1_1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_get_data_values(self):
3131
def test_update_points(self):
3232
self.memory_db.update([{"value":15,"id":1}])
3333
dvs = self.memory_db.getDataValuesDF()
34-
print dvs["DataValue"]
34+
print ( dvs["DataValue"] )
3535
assert dvs["DataValue"][1-1] == 9
3636

3737
def test_update_value(self):

tests/test_odm2/test_createservice.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def build_db(self):
3232
for line in ddl.split(');')[:-1]:
3333
try:
3434
db.engine.execute(line + ');')
35-
except Exception, e:
35+
except Exception as e:
3636
print e
3737

3838
self.write = CreateODM2(db)

tests/test_odm2/test_readservice.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def build_db(self):
5858
for line in ddl.split(');')[:-1]:
5959
try:
6060
db.engine.execute(line + ');')
61-
except Exception, e:
61+
except Exception as e:
6262
print e
6363

6464
self.reader = ReadODM2(db)

0 commit comments

Comments
 (0)