|
23 | 23 | #createconnection (dbtype, servername, dbname, username, password) |
24 | 24 | #session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm') |
25 | 25 | #session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0) |
26 | | -session_factory = dbconnection.createConnection('sqlite', '/Users/denversmith/Downloads/ODM2.sqlite', 2.0) |
| 26 | +#session_factory = dbconnection.createConnection('sqlite', '/Users/denversmith/Downloads/ODM2.sqlite', 2.0) |
| 27 | +session_factory = dbconnection.createConnection('postgresql', '50.19.46.248:5432', db='postgres',user='postgres',password='RomaeDintorni!m0nel') |
27 | 28 | # session_factory= dbconnection.createConnection('mssql') |
28 | 29 |
|
29 | 30 |
|
|
40 | 41 | allVars = read.getVariables() |
41 | 42 |
|
42 | 43 | for x in allVars: |
43 | | - print x.VariableCode + ": " + x.VariableNameCV |
| 44 | + print(x.VariableCode + ": " + x.VariableNameCV) |
44 | 45 |
|
45 | 46 |
|
46 | 47 |
|
47 | 48 | # Get all of the people from the database |
48 | 49 | allPeople = read.getPeople() |
49 | 50 |
|
50 | 51 | for x in allPeople: |
51 | | - print x.PersonFirstName + " " + x.PersonLastName |
| 52 | + print(x.PersonFirstName + " " + x.PersonLastName) |
52 | 53 |
|
53 | 54 | try: |
54 | | - print "\n-------- Information about an Affiliation ---------" |
| 55 | + print("\n-------- Information about an Affiliation ---------") |
55 | 56 | allaff = read.getAllAffiliations() |
56 | 57 | for x in allaff: |
57 | | - print x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID) |
| 58 | + print(x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID)) |
58 | 59 | except Exception as e: |
59 | | - print "Unable to demo getAllAffiliations", e |
| 60 | + print("Unable to demo getAllAffiliations", e) |
60 | 61 |
|
61 | 62 | # Get all of the SamplingFeatures from the database that are Sites |
62 | 63 | try: |
63 | 64 | siteFeatures = read.getSamplingFeaturesByType('Site') |
64 | 65 | numSites = len(siteFeatures) |
65 | 66 |
|
66 | 67 | for x in siteFeatures: |
67 | | - print x.SamplingFeatureCode + ": " + x.SamplingFeatureName |
| 68 | + print(x.SamplingFeatureCode + ": " + x.SamplingFeatureName) |
68 | 69 | except Exception as e: |
69 | | - print "Unable to demo getSamplingFeaturesByType", e |
| 70 | + print("Unable to demo getSamplingFeaturesByType", e) |
70 | 71 |
|
71 | 72 |
|
72 | 73 | # Now get the SamplingFeature object for a SamplingFeature code |
73 | 74 | try: |
74 | 75 | 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) |
| 76 | + print(sf) |
| 77 | + print("\n-------- Information about an individual SamplingFeature ---------") |
| 78 | + print("The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n") |
| 79 | + print("SamplingFeatureCode: " + sf.SamplingFeatureCode) |
| 80 | + print("SamplingFeatureName: " + sf.SamplingFeatureName) |
| 81 | + print("SamplingFeatureDescription: %s" % sf.SamplingFeatureDescription) |
| 82 | + print("SamplingFeatureGeotypeCV: %s" % sf.SamplingFeatureGeotypeCV) |
| 83 | + print("SamplingFeatureGeometry: %s" % sf.FeatureGeometry) |
| 84 | + print("Elevation_m: %s" % str(sf.Elevation_m)) |
84 | 85 | except Exception as e: |
85 | | - print "Unable to demo getSamplingFeatureByCode: ", e |
| 86 | + print("Unable to demo getSamplingFeatureByCode: ", e) |
86 | 87 |
|
87 | 88 | #add sampling feature |
88 | | -print "\n------------ Create Sampling Feature --------- \n", |
| 89 | +print("\n------------ Create Sampling Feature --------- \n") |
89 | 90 | try: |
90 | 91 | from odm2api.ODM2.models import SamplingFeatures |
91 | 92 | newsf = SamplingFeatures() |
|
100 | 101 | newsf.SamplingFeatureUUID= sf.SamplingFeatureUUID+"2" |
101 | 102 | session.add(newsf) |
102 | 103 | #session.commit() |
103 | | - print "new sampling feature added to database", newsf |
| 104 | + print("new sampling feature added to database", newsf) |
104 | 105 |
|
105 | 106 | except Exception as e : |
106 | | - print "error adding a sampling feature: " + str(e) |
| 107 | + print("error adding a sampling feature: " + str(e)) |
107 | 108 |
|
108 | 109 |
|
109 | 110 | # Drill down and get objects linked by foreign keys |
110 | | -print "\n------------ Foreign Key Example --------- \n", |
| 111 | +print("\n------------ Foreign Key Example --------- \n",) |
111 | 112 | try: |
112 | 113 | # Call getResults, but return only the first result |
113 | 114 | 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 |
| 115 | + print("The FeatureAction object for the Result is: ", firstResult.FeatureActionObj) |
| 116 | + print("The Action object for the Result is: ", firstResult.FeatureActionObj.ActionObj) |
116 | 117 | print ("\nThe following are some of the attributes for the Action that created the Result: \n" + |
117 | 118 | "ActionTypeCV: " + firstResult.FeatureActionObj.ActionObj.ActionTypeCV + "\n" + |
118 | 119 | "ActionDescription: " + firstResult.FeatureActionObj.ActionObj.ActionDescription + "\n" + |
|
121 | 122 | "MethodName: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodName + "\n" + |
122 | 123 | "MethodDescription: " + firstResult.FeatureActionObj.ActionObj.MethodObj.MethodDescription) |
123 | 124 | except Exception as e: |
124 | | - print "Unable to demo Foreign Key Example: ", e |
| 125 | + print("Unable to demo Foreign Key Example: ", e) |
125 | 126 |
|
126 | 127 |
|
127 | 128 | # Now get a particular Result using a ResultID |
128 | | -print "\n------- Example of Retrieving Attributes of a Time Series Result -------" |
| 129 | +print("\n------- Example of Retrieving Attributes of a Time Series Result -------") |
129 | 130 | try: |
130 | 131 | tsResult = read.getTimeSeriesResultByResultId(1) |
131 | 132 | print ( |
|
142 | 143 | "SamplingFeature: " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " + |
143 | 144 | tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName) |
144 | 145 | except Exception as e: |
145 | | - print "Unable to demo Example of retrieving Attributes of a time Series Result: ", e |
| 146 | + print("Unable to demo Example of retrieving Attributes of a time Series Result: ", e) |
146 | 147 |
|
147 | 148 | # Get the values for a particular TimeSeriesResult |
148 | | -print "\n-------- Example of Retrieving Time Series Result Values ---------" |
| 149 | +print("\n-------- Example of Retrieving Time Series Result Values ---------") |
149 | 150 |
|
150 | 151 | tsValues = read.getTimeSeriesResultValuesByResultId(1) # Return type is a pandas dataframe |
151 | 152 |
|
152 | 153 | # Print a few Time Series Values to the console |
153 | 154 | # tsValues.set_index('ValueDateTime', inplace=True) |
154 | 155 | try: |
155 | | - print tsValues.head() |
| 156 | + print(tsValues.head()) |
156 | 157 | except Exception as e: |
157 | | - print e |
| 158 | + print(e) |
158 | 159 |
|
159 | 160 | # Plot the time series |
160 | 161 |
|
|
173 | 174 | ax.grid(True) |
174 | 175 | plt.show() |
175 | 176 | except Exception as e: |
176 | | - print "Unable to demo plotting of tsValues: ", e |
| 177 | + print("Unable to demo plotting of tsValues: ", e) |
0 commit comments