|
13 | 13 | # print directory |
14 | 14 | # sys.path.insert(0, directory) |
15 | 15 |
|
16 | | -from api.ODMconnection import dbconnection |
17 | | -from api.ODM2.services.readService import * |
| 16 | +from odm2api.ODMconnection import dbconnection |
| 17 | +from odm2api.ODM2.services.readService import * |
18 | 18 | # Create a connection to the ODM2 database |
19 | 19 | # ---------------------------------------- |
20 | 20 |
|
21 | 21 |
|
22 | 22 | #connect to database |
23 | 23 | #createconnection (dbtype, servername, dbname, username, password) |
24 | 24 | #session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm') |
25 | | -session_factory = dbconnection.createConnection('sqlite', '/Users/stephanie/DEV/DBs/ODM2.sqlite', 2.0) |
| 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 | 27 | # session_factory= dbconnection.createConnection('mssql') |
27 | 28 |
|
28 | 29 |
|
|
68 | 69 | print "Unable to demo getSamplingFeaturesByType", e |
69 | 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 |
75 | 76 | print "\n-------- Information about an individual SamplingFeature ---------" |
76 | | - print ( |
77 | | - "The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n" + |
78 | | - "SamplingFeatureCode: " + sf.SamplingFeatureCode + "\n" + |
79 | | - "SamplingFeatureName: " + sf.SamplingFeatureName + "\n" + |
80 | | - "SamplingFeatureDescription: " + sf.SamplingFeatureDescription + "\n" + |
81 | | - "SamplingFeatureGeotypeCV: " + sf.SamplingFeatureGeotypeCV + "\n" + |
82 | | - "SamplingFeatureGeometry: " + sf.FeatureGeometry + "\n" + |
83 | | - "Elevation_m: " + str(sf.Elevation_m)) |
| 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 | 85 | print "Unable to demo getSamplingFeatureByCode: ", e |
86 | 86 |
|
87 | 87 | #add sampling feature |
88 | 88 | print "\n------------ Create Sampling Feature --------- \n", |
89 | 89 | try: |
90 | | - from api.ODM2.models import SamplingFeatures |
| 90 | + from odm2api.ODM2.models import SamplingFeatures |
91 | 91 | newsf = SamplingFeatures() |
92 | 92 | session = session_factory.getSession() |
93 | 93 | newsf.FeatureGeometry = "POINT(-111.946 41.718)" |
|
127 | 127 | # Now get a particular Result using a ResultID |
128 | 128 | print "\n------- Example of Retrieving Attributes of a Time Series Result -------" |
129 | 129 | try: |
130 | | - tsResult = read.getTimeSeriesResultByResultId(19) |
| 130 | + tsResult = read.getTimeSeriesResultByResultId(1) |
131 | 131 | print ( |
132 | 132 | "The following are some of the attributes for the TimeSeriesResult retrieved using getTimeSeriesResultByResultID(): \n" + |
133 | | - "ResultTypeCV: " + tsResult.ResultTypeCV + "\n" + |
| 133 | + "ResultTypeCV: " + tsResult.ResultObj.ResultTypeCV + "\n" + |
134 | 134 | # Get the ProcessingLevel from the TimeSeriesResult's ProcessingLevel object |
135 | | - "ProcessingLevel: " + tsResult.ProcessingLevelObj.Definition + "\n" + |
136 | | - "SampledMedium: " + tsResult.SampledMediumCV + "\n" + |
| 135 | + "ProcessingLevel: " + tsResult.ResultObj.ProcessingLevelObj.Definition + "\n" + |
| 136 | + "SampledMedium: " + tsResult.ResultObj.SampledMediumCV + "\n" + |
137 | 137 | # Get the variable information from the TimeSeriesResult's Variable object |
138 | | - "Variable: " + tsResult.VariableObj.VariableCode + ": " + tsResult.VariableObj.VariableNameCV + "\n" |
| 138 | + "Variable: " + tsResult.ResultObj.VariableObj.VariableCode + ": " + tsResult.ResultObj.VariableObj.VariableNameCV + "\n" |
139 | 139 | "AggregationStatistic: " + tsResult.AggregationStatisticCV + "\n" + |
140 | 140 | "Elevation_m: " + str(sf.Elevation_m) + "\n" + |
141 | 141 | # Get the site information by drilling down |
142 | | - "SamplingFeature: " + tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " + |
143 | | - tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName) |
| 142 | + "SamplingFeature: " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " + |
| 143 | + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName) |
144 | 144 | except Exception as e: |
145 | 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 | 148 | print "\n-------- Example of Retrieving Time Series Result Values ---------" |
149 | 149 |
|
150 | | -tsValues = read.getTimeSeriesResultValuesByResultId(19) # Return type is a pandas dataframe |
| 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) |
|
162 | 162 | fig = plt.figure() |
163 | 163 | ax = fig.add_subplot(111) |
164 | 164 | tsValues.plot(x='ValueDateTime', y='DataValue', kind='line', |
165 | | - title=tsResult.VariableObj.VariableNameCV + " at " + tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName, |
| 165 | + title=tsResult.ResultObj.VariableObj.VariableNameCV + " at " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName, |
166 | 166 | ax=ax) |
167 | | - ax.set_ylabel(tsResult.VariableObj.VariableNameCV + " (" + tsResult.UnitObj.UnitsAbbreviation + ")") |
| 167 | + ax.set_ylabel(tsResult.ResultObj.VariableObj.VariableNameCV + " (" + tsResult.ResultObj.UnitsObj.UnitsAbbreviation + ")") |
168 | 168 | ax.set_xlabel("Date/Time") |
169 | 169 | ax.xaxis.set_minor_locator(dates.MonthLocator()) |
170 | 170 | ax.xaxis.set_minor_formatter(dates.DateFormatter('%b')) |
|
0 commit comments