-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
112 lines (88 loc) · 3.72 KB
/
web.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
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate
from dash import Dash, html, dcc
import dash
from generator.generator import Generator as gen
from processor.processor import Processor as pcc
from settings.constants import Constants as CONST
import pandas as pd
app = Dash(__name__)
author_message = gen.generate_div("author","Desarrollado por Julián Guillermo Zapata Rugeles")
welcome_message = gen.generate_div("description","Viva Air Analitics")
refres_layout = gen.generate_div("refresh_div",[
gen.generate_button("all_time_line", " Línea Tiempo"),
gen.generate_button("change_history"," Históricos "),
gen.generate_button("offline_button"," Data Local "),
gen.generate_button("refresh_button"," Data Remota "),
])
graphic_layout= gen.generate_div("graphic","")
desde = dcc.Dropdown(
id = "desde",
className="desde",
options=[
{'label': ' Medellin ', 'value': 'MDE'},
{'label': ' Santa Marta ', 'value': 'SMR'},
{'label': ' Bogotá ', 'value': 'BOG'},
{'label': ' Pasto ', 'value': 'PSO'},
{'label': ' Cali ', 'value': 'CLO'},
{'label': ' San Andrés ', 'value': 'ADZ'},
],
value='MDE'
)
hacia= dcc.Dropdown(
id = "hacia",
className="hacia",
options=[
{'label': ' Medellin ', 'value': 'MDE'},
{'label': ' Santa Marta ', 'value': 'SMR'},
{'label': ' Bogotá ', 'value': 'BOG'},
{'label': ' Pasto ', 'value': 'PSO'},
{'label': ' Cali ', 'value': 'CLO'},
{'label': ' San Andrés ', 'value': 'ADZ'},
],
value='SMR'
)
travel_selector = gen.generate_div("travel_selector",[desde,hacia,refres_layout])
app.layout = html.Div([
welcome_message,
author_message,
travel_selector,
graphic_layout
])
@app.callback(
Output(component_id='graphic', component_property='children'),
Input(component_id='refresh_button', component_property='n_clicks'),
Input(component_id='desde', component_property='value'),
Input(component_id='hacia', component_property='value'),
Input(component_id='offline_button', component_property='n_clicks'),
Input(component_id='all_time_line', component_property='n_clicks'),
prevent_initiall_call=True
)
def call_back_action(click,desde,hacia,offline,hist):
ctx = dash.callback_context
if not ctx.triggered:
return "ESPERANDO POR ORDENES"
else:
action_id = ctx.triggered[0]['prop_id'].split('.')[0]
if action_id == "refresh_button":
CONST.FROM = desde
CONST.TOWARDS = hacia
pcc.get_dataframe()
load_dataframe = pcc.load_dataframe(CONST.PATH_DATA_SHORT)
graphic = gen.generate_simple_graphic(load_dataframe)
return graphic
elif action_id == "offline_button":
load_dataframe = pcc.load_dataframe(CONST.PATH_DATA_SHORT)
graphic = gen.generate_simple_graphic(load_dataframe)
return graphic
elif action_id == "all_time_line":
load_dataframe1 = pcc.load_dataframe(CONST.PATH_DATA_SHORT)
load_dataframe2 = pcc.load_dataframe(CONST.PATH_INIT_COMPARE)
graphic = gen.generate_timeline_graphic(load_dataframe1,load_dataframe2)
return graphic
else:
CONST.FROM = desde
CONST.TOWARDS = hacia
return f"CONFIGURADO DESDE {CONST.FROM} HACIA {CONST.TOWARDS}"
if __name__ == '__main__':
app.run_server(debug=True)