-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpylayout.py
429 lines (402 loc) · 12.9 KB
/
pylayout.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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
"""
This module contains the layout components for a Dash application.
The layout includes HTML elements, Bootstrap components,
and functions to generate graphs and figures.
"""
from dash import html, dcc
import dash_bootstrap_components as dbc
import pandas as pd
import plotly.io as pio
import pyfigure
import pylayoutfunc
from pyconfig import appConfig
from pytemplate import mytemplate
pio.templates.default = mytemplate
HTML_TITLE = html.Div(
[
html.H1(
appConfig.DASH_APP.APP_TITLE, className="float fw-bold mt-3 fs-1 fw-bold"
),
html.Span("KAGGLE DATASET VERSION", className="fw-bold"),
html.Br(),
html.Span(
html.A(
[appConfig.GITHUB_REPO, "@", appConfig.VERSION],
href="https://github.com/taruma/demo-stations",
target="_blank",
),
className="text-muted",
),
html.Br(),
],
className="text-center",
)
# ALERT_INFO = dbc.Alert(
# [
# "Informasi aplikasi ini dapat dilihat di ",
# html.A(
# "GitHub README",
# href="https://github.com/taruma/demo-stations#readme",
# target="_blank",
# ),
# ".",
# ],
# color="info",
# class_name="text-center fw-bold",
# )
ALERT_DATA = dbc.Alert(
[
"The displayed data comes from the KAGGLE DATASET.",
html.Br(),
"Information about the Kaggle dataset can be found ",
html.A(
"here",
href="https://www.kaggle.com/datasets/greegtitan/indonesia-climate",
target="_blank",
),
". With HDF5 data from ",
html.A(
"here",
href="https://www.kaggle.com/code/tarumainfo/compile-rainfall-dataset-to-hdf5",
target="_blank",
),
".",
# html.Br(),
# "With this modification, the metadata/rainfall download options are disabled.",
],
color="warning",
class_name="text-center fw-bold",
)
HTML_INFO = html.Div(
# [ALERT_INFO, ALERT_DATA],
[ALERT_DATA],
className="mt-3",
)
def html_map(combined_metadata_rainfall: pd.DataFrame) -> html.Div:
"""Generate a map of rainfall stations."""
return html.Div(
[
html.H2("Map of Rainfall Stations", className="text-center"),
pylayoutfunc.graph_map(
figure=pyfigure.generate_station_map_figure(combined_metadata_rainfall)
),
],
className="mt-5",
)
HTML_ROW_INPUT = dbc.Container(
[
dbc.Row(
[
dbc.Col(
[
dbc.Label("Coordinate Name / Nama Koordinat"),
dbc.Input(
id="input-name-coordinate",
placeholder="type coordinate name...",
type="text",
value="My Coordinate",
),
dbc.FormText("Example: My Coordinate"),
],
md=3,
),
dbc.Col(
[
dbc.Label("Latitude / Lintang Derajat"),
dbc.Input(
id="input-latitude",
placeholder="type valid latitude coordinate...",
type="text",
value="""6°50'49.9"S""",
),
dbc.FormText("""Example: 6°50'49.9"S"""),
],
md=3,
),
dbc.Col(
[
dbc.Label("Longitude / Bujur Derajat"),
dbc.Input(
id="input-longitude",
placeholder="type valid longitude coordinate...",
type="text",
value="107.525361",
),
dbc.FormText("Example: 107.525361"),
],
md=3,
),
dbc.Col(
[
dbc.Label("Radius (km)"),
dbc.Input(
id="input-radius",
placeholder="0 - ♾️",
type="number",
value=100,
),
],
# width=2,
),
dbc.Col(
[
dbc.Label("Total Stations"),
dbc.Input(
id="input-n-stations",
placeholder="0 - ♾️",
type="number",
value=5,
),
],
# width=2,
),
],
)
],
fluid=True,
class_name="mt-4",
)
HTML_ROW_BUTTON_NEAREST = dbc.Container(
dbc.Row(
dbc.Col(
dbc.Button(
"Find Nearest Stations",
id="button-coordinate-validity",
size="lg",
),
width="auto",
),
justify="end",
),
class_name="my-3",
fluid=True,
)
HTML_ROW_COORDINATE = dbc.Container(
[
dbc.Row(
[
dbc.Col(
[
html.H3("Map of Nearest Stations"),
dcc.Loading(
dcc.Graph(
figure=pyfigure.generate_empty_figure(margin_all=50),
config={"staticPlot": True},
),
id="graph-coordinate",
),
],
md=6,
),
dbc.Col(
[
html.H3("Table of Nearest Stations"),
dcc.Loading(
dcc.Graph(
figure=pyfigure.generate_empty_figure(margin_all=50),
config={"staticPlot": True},
),
id="table-coordinate",
),
],
md=6,
),
],
justify="start",
)
],
fluid=True,
)
HTML_ROW_BUTTON_GRAPH_COMPLETENESS = dbc.Container(
dbc.Row(
dbc.Col(
dbc.Button(
"Plot Rainfall Data Completeness",
id="button-graph-completeness",
color="warning",
disabled=True,
size="lg",
# class_name="float-end",
),
width="auto",
),
justify="center",
),
fluid=True,
class_name="my-3",
)
HTML_ROW_COMPLETENESS_RAINFALL = dbc.Container(
[
dbc.Row(
[
html.H3("Rainfall Data Completeness"),
dcc.Loading(
dcc.Graph(
figure=pyfigure.generate_empty_figure(margin_all=50),
config={"staticPlot": True},
),
id="graph-completeness-rainfall",
),
],
justify="start",
)
],
fluid=True,
class_name="my-3",
)
def _options_stations(combined_metadata_rr: pd.DataFrame) -> list[dict]:
return [
{"label": f"{stat_id} - {series.station_name}", "value": stat_id}
for stat_id, series in combined_metadata_rr.iterrows()
]
def html_row_rainfall_options(combined_metadata_rr: pd.DataFrame) -> dbc.Container:
"""Generate a row of rainfall data options."""
return dbc.Container(
[
dbc.Row(
[
dbc.Col(
[
html.H3("Rainfall Data Options"),
dbc.Card(
[
dbc.Label("Select Stations"),
dcc.Dropdown(
id="dropdown-stations",
options=_options_stations(combined_metadata_rr),
clearable=True,
multi=True,
value=[
"kg_96783",
"kg_96751",
"kg_96791",
"kg_96753",
"kg_96747",
],
),
html.Br(),
dbc.Label("Select Years"),
dcc.Loading(
html.P(
"Pick Stations First",
className="text-muted text-center",
),
id="row-rangeslider-years",
),
html.Br(),
dbc.Checklist(
options=[
{
"label": "Clean Unmeasured Data (8888 & 9999)",
"value": "clean-data",
}
],
value=["clean-data"],
id="switches-clean-data",
switch=True,
),
],
body=True,
),
],
),
],
justify="start",
),
dbc.Row(
[
dbc.Col(
[
dbc.Button(
"Plot Rainfall Data",
id="button-graph-rainfall",
color="danger",
size="lg",
disabled=True,
),
],
width="auto",
),
],
class_name="my-4",
justify="center",
),
],
fluid=True,
class_name="my-3",
)
HTML_ROW_GRAPH_RAINFALL = dbc.Container(
[
dbc.Row(
[
html.H3("Rainfall Data"),
dcc.Loading(
dcc.Graph(
figure=pyfigure.generate_empty_figure(margin_all=50),
config={"staticPlot": True},
),
id="graph-rainfall-data",
),
],
justify="start",
)
],
fluid=True,
class_name="my-3",
)
HTML_ROW_BUTTON_DOWNLOAD = dbc.Container(
dbc.Row(
dbc.Col(
[
dbc.Button(
"Download Metadata Stations",
id="button-download-metadata-stations",
size="lg",
color="info",
class_name="mx-3",
disabled=False,
),
dcc.Download(id="download-metadata-stations"),
dbc.Button(
"Download Rainfall Data",
id="button-download-rainfall",
size="lg",
disabled=True,
color="primary",
class_name="mx-3",
),
dcc.Download(id="download-rainfall"),
],
width="auto",
),
justify="center",
),
fluid=True,
class_name="my-3",
)
_HTML_TROUBLESHOOTER = html.Div(id="row-troubleshooter")
HTML_CREATOR = html.P(
[
html.Hr(),
"created by ",
html.A("taruma", href="https://taruma.my.id"),
# ". Sponsored by ",
# html.A("FIAKO Engineering", href="https://fiako.engineering"),
],
className="text-muted text-center mt-5 mb-1",
)
HTML_FOOTER = html.Div(
html.Footer(
[
html.Span("\u00A9"),
" 2024 ",
html.A(
"Taruma Sakti Megariansyah",
href="https://dev.taruma.info",
target="_blank",
),
".",
],
className="text-center mb-3",
),
)