-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
113 lines (94 loc) · 3.72 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
from dash import Dash, html, dcc, Input, Output
import dash_bootstrap_components as dbc
import dash_daq as daq
from data_source.botcity import BotcityApiPlugin
from data_access.botcity import BotcityDataAccess
from components.tasks_grid import build_tasks_grid
from components.schedules_grid import build_schedules_grid
from components.runners_grid import build_runners_grid
from components.connections_grid import build_connections_grid
from typing import Hashable, Dict, List, Any
from app import configurations as config
# iniciando app dash
app = Dash(__name__, external_stylesheets=[dbc.themes.DARKLY], title='BotCity Dashboard')
# iniciando acesso ao botcity
dso_botcity = BotcityApiPlugin(login=config.MAESTRO_LOGIN, key=config.MAESTRO_KEY)
dao_botcity = BotcityDataAccess(dso_botcity)
# montando grids
tasks_grid = build_tasks_grid()
schedules_grid = build_schedules_grid()
runners_grid = build_runners_grid()
connections_grid = build_connections_grid()
# desenhando o layout do dashboard
app.layout = dbc.Container(
[
dbc.Row(
[
dbc.Col(html.Div('BotCity Dashboard', className='h2 p-2 text-white'), className='py-2'),
dbc.Col(html.Div(
[daq.BooleanSwitch(on=True, label='Refresh Automático', id='refresh-switch', color="#9B51E0")]),
className='py-2')
]
),
dbc.Row(
[
html.Div(
[
html.H5('Últimas 100 tarefas executadas', className='h5 p-2 text-white'),
dbc.Col(tasks_grid, className='py-1')
]
)
]
),
dbc.Row(
[
dbc.Col(
html.Div(
[
html.H5('Tarefas agendadas', className='h5 p-2 text-white'),
schedules_grid
]
), className='py-1'
),
dbc.Col(
html.Div(
[
html.H5('Disponibilidade dos runners', className='h5 p-2 text-white'),
runners_grid
]
), className='py-1'
),
dbc.Col(
html.Div(
[
html.H5('Disponibilidade dos sistemas', className='h5 p-2 text-white'),
connections_grid
]
), className='py-1'
),
]
),
dcc.Interval(id='refresh-interval', interval=180 * 1000, n_intervals=0),
]
)
######################################################################
# As Callback são funções executadas quando um evento refresh ocorre.#
######################################################################
@app.callback(Output('refresh-interval', 'disabled'),
Input('refresh-switch', 'on'))
def switch_interval(on: bool) -> bool:
return not on
@app.callback(Output('tasks-grid', 'rowData'),
Input('refresh-interval', 'n_intervals'))
def refresh_tasks_grid(_) -> List[Dict[Hashable, Any]]:
return dao_botcity.get_tasks_data()
@app.callback(Output('schedules-grid', 'rowData'),
Input('refresh-interval', 'n_intervals'))
def refresh_schedules_grid(_) -> List[Dict[Hashable, Any]]:
return dao_botcity.get_schedules_data()
@app.callback(Output('runners-grid', 'rowData'),
Input('refresh-interval', 'n_intervals'))
def refresh_runners_grid(_) -> List[Dict[Hashable, Any]]:
return dao_botcity.get_runners_data()
if __name__ == '__main__':
app.run(debug=True)