|
40 | 40 | allVars = read.getVariables()
|
41 | 41 |
|
42 | 42 | for x in allVars:
|
43 |
| - print x.VariableCode + ": " + x.VariableNameCV |
| 43 | + print(x.VariableCode + ": " + x.VariableNameCV) |
44 | 44 |
|
45 | 45 |
|
46 | 46 |
|
47 | 47 | # Get all of the people from the database
|
48 | 48 | allPeople = read.getPeople()
|
49 | 49 |
|
50 | 50 | for x in allPeople:
|
51 |
| - print x.PersonFirstName + " " + x.PersonLastName |
| 51 | + print(x.PersonFirstName + " " + x.PersonLastName) |
52 | 52 |
|
53 | 53 | try:
|
54 |
| - print "\n-------- Information about an Affiliation ---------" |
| 54 | + print("\n-------- Information about an Affiliation ---------") |
55 | 55 | allaff = read.getAllAffiliations()
|
56 | 56 | for x in allaff:
|
57 |
| - print x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID) |
| 57 | + print(x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID)) |
58 | 58 | except Exception as e:
|
59 |
| - print "Unable to demo getAllAffiliations", e |
| 59 | + print("Unable to demo getAllAffiliations", e) |
60 | 60 |
|
61 | 61 | # Get all of the SamplingFeatures from the database that are Sites
|
62 | 62 | try:
|
63 | 63 | siteFeatures = read.getSamplingFeaturesByType('Site')
|
64 | 64 | numSites = len(siteFeatures)
|
65 | 65 |
|
66 | 66 | for x in siteFeatures:
|
67 |
| - print x.SamplingFeatureCode + ": " + x.SamplingFeatureName |
| 67 | + print(x.SamplingFeatureCode + ": " + x.SamplingFeatureName) |
68 | 68 | except Exception as e:
|
69 |
| - print "Unable to demo getSamplingFeaturesByType", e |
| 69 | + print("Unable to demo getSamplingFeaturesByType", e) |
70 | 70 |
|
71 | 71 |
|
72 | 72 | # Now get the SamplingFeature object for a SamplingFeature code
|
73 | 73 | try:
|
74 | 74 | 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)) |
84 | 84 | except Exception as e:
|
85 |
| - print "Unable to demo getSamplingFeatureByCode: ", e |
| 85 | + print("Unable to demo getSamplingFeatureByCode: ", e) |
86 | 86 |
|
87 | 87 | #add sampling feature
|
88 |
| -print "\n------------ Create Sampling Feature --------- \n", |
| 88 | +print("\n------------ Create Sampling Feature --------- \n") |
89 | 89 | try:
|
90 | 90 | from odm2api.ODM2.models import SamplingFeatures
|
91 | 91 | newsf = SamplingFeatures()
|
|
100 | 100 | newsf.SamplingFeatureUUID= sf.SamplingFeatureUUID+"2"
|
101 | 101 | session.add(newsf)
|
102 | 102 | #session.commit()
|
103 |
| - print "new sampling feature added to database", newsf |
| 103 | + print("new sampling feature added to database", newsf) |
104 | 104 |
|
105 | 105 | except Exception as e :
|
106 |
| - print "error adding a sampling feature: " + str(e) |
| 106 | + print("error adding a sampling feature: " + str(e)) |
107 | 107 |
|
108 | 108 |
|
109 | 109 | # Drill down and get objects linked by foreign keys
|
110 |
| -print "\n------------ Foreign Key Example --------- \n", |
| 110 | +print("\n------------ Foreign Key Example --------- \n",) |
111 | 111 | try:
|
112 | 112 | # Call getResults, but return only the first result
|
113 | 113 | 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) |
116 | 116 | print ("\nThe following are some of the attributes for the Action that created the Result: \n" +
|
117 | 117 | "ActionTypeCV: " + firstResult.FeatureActionObj.ActionObj.ActionTypeCV + "\n" +
|
118 | 118 | "ActionDescription: " + firstResult.FeatureActionObj.ActionObj.ActionDescription + "\n" +
|
|
121 | 121 | "MethodName: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodName + "\n" +
|
122 | 122 | "MethodDescription: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodDescription)
|
123 | 123 | except Exception as e:
|
124 |
| - print "Unable to demo Foreign Key Example: ", e |
| 124 | + print("Unable to demo Foreign Key Example: ", e) |
125 | 125 |
|
126 | 126 |
|
127 | 127 | # 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 -------") |
129 | 129 | try:
|
130 | 130 | tsResult = read.getTimeSeriesResultByResultId(1)
|
131 | 131 | print (
|
|
142 | 142 | "SamplingFeature: " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
|
143 | 143 | tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
|
144 | 144 | 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) |
146 | 146 |
|
147 | 147 | # 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 ---------") |
149 | 149 |
|
150 | 150 | tsValues = read.getTimeSeriesResultValuesByResultId(1) # Return type is a pandas dataframe
|
151 | 151 |
|
152 | 152 | # Print a few Time Series Values to the console
|
153 | 153 | # tsValues.set_index('ValueDateTime', inplace=True)
|
154 | 154 | try:
|
155 |
| - print tsValues.head() |
| 155 | + print(tsValues.head()) |
156 | 156 | except Exception as e:
|
157 |
| - print e |
| 157 | + print(e) |
158 | 158 |
|
159 | 159 | # Plot the time series
|
160 | 160 |
|
|
173 | 173 | ax.grid(True)
|
174 | 174 | plt.show()
|
175 | 175 | except Exception as e:
|
176 |
| - print "Unable to demo plotting of tsValues: ", e |
| 176 | + print("Unable to demo plotting of tsValues: ", e) |
0 commit comments