|
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 |
|
|
73 | 74 | try: |
74 | 75 | sf = read.getSamplingFeatureByCode('USU-LBR-Mendon') |
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.geom_wkb |
| 83 | + print "Elevation_m: %s" % str(sf.Elevation_m) |
| 84 | + #print ( |
| 85 | + # "The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n" + |
| 86 | + # "SamplingFeatureCode: " + sf.SamplingFeatureCode + "\n" + |
| 87 | + # "SamplingFeatureName: " + sf.SamplingFeatureName + "\n" + |
| 88 | + # "SamplingFeatureDescription: " + sf.SamplingFeatureDescription + "\n" + |
| 89 | + # "SamplingFeatureGeotypeCV: " + sf.SamplingFeatureGeotypeCV + "\n" + |
| 90 | + # "SamplingFeatureGeometry: " + sf.FeatureGeometry.geom_wkb + "\n" + |
| 91 | + # "Elevation_m: " + str(sf.Elevation_m)) |
84 | 92 | except Exception as e: |
85 | 93 | print "Unable to demo getSamplingFeatureByCode: ", e |
86 | 94 |
|
|
127 | 135 | # Now get a particular Result using a ResultID |
128 | 136 | print "\n------- Example of Retrieving Attributes of a Time Series Result -------" |
129 | 137 | try: |
130 | | - tsResult = read.getTimeSeriesResultByResultId(19) |
| 138 | + tsResult = read.getTimeSeriesResultByResultId(1) |
131 | 139 | print ( |
132 | 140 | "The following are some of the attributes for the TimeSeriesResult retrieved using getTimeSeriesResultByResultID(): \n" + |
133 | | - "ResultTypeCV: " + tsResult.ResultTypeCV + "\n" + |
| 141 | + "ResultTypeCV: " + tsResult.ResultObj.ResultTypeCV + "\n" + |
134 | 142 | # Get the ProcessingLevel from the TimeSeriesResult's ProcessingLevel object |
135 | | - "ProcessingLevel: " + tsResult.ProcessingLevelObj.Definition + "\n" + |
136 | | - "SampledMedium: " + tsResult.SampledMediumCV + "\n" + |
| 143 | + "ProcessingLevel: " + tsResult.ResultObj.ProcessingLevelObj.Definition + "\n" + |
| 144 | + "SampledMedium: " + tsResult.ResultObj.SampledMediumCV + "\n" + |
137 | 145 | # Get the variable information from the TimeSeriesResult's Variable object |
138 | | - "Variable: " + tsResult.VariableObj.VariableCode + ": " + tsResult.VariableObj.VariableNameCV + "\n" |
| 146 | + "Variable: " + tsResult.ResultObj.VariableObj.VariableCode + ": " + tsResult.ResultObj.VariableObj.VariableNameCV + "\n" |
139 | 147 | "AggregationStatistic: " + tsResult.AggregationStatisticCV + "\n" + |
140 | 148 | "Elevation_m: " + str(sf.Elevation_m) + "\n" + |
141 | 149 | # Get the site information by drilling down |
142 | | - "SamplingFeature: " + tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " + |
143 | | - tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName) |
| 150 | + "SamplingFeature: " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " + |
| 151 | + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName) |
144 | 152 | except Exception as e: |
145 | 153 | print "Unable to demo Example of retrieving Attributes of a time Series Result: ", e |
146 | 154 |
|
147 | 155 | # Get the values for a particular TimeSeriesResult |
148 | 156 | print "\n-------- Example of Retrieving Time Series Result Values ---------" |
149 | 157 |
|
150 | | -tsValues = read.getTimeSeriesResultValuesByResultId(19) # Return type is a pandas dataframe |
| 158 | +tsValues = read.getTimeSeriesResultValuesByResultId(1) # Return type is a pandas dataframe |
151 | 159 |
|
152 | 160 | # Print a few Time Series Values to the console |
153 | 161 | # tsValues.set_index('ValueDateTime', inplace=True) |
|
162 | 170 | fig = plt.figure() |
163 | 171 | ax = fig.add_subplot(111) |
164 | 172 | tsValues.plot(x='ValueDateTime', y='DataValue', kind='line', |
165 | | - title=tsResult.VariableObj.VariableNameCV + " at " + tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName, |
| 173 | + title=tsResult.ResultObj.VariableObj.VariableNameCV + " at " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName, |
166 | 174 | ax=ax) |
167 | | - ax.set_ylabel(tsResult.VariableObj.VariableNameCV + " (" + tsResult.UnitObj.UnitsAbbreviation + ")") |
| 175 | + ax.set_ylabel(tsResult.ResultObj.VariableObj.VariableNameCV + " (" + tsResult.ResultObj.UnitsObj.UnitsAbbreviation + ")") |
168 | 176 | ax.set_xlabel("Date/Time") |
169 | 177 | ax.xaxis.set_minor_locator(dates.MonthLocator()) |
170 | 178 | ax.xaxis.set_minor_formatter(dates.DateFormatter('%b')) |
|
0 commit comments