-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
executable file
·709 lines (630 loc) · 24.3 KB
/
app.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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
import json
import pathlib
import urllib3
import dash
from dash.dependencies import Input, Output, State, ALL, ClientsideFunction
from dash.exceptions import PreventUpdate
from dash.dash import no_update
import dash_html_components as html
import dash_bootstrap_components as dbc
from flask import flash, get_flashed_messages
from flask_caching import Cache
from data import dev
import preprocessing
from settings import (
SECRET_KEY,
DB_URL,
DEBUG,
MANAGE_DB,
SKIP_TS,
SC_FILTERS,
USE_DUMMY_DATA,
CACHE_CONFIG,
MAX_WARNINGS,
MAX_INFOS,
)
import scenario
import graphs
from models import db, get_model_options, Filter, Colors, Labels, Scenarios
urllib3.disable_warnings()
APP_PATH = str(pathlib.Path(__file__).parent.resolve())
# Initialize app
app = dash.Dash(
__name__,
meta_tags=[
{"name": "viewport", "content": "width=device-width, initial-scale=4.0"},
],
external_stylesheets=[dbc.themes.BOOTSTRAP],
)
server = app.server
server.secret_key = SECRET_KEY
# Database
server.config["SQLALCHEMY_DATABASE_URI"] = DB_URL
server.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.init_app(server)
# Cache
cache = Cache()
cache.init_app(server, config=CACHE_CONFIG)
# Layout
if not MANAGE_DB:
from layout.main import (
DEFAULT_LAYOUT,
get_layout,
get_graph_options,
get_error_and_warnings_div,
)
from layout.imprint import get_imprint_layout
from layout.privacy import get_privacy_layout
from layout.results import get_results_layout
from layout.docs import get_docs_layout
app.layout = DEFAULT_LAYOUT
app.validation_layout = html.Div(
[
DEFAULT_LAYOUT,
get_layout(app, scenarios=scenario.get_scenarios()),
get_imprint_layout(app),
get_privacy_layout(app),
get_results_layout(app),
get_docs_layout(app)
]
)
# Multiple pages
@app.callback(
dash.dependencies.Output("page-content", "children"),
[dash.dependencies.Input("url", "pathname")],
)
def display_page(pathname):
if pathname == "/imprint":
return get_imprint_layout(app)
elif pathname == "/privacy":
return get_privacy_layout(app)
elif pathname == "/documentation":
return get_docs_layout(app)
elif pathname == "/results":
return get_results_layout(app)
else:
return get_layout(app, scenarios=scenario.get_scenarios())
@cache.memoize()
def get_scenario_data(scenario_id, table):
app.logger.info(f"Loading scenario data #{scenario_id} (not cached)...")
if USE_DUMMY_DATA:
return dev.get_dummy_data(scenario_id, table)
return scenario.get_scenario_data(scenario_id, table)
@cache.memoize()
def get_multiple_scenario_data(*scenario_ids, table):
app.logger.info("Merging scenario data (not cached)...")
scenarios = [get_scenario_data(scenario_id, table) for scenario_id in scenario_ids]
merged = scenario.merge_scenario_data(scenarios)
app.logger.info("Merged scenario data")
return merged
@cache.memoize()
def get_scenario_filters(scenario_id):
app.logger.info(f"Loading scenario data #{scenario_id} (not cached)...")
if USE_DUMMY_DATA:
return dev.get_dummy_filters(scenario_id)
return scenario.get_scenario_filters(scenario_id)
@cache.memoize()
def get_multiple_scenario_filters(*scenario_ids):
app.logger.info("Merging scenario data (not cached)...")
scenarios = [
get_scenario_filters(scenario_id) for scenario_id in scenario_ids
]
merged = scenario.merge_scenario_data(scenarios)
app.logger.info("Merged scenario data")
return merged
@app.callback(
Output(component_id="dd_scenario", component_property="options"),
Input("scenario_reload", "n_clicks"),
)
def reload_scenarios(_):
scenarios = scenario.get_scenarios()
return [
{"label": f"{sc['id']}, {sc['scenario']}, {sc['source']}", "value": sc["id"]}
for sc in scenarios
]
app.clientside_callback(
ClientsideFunction(namespace="clientside", function_name="update_refresh_elements"),
Output(component_id="refresh_scalars", component_property="className"),
Output(component_id="refresh_timeseries", component_property="className"),
[
Input("dd_scenario", "value"),
Input(component_id="order_by", component_property="value"),
Input(component_id="aggregation_group_by", component_property="value"),
Input({"name": ALL, "type": "filters"}, "value"),
Input({"name": ALL, "type": "unit-dropdown"}, "value"),
Input({"name": ALL, "type": "graph_scalars_option"}, "value"),
Input({"name": ALL, "type": "graph_timeseries_option"}, "value"),
Input("load_filters", "value"),
Input("load_colors", "value"),
Input("load_labels", "value"),
],
prevent_initial_call=True,
)
@app.callback(
[
Output(component_id="load_filters", component_property="options"),
Output(component_id="save_filters_name", component_property="value"),
],
Input("save_filters", "n_clicks"),
[
State(component_id="save_filters_name", component_property="value"),
State(component_id="graph_scalars_options", component_property="children"),
State(component_id="graph_timeseries_options", component_property="children"),
State(component_id="order_by", component_property="value"),
State(component_id="aggregation_group_by", component_property="value"),
State(component_id="normalize", component_property="value"),
State(component_id="filters", component_property="children"),
],
)
def save_filters(
_,
name,
graph_scalars_options,
graph_timeseries_options,
order_by,
agg_group_by,
normalize,
filter_div,
):
if not name:
raise PreventUpdate
filters = preprocessing.extract_filters("scalars", filter_div)
filters["order_by"] = order_by
filters["agg_group_by"] = agg_group_by
filters["normalize"] = normalize
scalar_graph_options = preprocessing.extract_graph_options("scalars", graph_scalars_options)
ts_graph_options = preprocessing.extract_graph_options("timeseries", graph_timeseries_options)
db_filter = Filter(
name=name,
filters=filters,
scalar_graph_options=scalar_graph_options,
ts_graph_options=ts_graph_options,
)
db.session.add(db_filter)
db.session.commit()
return get_model_options(Filter), ""
@app.callback(
[
Output(component_id="load_colors", component_property="options"),
Output(component_id="save_colors_name", component_property="value"),
Output(component_id="colors_error", component_property="children"),
],
Input("save_colors", "n_clicks"),
[
State(component_id="save_colors_name", component_property="value"),
State(component_id="colors", component_property="value"),
],
)
def save_colors(_, name, str_colors):
if not name:
raise PreventUpdate
try:
colors = json.loads(str_colors)
except json.JSONDecodeError as je:
flash(
f"Could not read color mapping. Input must be valid JSON. (Error: {je})",
"error",
)
return get_model_options(Colors), "", show_logs()[0]
db_colors = Colors(name=name, colors=colors,)
db.session.add(db_colors)
db.session.commit()
return get_model_options(Colors), "", show_logs()[0]
@app.callback(
[
Output(component_id="load_labels", component_property="options"),
Output(component_id="save_labels_name", component_property="value"),
Output(component_id="labels_error", component_property="children"),
],
Input("save_labels", "n_clicks"),
[
State(component_id="save_labels_name", component_property="value"),
State(component_id="labels", component_property="value"),
],
)
def save_labels(_, name, str_labels):
if not name:
raise PreventUpdate
try:
labels = json.loads(str_labels)
except json.JSONDecodeError as je:
flash(
f"Could not read labels. Input must be valid JSON. (Error: {je})", "error"
)
return get_model_options(Labels), "", show_logs()[0]
db_labels = Labels(name=name, labels=labels,)
db.session.add(db_labels)
db.session.commit()
return get_model_options(Labels), "", show_logs()[0]
@app.callback(
[
Output(component_id="load_scenarios", component_property="options"),
Output(component_id="save_scenarios_name", component_property="value"),
Output(component_id="scenarios_error", component_property="children"),
],
Input("save_scenarios", "n_clicks"),
[
State(component_id="save_scenarios_name", component_property="value"),
State(component_id="dd_scenario", component_property="value"),
],
)
def save_scenarios(_, name, scenario_ids):
if not name or not scenario_ids:
raise PreventUpdate
db_scenarios = Scenarios(name=name, ids=scenario_ids,)
db.session.add(db_scenarios)
db.session.commit()
return get_model_options(Scenarios), "", show_logs()[0]
# TODO: Fixed arg number can possibly fixed with Dash 2.0 allowing for keyword args,
# but Dash 2.0 breaks CSS styles
@app.callback(
[
Output(component_id="graph_scalars_plot_switch", component_property="value"),
Output(component_id="graph_timeseries_plot_switch", component_property="value"),
Output(component_id="order_by", component_property="value"),
Output(component_id="aggregation_group_by", component_property="value"),
Output(component_id="normalize", component_property="value"),
]
+ [
Output(
component_id={"name": filter_, "type": "filter-dropdown"},
component_property="value",
)
for filter_ in SC_FILTERS
]
+ [Output(component_id="save_load_errors", component_property="children")],
[
Input("load_filters", "value"),
] +
[Input(f"all_{filter_}", "n_clicks") for filter_ in SC_FILTERS],
State(component_id="dd_scenario", component_property="value"),
prevent_initial_call=True,
)
def load_filters(name, _, __, ___, ____, _____, ______, _______, ________, scenarios):
if not scenarios:
flash("No scenario selected - cannot load filters without scenario", "error")
return (
no_update,
no_update,
no_update,
no_update,
no_update,
*([no_update] * len(SC_FILTERS)),
show_logs()[0],
)
ctx = dash.callback_context
# All Button clicked:
if ctx.triggered[0]["prop_id"].endswith("n_clicks"):
current_filter = ctx.triggered[0]["prop_id"][4:-9]
raw_filter_values = get_multiple_scenario_filters(*scenarios)
scan_filters = {current_filter: SC_FILTERS[current_filter]}
current_filter_options = preprocessing.get_filter_options(
raw_filter_values,
filter_list=scan_filters,
as_options=False
)
filter_options = [no_update] * len(SC_FILTERS)
current_filter_index = list(SC_FILTERS.keys()).index(current_filter)
filter_options[current_filter_index] = list(current_filter_options[current_filter])
return (
no_update,
no_update,
no_update,
no_update,
no_update,
*filter_options,
show_logs()[0],
)
# Load filters:
if not name:
raise PreventUpdate
db_filter = Filter.query.filter_by(name=name).first()
filters = [db_filter.filters.get(filter_, None) for filter_ in SC_FILTERS]
flash("Successfully loaded filters", "info")
return (
db_filter.scalar_graph_options["type"],
db_filter.ts_graph_options["type"],
db_filter.filters.get("order_by", []),
db_filter.filters["agg_group_by"],
db_filter.filters["normalize"] if "normalize" in db_filter.filters else no_update,
*filters,
show_logs()[0],
)
@app.callback(
Output(component_id="colors", component_property="value"),
Input("load_colors", "value"),
prevent_initial_call=True,
)
def load_colors(name):
if not name:
raise PreventUpdate
db_colors = Colors.query.filter_by(name=name).first()
return json.dumps(db_colors.colors)
@app.callback(
Output(component_id="labels", component_property="value"),
Input("load_labels", "value"),
prevent_initial_call=True,
)
def load_labels(name):
if not name:
raise PreventUpdate
db_labels = Labels.query.filter_by(name=name).first()
return json.dumps(db_labels.labels)
@app.callback(
Output(component_id="dd_scenario", component_property="value"),
Input("load_scenarios", "value"),
prevent_initial_call=True,
)
def load_scenarios(name):
if not name:
raise PreventUpdate
db_scenarios = Scenarios.query.filter_by(name=name).first()
return db_scenarios.ids
@app.callback(
[
Output(
component_id={"name": filter_, "type": "filter-dropdown"},
component_property="options",
)
for filter_ in SC_FILTERS
],
[Input(component_id="dd_scenario", component_property="value")],
)
def load_scenario(scenarios):
if scenarios is None:
raise PreventUpdate
scenarios = scenarios if isinstance(scenarios, list) else [scenarios]
filters = get_multiple_scenario_filters(*scenarios)
app.logger.info("Data successfully loaded")
return preprocessing.get_filter_options(filters)
@app.callback(
[Output(component_id="graph_scalars_options", component_property="children")],
[
Input(component_id="graph_scalars_plot_switch", component_property="value"),
Input("load_filters", "value"),
],
prevent_initial_call=True,
)
def toggle_scalar_graph_options(plot_type, name):
# Have to use "callback_context" as every component can only have one output callback
ctx = dash.callback_context
if ctx.triggered[0]["prop_id"] == "graph_scalars_plot_switch.value":
graph_scalar_options = get_graph_options("scalars", plot_type)
else:
if not name:
raise PreventUpdate
db_filter = Filter.query.filter_by(name=name).first()
graph_scalar_options = get_graph_options(
"scalars",
db_filter.scalar_graph_options["type"],
db_filter.scalar_graph_options["options"],
)
return (graph_scalar_options,)
@app.callback(
[Output(component_id="graph_timeseries_options", component_property="children")],
[
Input(component_id="graph_timeseries_plot_switch", component_property="value"),
Input("load_filters", "value"),
],
prevent_initial_call=True,
)
def toggle_timeseries_graph_options(plot_type, name):
# Have to use "callback_context" as every component can only have one output callback
ctx = dash.callback_context
if ctx.triggered[0]["prop_id"] == "graph_timeseries_plot_switch.value":
graph_timeseries_options = get_graph_options("timeseries", plot_type)
else:
if not name:
raise PreventUpdate
db_filter = Filter.query.filter_by(name=name).first()
graph_timeseries_options = get_graph_options(
"timeseries",
db_filter.ts_graph_options["type"],
db_filter.ts_graph_options["options"],
)
return (graph_timeseries_options,)
@app.callback(
[
Output(component_id="graph_scalars", component_property="figure"),
Output(component_id="table_scalars", component_property="data"),
Output(component_id="table_scalars", component_property="columns"),
Output(component_id="graph_scalars_error", component_property="children"),
Output(component_id="tab_scalars_error", component_property="labelClassName"),
Output(component_id="view-dashboard_scalars", component_property="className"),
Output(component_id="view-dashboard-data_scalars", component_property="className"),
Output(component_id="table_div_scalars", component_property="style"),
],
[
Input(component_id="refresh_scalars", component_property="n_clicks"),
Input(component_id="view-dashboard_scalars", component_property="n_clicks"),
Input(component_id="view-dashboard-data_scalars", component_property="n_clicks"),
],
[
State(component_id="view-dashboard-data_scalars", component_property="className"),
State(component_id="units", component_property="children"),
State(component_id="graph_scalars_options", component_property="children"),
State(component_id="filters", component_property="children"),
State(component_id="colors", component_property="value"),
State(component_id="labels", component_property="value"),
State(component_id="order_by", component_property="value"),
State(component_id="aggregation_group_by", component_property="value"),
State(component_id="normalize", component_property="value"),
State(component_id="dd_scenario", component_property="value"),
],
prevent_initial_call=True,
)
def scalar_graph(
_,
__,
___,
show_data_cls,
units_div,
graph_scalars_options,
filter_div,
colors,
labels,
order_by,
agg_group_by,
normalize,
scenarios,
):
if scenarios is None:
raise PreventUpdate
# Check if data shall be shown:
show_data = show_data_cls and "active" in show_data_cls
data_div_cls = no_update, no_update, no_update
ctx = dash.callback_context
if "view-dashboard-data" in ctx.triggered[0]["prop_id"]:
if show_data:
raise PreventUpdate
show_data = True
data_div_cls = "view view--dashboard", "view view--dashboard-data active", {}
elif "view-dashboard" in ctx.triggered[0]["prop_id"]:
if not show_data:
raise PreventUpdate
show_data = False
data_div_cls = "view view--dashboard active", "view view--dashboard-data", {"display": "none"}
data = get_multiple_scenario_data(*scenarios, table="oed_scalars")
filters = preprocessing.extract_filters("scalars", filter_div)
units = preprocessing.extract_unit_options(units_div)
graph_options = preprocessing.extract_graph_options("scalars", graph_scalars_options)
colors = preprocessing.extract_colors(colors)
graph_options["options"]["color_discrete_map"] = colors
labels = preprocessing.extract_labels(labels)
try:
preprocessed_data = preprocessing.prepare_scalars(
data, order_by, agg_group_by, units, filters, labels
)
except preprocessing.PreprocessingError:
log_div, log_level = show_logs()
return graphs.get_empty_fig(), [], [], log_div, log_level, *data_div_cls
if preprocessed_data.empty:
flash("No data for current filter settings", "warning")
log_div, log_level = show_logs()
return graphs.get_empty_fig(), [], [], log_div, log_level, *data_div_cls
if normalize:
preprocessed_data = preprocessing.normalize_data(preprocessed_data, graph_options)
try:
fig = graphs.get_scalar_plot(preprocessed_data, graph_options)
except graphs.PlottingError:
log_div, log_level = show_logs()
return graphs.get_empty_fig(), [], [], log_div, log_level, *data_div_cls
if show_data:
columns = [{"name": i, "id": i} for i in preprocessed_data.columns]
data_table = preprocessed_data.applymap(str).to_dict("records")
else:
columns = []
data_table = []
log_div, log_level = show_logs()
return fig, data_table, columns, log_div, log_level, *data_div_cls
@app.callback(
[
Output(component_id="graph_timeseries", component_property="figure"),
Output(component_id="table_timeseries", component_property="data"),
Output(component_id="table_timeseries", component_property="columns"),
Output(component_id="graph_timeseries_error", component_property="children"),
Output(component_id="tab_timeseries_error", component_property="labelClassName"),
Output(component_id="view-dashboard_timeseries", component_property="className"),
Output(component_id="view-dashboard-data_timeseries", component_property="className"),
Output(component_id="table_div_timeseries", component_property="style"),
],
[
Input(component_id="refresh_timeseries", component_property="n_clicks"),
Input(component_id="view-dashboard_timeseries", component_property="n_clicks"),
Input(component_id="view-dashboard-data_timeseries", component_property="n_clicks"),
],
[
State(component_id="view-dashboard-data_timeseries", component_property="className"),
State(component_id="units", component_property="children"),
State(component_id="graph_timeseries_options", component_property="children"),
State(component_id="filters", component_property="children"),
State(component_id="colors", component_property="value"),
State(component_id="labels", component_property="value"),
State(component_id="order_by", component_property="value"),
State(component_id="aggregation_group_by", component_property="value"),
State(component_id="dd_scenario", component_property="value"),
],
prevent_initial_call=True,
)
def timeseries_graph(
_,
__,
___,
show_data_cls,
units_div,
graph_timeseries_options,
filter_div,
colors,
labels,
order_by,
agg_group_by,
scenarios,
):
if scenarios is None or SKIP_TS:
raise PreventUpdate
# Check if data shall be shown:
show_data = show_data_cls and "active" in show_data_cls
data_div_cls = no_update, no_update, no_update
ctx = dash.callback_context
if "view-dashboard-data" in ctx.triggered[0]["prop_id"]:
if show_data:
raise PreventUpdate
data_div_cls = "view view--dashboard", "view view--dashboard-data active", {}
elif "view-dashboard" in ctx.triggered[0]["prop_id"]:
if not show_data:
raise PreventUpdate
show_data = False
data_div_cls = "view view--dashboard active", "view view--dashboard-data", {"display": "none"}
data = get_multiple_scenario_data(*scenarios, table="oed_timeseries")
filters = preprocessing.extract_filters("timeseries", filter_div)
units = preprocessing.extract_unit_options(units_div)
graph_options = preprocessing.extract_graph_options("timeseries", graph_timeseries_options)
colors = preprocessing.extract_colors(colors)
graph_options["options"]["color_discrete_map"] = colors
labels = preprocessing.extract_labels(labels)
try:
preprocessed_data = preprocessing.prepare_timeseries(
data, order_by, agg_group_by, units, filters, labels
)
except preprocessing.PreprocessingError:
log_div, log_level = show_logs()
return graphs.get_empty_fig(), [], [], log_div, log_level, *data_div_cls
if preprocessed_data.empty:
flash("No data for current filter settings", "warning")
log_div, log_level = show_logs()
return graphs.get_empty_fig(), [], [], log_div, log_level, *data_div_cls
try:
fig = graphs.get_timeseries_plot(preprocessed_data, graph_options)
except graphs.PlottingError:
log_div, log_level = show_logs()
return graphs.get_empty_fig(), [], [], log_div, log_level, *data_div_cls
if show_data:
columns = [{"name": i, "id": i} for i in preprocessed_data.columns]
data_table = preprocessed_data.applymap(str).to_dict("records")
else:
columns = []
data_table = []
log_div, log_level = show_logs()
return fig, data_table, columns, log_div, log_level, *data_div_cls
def show_logs():
errors = get_flashed_messages(category_filter=["error"])
warnings = get_flashed_messages(category_filter=["warning"])
if len(warnings) > MAX_WARNINGS:
warnings = warnings[:MAX_WARNINGS]
warnings.append(
f"Too many warnings (>{MAX_WARNINGS}) - Skipping further warnings..."
)
infos = get_flashed_messages(category_filter=["info"])
if len(infos) > MAX_INFOS:
infos = infos[:MAX_INFOS]
infos.append(f"Too many infos (>{MAX_INFOS}) - Skipping further infos...")
level = "infos"
if errors:
level = "errors"
elif warnings:
level = "warnings"
return get_error_and_warnings_div(errors, warnings, infos), level
if __name__ == "__main__":
app.run_server(
debug=DEBUG, use_debugger=False, use_reloader=False, passthrough_errors=True
)