-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuizzapp.py
151 lines (132 loc) · 4.84 KB
/
Quizzapp.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
from dash import Dash, dcc, html, Input, Output, State, callback, dash_table
import dash_bootstrap_components as dbc
import pandas as pd
import datetime
from Task import Task
from Team import Team
# Add some dummy Tasks & Solutions
Tasks = [
Task("Solve 2x=4", 2),
Task("Anglesum in a triangle", 180),
Task("Smallest prime", 2)
]
# Add some Teams and their Auth Tokens.
Teams = [Team(Name, Token) for Name, Token in {
"Blue" : "BERRY",
"Red": "WHINE",
"Yellow": "SUN",
"Green": "TREE"
}.items()
]
app = Dash(__name__, external_stylesheets=[dbc.themes.SKETCHY])
def serve_layout():
time = datetime.datetime.now()
# Get Teams-Table
TeamTable = pd.DataFrame([ {k:v for k, v in T.__dict__.items() if k != 'Submission_History' } for T in Team.Instance_Arr])
TeamTable.index += 1
TeamTable = TeamTable.sort_values(by=['Score'], ascending=False).reindex()
# Get TaskTable
TaskTable = pd.DataFrame([T.__dict__ for T in Task.Instance_Arr])
D ={ i: Task[i].get_current_value() for i in TaskTable['ID'] }
TaskTable['Value'] = TaskTable['ID'].map(D)
return dbc.Container(
[
dbc.Row(
html.H1(f'Game State {time:%H:%M:%S}')
),
dbc.Row(
[
dbc.Col(
[
dcc.Markdown("## Teams"),
dash_table.DataTable(data=TeamTable[['Name', 'Score', 'Joker']].to_dict('records'))
],
width=6,
),
dbc.Col(
[
dcc.Markdown("## Tasks"),
dash_table.DataTable(data=TaskTable[['Value', 'ID', 'Text']].to_dict('records'))
],
width = 6,
)
]
),
html.Br(),
dbc.Row(
[
dbc.Col(
[
dcc.Dropdown(
id = "Task",
options= [f'Task {T.ID}' for T in Task.Instance_Arr] + ['Joker'],
style={"width":"100%"},
placeholder="Submission",
)
],
width=3
),
dbc.Col(
[
dcc.Input(
id = "Submission",
value = "",
type="text",
placeholder="Input",
style={"width":"100%"},
)
],
width=3
),
dbc.Col(
[
dcc.Input(
id = "Token",
value = "",
type="text",
placeholder="Token",
style={"width":"100%"},
)
],
width=3
),
dbc.Button(
"OK", id="Submission-Button", className="me-2", n_clicks=0
)
]
),
html.Span(id="Response", style={"verticalAlign": "middle"}),
]
)
app.layout = serve_layout
@callback(
Output("Response", "children"),
Input('Submission-Button', 'n_clicks'),
State('Task', 'value'),
State('Submission', 'value'),
State('Token', 'value')
)
def on_button_click(n, TaskID, Submission, Token):
if n == 0:
return
else:
T = Team.get_Team(Token)
if T is None:
return "Invalid Token. No changes made.."
if TaskID == 'Joker':
result = T.Pick_Joker(Submission)
if result:
return f'Joker set for Task {Submission}.'
else:
return f'Joker was not set.'
# Strip the Label. Get only the number.
TaskID = int(TaskID[5:])
result = T.Submit(TaskID, int(Submission))
if result == 0:
return "Data was submitted previously. No changes made."
if result > 0:
return f'Correct. {result} Points for Team {T.Name}.'
if result < 0:
return f'Incorrect. {result} Points for Team {T.Name}'
if __name__ == '__main__':
app.run(debug=True, port=5000, host='0.0.0.0')