-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
394 lines (304 loc) · 11.7 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# ===============================================================================
# Copyright 2021 ross
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================
"""
main.py. This module holds all the cloud function entry points.
"""
import os
from stao.constants import NO_DESCRIPTION, MANUAL_SENSOR, DTW_OBS_PROP, PRESSURE_SENSOR, ACOUSTIC_SENSOR, \
TOTALIZER_OBSERVED_PROPERTIES, TOTALIZER_SENSOR, HYDROVU_SENSOR
from stao.base_stao import SimpleSTAO
# try:
# from constants import NO_DESCRIPTION, MANUAL_SENSOR, DTW_OBS_PROP, PRESSURE_SENSOR, ACOUSTIC_SENSOR, \
# TOTALIZER_OBSERVED_PROPERTIES, TOTALIZER_SENSOR, HYDROVU_SENSOR
# from stao import SimpleSTAO
# except ImportError as e:
# print('imasdf', e)
# from stao.constants import NO_DESCRIPTION, MANUAL_SENSOR, DTW_OBS_PROP, PRESSURE_SENSOR, ACOUSTIC_SENSOR, \
# HYDROVU_SENSOR
# from stao.constants import NO_DESCRIPTION, MANUAL_SENSOR, DTW_OBS_PROP, PRESSURE_SENSOR, ACOUSTIC_SENSOR, \
# TOTALIZER_OBSERVED_PROPERTIES, TOTALIZER_SENSOR
# from stao.stao import SimpleSTAO
try:
import sentry_sdk
from sentry_sdk.integrations.gcp import GcpIntegration
sentry_sdk.init(
dsn=os.getenv('SENTRY_DSN'),
integrations=[GcpIntegration()],
traces_sample_rate=1.0, # adjust the sample rate in production as needed
)
except ImportError as e:
print('sentry not enabled', e)
# ======================== bernco ===========================
def bernco_manual_water_levels(request):
from stao.bernco.manual import BernCoManualGWLObservations
stao = BernCoManualGWLObservations()
return stao.render(request)
def bernco_manual_waterlevel_datastreams(request):
from stao.bernco.manual import BernCoWellDatastreams
stao = BernCoWellDatastreams()
ss = SimpleSTAO()
ss.render('sensor', MANUAL_SENSOR)
ss.render('observed_property', DTW_OBS_PROP)
return stao.render(request)
def bernco_manual_things(request):
from stao.bernco.manual import BernCoThings
stao = BernCoThings()
return stao.render(request)
def bernco_manual_locations(request):
from stao.bernco.manual import BernCoLocations
stao = BernCoLocations()
return stao.render(request)
def bernco_hydrovu_locations(request):
from stao.bernco.entities import BernCoLocations
stao = BernCoLocations()
return stao.render(request)
def bernco_hydrovu_things(request):
from stao.bernco.entities import BernCoThings
stao = BernCoThings()
return stao.render(request)
def bernco_hydrovu_waterlevel_datastreams(request):
from stao.bernco.entities import BernCoWaterLevelsDatastreams
stao = BernCoWaterLevelsDatastreams()
ss = SimpleSTAO()
ss.render('sensor', HYDROVU_SENSOR)
return stao.render(request)
def bernco_hydrovu_water_levels(request):
from stao.bernco.entities import BernCoObservations
stao = BernCoObservations()
return stao.render(request)
def pecos_manual_waterlevel_datastreams(request):
from stao.pecos_manual.entities import PecosManualWaterlevelsDatastreams
stao = PecosManualWaterlevelsDatastreams()
ss = SimpleSTAO()
ss.render('sensor', MANUAL_SENSOR)
ss.render('observed_property', DTW_OBS_PROP)
return stao.render(request)
def pecos_manual_waterlevel_observations(request):
from stao.pecos_manual.entities import PecosManualWaterLevelsObservations
stao = PecosManualWaterLevelsObservations()
return stao.render(request)
# ======================== pvacd hydrovu ===========================
def pecos_hydrovu_locations(request):
print('received request', request)
from stao.pecos_hydrovu.entities import PHVLocations
print('imported PHVLocations', PHVLocations)
stao = PHVLocations()
print('created PHVLocations', stao)
try:
resp = stao.render(request)
except BaseException as e:
import traceback
exc = traceback.format_exc()
print('error', exc)
resp = {'error': str(e)}
print('response', resp)
return resp
def pecos_hydrovu_things(request):
from stao.pecos_hydrovu.entities import PHVThings
stao = PHVThings()
return stao.render(request)
def pecos_hydrovu_waterlevel_datastreams(request):
from stao.pecos_hydrovu.entities import PHVWaterLevelsDatastreams
stao = PHVWaterLevelsDatastreams()
ss = SimpleSTAO()
ss.render('sensor', HYDROVU_SENSOR)
return stao.render(request)
def pecos_hydrovu_water_levels(request):
from stao.pecos_hydrovu.entities import PHVObservations
stao = PHVObservations()
return stao.render(request)
# =================================================
# ======================== isc seven rivers ===========================
def isc_seven_rivers_locations(request):
from stao.isc_seven_rivers.entities import etl_locations
return etl_locations(request)
def isc_seven_rivers_things(request):
from stao.isc_seven_rivers.entities import etl_things
return etl_things(request)
def isc_seven_rivers_datastreams(request):
from stao.isc_seven_rivers.entities import ISCSevenRiversSensors, ISCSevenRiversObservedProperties, \
ISCSevenRiversDatastreams
ret = []
for k in (ISCSevenRiversSensors, ISCSevenRiversObservedProperties, ISCSevenRiversDatastreams):
stao = k()
ret.append(stao.render(request))
return ','.join(ret)
def isc_seven_rivers_water_levels(request):
from stao.isc_seven_rivers.entities import ISCSevenRiversWaterLevels
stao = ISCSevenRiversWaterLevels()
return stao.render(request)
# =============== NMBGMR =====================
# def nmbgmr_locations(request):
# from stao.nmbgmr.entities import NMBGMRLocations
# stao = NMBGMRLocations()
# return stao.render(request)
#
#
# def nmbgmr_things(request):
# from nmbgmr.entities import NMBGMRThings
# stao = NMBGMRThings()
# return stao.render(request)
#
#
# def nmbgmr_manual_waterlevel_datastreams(request):
# from nmbgmr.entities import NMBGMRManualWaterLevelsDatastreams
# stao = NMBGMRManualWaterLevelsDatastreams()
#
# ss = SimpleSTAO()
# ss.render('sensor', MANUAL_SENSOR)
# ss.render('observed_property', DTW_OBS_PROP)
#
# return stao.render(request)
#
#
# def nmbgmr_pressure_waterlevel_datastreams(request):
# from nmbgmr.entities import NMBGMRPressureWaterLevelsDatastreams
# stao = NMBGMRPressureWaterLevelsDatastreams()
#
# ss = SimpleSTAO()
# ss.render('sensor', PRESSURE_SENSOR)
# ss.render('observed_property', DTW_OBS_PROP)
#
# return stao.render(request)
#
#
# def nmbgmr_acoustic_waterlevel_datastreams(request):
# from nmbgmr.entities import NMBGMRAcousticWaterLevelsDatastreams
# stao = NMBGMRAcousticWaterLevelsDatastreams()
#
# ss = SimpleSTAO()
# ss.render('sensor', ACOUSTIC_SENSOR)
# ss.render('observed_property', DTW_OBS_PROP)
#
# return stao.render(request)
#
#
# def nmbgmr_pressure_waterlevel_observations(request):
# from nmbgmr.entities import NMBGMRWaterLevelsObservations
# stao = NMBGMRWaterLevelsObservations('pressure_gwl')
# return stao.render(request)
#
#
# def nmbgmr_acoustic_waterlevel_observations(request):
# from nmbgmr.entities import NMBGMRWaterLevelsObservations
# stao = NMBGMRWaterLevelsObservations('acoustic_gwl')
# return stao.render(request)
#
#
# def nmbgmr_manual_waterlevel_observations(request):
# from nmbgmr.entities import NMBGMRWaterLevelsObservations
# stao = NMBGMRWaterLevelsObservations('nmbgmr_manual_gwl')
# return stao.render(request)
# =================================================
# =============== OSE RealTime =====================
# def ose_realtime_locations(request):
# from ose_realtime.entities import OSERealtimeLocations
# stao = OSERealtimeLocations()
# return stao.render(request)
#
#
# def ose_realtime_things(request):
# from ose_realtime.entities import OSERealtimeThings
# stao = OSERealtimeThings()
# return stao.render(request)
#
#
# def ose_realtime_datastreams(request):
# from ose_realtime.entities import OSERealtimeSensors, OSERealtimeObservedProperties, OSERealtimeDatastreams
#
# ret = []
# for k in (OSERealtimeSensors, OSERealtimeObservedProperties, OSERealtimeDatastreams):
# stao = k()
# ret.append(stao.render(request))
#
# return ','.join(ret)
# =================================================
def isc_seven_rivers_totalizer_datastreams(request):
from stao.isc_seven_rivers.entities import ISCSevenRiversTotalizerDatastreams
ss = SimpleSTAO()
ss.render('sensor', TOTALIZER_SENSOR)
for obspropd in TOTALIZER_OBSERVED_PROPERTIES:
payload = obspropd.fromkeys(('name', 'description', 'definition', 'properties'))
ss.render('observed_property', payload)
stao = ISCSevenRiversTotalizerDatastreams()
return stao.render(request)
# =============== CABQ =====================
# def cabq_waterelevations(request):
# from cabq.entities import CABQWaterElevations
# stao = CABQWaterElevations()
# ret = stao.render(request)
# return ret
#
#
# def cabq_waterdepths(request):
# from cabq.entities import CABQWaterDepths
# stao = CABQWaterDepths()
# ret = stao.render(request)
# return ret
def cabq_locations(request):
from stao.cabq.entities import CABQLocations
stao = CABQLocations()
return stao.render(request, dry=False)
def cabq_things(request):
from stao.cabq.entities import CABQThings
stao = CABQThings()
return stao.render(request, dry=False)
def cabq_datastreams(request):
from stao.cabq.entities import CABQDatastreams
stao = CABQDatastreams()
return stao.render(request, dry=False)
def cabq_waterlevels(request):
from stao.cabq.entities import CABQWaterDepths
stao = CABQWaterDepths()
return stao.render(request, dry=False)
def cabq_waterlevel_elevations(request):
from stao.cabq.entities import CABQWaterElevations
stao = CABQWaterElevations()
return stao.render(request, dry=False)
# ============== EBID ========================
def ebid_well_locations(request):
from stao.ebid.entities import EBIDWellLocations
stao = EBIDWellLocations()
return stao.render(request, dry=False)
def ebid_well_things(request):
from stao.ebid.entities import EBIDWellThings
stao = EBIDWellThings()
return stao.render(request, dry=False)
def ebid_well_datastreams(request):
from stao.ebid.entities import EBIDWellDatastreams
stao = EBIDWellDatastreams()
return stao.render(request, dry=False)
def ebid_well_waterlevels(request):
from stao.ebid.entities import EBIDGWLObservations
stao = EBIDGWLObservations()
return stao.render(request, dry=False)
if __name__ == '__main__':
# cabq_locations(None)
# cabq_things(None)
# cabq_datastreams(None)
# cabq_waterlevels(None)
cabq_waterlevel_elevations(None)
# ebid_locations(None)
# ebid_things(None)
# ebid_well_datastreams(None)
# ebid_well_waterlevels(None)
# pecos_hydrovu_things(None)
# pecos_hydrovu_locations(None)
# pecos_manual_waterlevel_datastreams(None)
# state = None
# for i in range(2):
# state = pecos_manual_waterlevel_observations(state)
# ============= EOF =============================================