-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathevent_table.py
116 lines (101 loc) · 4.16 KB
/
event_table.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
#
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the 'Software'),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
import dash
from dash import dcc, html, dash_table, Input, Output
from .card import create_card, card_callback
from server import Server
from datetime import datetime
def create_event_table():
columns = [
dict(id='id', name='ID', hideable=True),
dict(id='1', name='Begin', hideable=True, type='datetime'),
dict(id='2', name='End', hideable=True, type='datetime'),
dict(id='3', name='Frames', hideable=True, type='numeric'),
dict(id='4', name='Stream', hideable=True),
dict(id='5', name='Model', hideable=True),
dict(id='6', name='Class', hideable=True, type='numeric'),
dict(id='7', name='Label', hideable=True),
dict(id='8', name='Score', hideable=True, type='numeric', format=dash_table.FormatTemplate.percentage(1)),
dict(id='9', name='Max Score', hideable=True, type='numeric', format=dash_table.FormatTemplate.percentage(1))
]
"""
style_header={
#'backgroundColor': 'rgb(50, 50, 50)',
#'color': 'white',
'whiteSpace': 'normal',
'height': 'auto',
},
style_data={
#'backgroundColor': 'rgb(70, 70, 70)',
#'color': 'white',
'whiteSpace': 'normal',
'height': 'auto',
'lineHeight': '15px'
},
"""
children = [
dash_table.DataTable(
data=[],
columns=columns,
id='event_table',
page_size=10,
filter_action='native',
filter_options={'case': 'insensitive', 'placeholder_text': 'filter...'},
sort_action='native',
sort_by=[{'column_id': 'id', 'direction': 'desc'}],
css=[{'selector': '.show-hide', 'rule': 'display: none'}],
style_table={'overflowX': 'auto'},
style_data={'font-size': 14}, #'font-family': 'monospace'
),
dcc.Interval(id='event_refresh_timer', interval=500)
]
return create_card(
html.Div(children, className='dbc-row-selectable'),
title=f"Events",
width=6,
height=12,
id='events'
)
@dash.callback(Output('event_table', 'data'),
Input('event_refresh_timer', 'n_intervals'))
def refresh_events(n_intervals):
request = Server.request('/events')
records = request.json()
#date_format = '%Y-%m-%d %H:%M:%S'
#date_format = '%-I:%M:%S %p'
date_format = '%H:%M:%S'
def event_to_dict(event):
d = {
'id': event[0],
'1': datetime.fromtimestamp(event[1]).strftime(date_format),
'2': datetime.fromtimestamp(event[2]).strftime(date_format),
}
for n in range(3, 10):
d[str(n)] = event[n]
return d
return [event_to_dict(event) for event in records]
@card_callback(Input('navbar_event_table', 'n_clicks'))
def open_events(n_clicks):
if n_clicks > 0:
return create_event_table()
else:
return None