|
1
|
|
|
""" |
|
2
|
|
|
The main public routes to view the site |
|
3
|
|
|
""" |
|
4
|
|
|
|
|
5
|
|
|
from bokeh.embed import components |
|
6
|
|
|
from flask import render_template, current_app |
|
7
|
|
|
|
|
8
|
|
|
from .blueprint import main |
|
9
|
|
|
from .plot import CorrelationPlot, SensorPlot |
|
10
|
|
|
from app.database import gage_sample |
|
11
|
|
|
from ..models import Gage, Region, Section, River, Sensor |
|
12
|
|
|
|
|
13
|
|
|
# Normal Pages |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
@main.route('/') |
|
17
|
|
|
def indexpage(): |
|
18
|
|
|
"""**/** |
|
19
|
|
|
|
|
20
|
|
|
Index page |
|
21
|
|
|
""" |
|
22
|
|
|
return render_template('index.html', gage_sample=gage_sample) |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
@main.route('/about/') |
|
26
|
|
|
def aboutpage(): |
|
27
|
|
|
"""**/about/** |
|
28
|
|
|
|
|
29
|
|
|
About this site. |
|
30
|
|
|
""" |
|
31
|
|
|
return render_template('about.html', gage_sample=gage_sample) |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
@main.route('/map/') |
|
35
|
|
|
def mappage(): |
|
36
|
|
|
"""**/map/** |
|
37
|
|
|
|
|
38
|
|
|
Map of gages and sections |
|
39
|
|
|
""" |
|
40
|
|
|
mapbox_access_token = current_app.config['MAPBOX_ACCESS_TOKEN'] |
|
41
|
|
|
return render_template('map.html', |
|
42
|
|
|
gage_sample=gage_sample, |
|
43
|
|
|
Gage=Gage, |
|
44
|
|
|
Section=Section, |
|
45
|
|
|
mapbox_access_token=mapbox_access_token) |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
@main.route('/gages/') |
|
49
|
|
|
@main.route('/gage/') |
|
50
|
|
|
def gagespage(): |
|
51
|
|
|
"""**/gages/** |
|
52
|
|
|
|
|
53
|
|
|
List of gages currently not grouped by regions, |
|
54
|
|
|
or anything else for that matter. |
|
55
|
|
|
""" |
|
56
|
|
|
return render_template('gages.html', Gage=Gage) |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
@main.route('/gage/<int:gid>/') |
|
60
|
|
|
@main.route('/gage/<slug>/') |
|
61
|
|
|
def gagepage(gid=None, slug=None): |
|
62
|
|
|
"""**/gage/<slug>/** |
|
63
|
|
|
|
|
64
|
|
|
Individual gage page |
|
65
|
|
|
""" |
|
66
|
|
|
if slug is None: |
|
67
|
|
|
gage = Gage.query.get_or_404(gid) |
|
68
|
|
|
else: |
|
69
|
|
|
gage = Gage.query.filter_by(slug=slug).first_or_404() |
|
70
|
|
|
sensors = Sensor.query.filter_by(gage_id=gage.id).all() |
|
71
|
|
|
|
|
72
|
|
|
plots = [SensorPlot(gage.id, sensor.stype).bokeh() for sensor in sensors] |
|
73
|
|
|
|
|
74
|
|
|
script, divs = components(plots) |
|
75
|
|
|
|
|
76
|
|
|
sensor_divs = zip(sensors, divs) |
|
77
|
|
|
|
|
78
|
|
|
return render_template('gage.html', |
|
79
|
|
|
Gage=Gage, |
|
80
|
|
|
gage=gage, |
|
81
|
|
|
gage_sample=gage_sample, |
|
82
|
|
|
script=script, |
|
83
|
|
|
sensor_divs=sensor_divs) |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
@main.route('/regions/') |
|
87
|
|
|
@main.route('/region/') |
|
88
|
|
|
def regionspage(): |
|
89
|
|
|
"""**/regions/** |
|
90
|
|
|
|
|
91
|
|
|
List all regions |
|
92
|
|
|
""" |
|
93
|
|
|
return render_template('regions.html', Gage=Gage, Region=Region) |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
@main.route('/region/<int:rid>/') |
|
97
|
|
|
@main.route('/region/<slug>/') |
|
98
|
|
|
def regionpage(rid=None, slug=None): |
|
99
|
|
|
"""**/region/<slug>/** |
|
100
|
|
|
|
|
101
|
|
|
Individual region page |
|
102
|
|
|
""" |
|
103
|
|
|
if slug is None: |
|
104
|
|
|
region = Region.query.get_or_404(rid) |
|
105
|
|
|
else: |
|
106
|
|
|
region = Region.query.filter_by(slug=slug).first_or_404() |
|
107
|
|
|
return render_template('region.html', |
|
108
|
|
|
Gage=Gage, |
|
109
|
|
|
Region=Region, |
|
110
|
|
|
region=region, |
|
111
|
|
|
Section=Section, |
|
112
|
|
|
River=River, |
|
113
|
|
|
gage_sample=gage_sample) |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
@main.route('/sections/') |
|
117
|
|
|
@main.route('/section/') |
|
118
|
|
|
def sectionspage(): |
|
119
|
|
|
"""**/sections/** |
|
120
|
|
|
|
|
121
|
|
|
List all sections |
|
122
|
|
|
""" |
|
123
|
|
|
return render_template('sections.html', Gage=Gage, Section=Section) |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
@main.route('/section/<int:sid>/') |
|
127
|
|
|
@main.route('/river/<river>/<slug>/') |
|
128
|
|
|
def sectionpage(sid=None, slug=None, river=None): |
|
129
|
|
|
"""**/section/<slug>/** |
|
130
|
|
|
|
|
131
|
|
|
Individual section page |
|
132
|
|
|
""" |
|
133
|
|
|
if river and slug: |
|
134
|
|
|
section = Section.query.join(Section.river)\ |
|
135
|
|
|
.filter(River.slug == river)\ |
|
136
|
|
|
.filter(Section.slug == slug)\ |
|
137
|
|
|
.first_or_404() |
|
138
|
|
|
else: |
|
139
|
|
|
section = Section.query.get_or_404(sid) |
|
140
|
|
|
|
|
141
|
|
|
correlations = section.correlations |
|
142
|
|
|
|
|
143
|
|
|
plots = [CorrelationPlot(correlation.section_id, correlation.sensor_id).bokeh() for correlation in correlations] |
|
144
|
|
|
script, divs = components(plots) |
|
145
|
|
|
|
|
146
|
|
|
correlation_divs = list(zip(correlations, divs)) |
|
147
|
|
|
|
|
148
|
|
|
return render_template('section.html', |
|
149
|
|
|
Gage=Gage, |
|
150
|
|
|
Section=Section, |
|
151
|
|
|
section=section, |
|
152
|
|
|
Sensor=Sensor, |
|
153
|
|
|
gage_sample=gage_sample, |
|
154
|
|
|
script=script, |
|
155
|
|
|
correlation_divs=correlation_divs) |
|
156
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
@main.route('/rivers/') |
|
159
|
|
|
@main.route('/river/') |
|
160
|
|
|
def riverspage(): |
|
161
|
|
|
"""**/rivers/** |
|
162
|
|
|
|
|
163
|
|
|
List all rivers |
|
164
|
|
|
""" |
|
165
|
|
|
return render_template('rivers.html', |
|
166
|
|
|
Gage=Gage, |
|
167
|
|
|
River=River, |
|
168
|
|
|
Section=Section) |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
@main.route('/river/<int:rid>/') |
|
172
|
|
|
@main.route('/river/<slug>/') |
|
173
|
|
|
def riverpage(rid=None, slug=None): |
|
174
|
|
|
"""**/river/<slug>/** |
|
175
|
|
|
|
|
176
|
|
|
Individual river page |
|
177
|
|
|
""" |
|
178
|
|
|
if slug is None: |
|
179
|
|
|
river = River.query.get_or_404(rid) |
|
180
|
|
|
else: |
|
181
|
|
|
river = River.query.filter_by(slug=slug).first_or_404() |
|
182
|
|
|
return render_template('river.html', |
|
183
|
|
|
Gage=Gage, |
|
184
|
|
|
River=River, |
|
185
|
|
|
Section=Section, |
|
186
|
|
|
river=river, |
|
187
|
|
|
gage_sample=gage_sample) |
|
188
|
|
|
|