updates
Browse files- app.py +7 -10
- static/script.js +0 -4
- templates/host.html +1 -2
app.py
CHANGED
@@ -47,14 +47,19 @@ def on_leave():
|
|
47 |
emit('update_participants', {"participants": participants, "count": len(participants)}, room='quiz')
|
48 |
print(f"{username} left the quiz.")
|
49 |
|
50 |
-
@socketio.on('
|
|
|
|
|
|
|
|
|
|
|
51 |
def start_quiz():
|
52 |
-
reset_quiz() # Reset the quiz state before starting
|
53 |
current_question['started'] = True
|
54 |
index = current_question['index']
|
55 |
if index < len(questions):
|
56 |
question = questions[index]
|
57 |
emit('new_question', question, room='quiz')
|
|
|
58 |
|
59 |
@socketio.on('submit_answer')
|
60 |
def receive_answer(data):
|
@@ -85,8 +90,6 @@ def check_answers():
|
|
85 |
if current_question['answers'].get(participant["username"]) == correct_answer:
|
86 |
participants[sid]["score"] += 1
|
87 |
|
88 |
-
emit('enable_end_quiz', room='quiz') # Enable the "End Quiz" button
|
89 |
-
|
90 |
@socketio.on('next_question')
|
91 |
def next_question():
|
92 |
current_question['index'] += 1
|
@@ -104,12 +107,6 @@ def end_quiz():
|
|
104 |
final_results = calculate_final_results()
|
105 |
emit('display_final_results', final_results, room='quiz')
|
106 |
|
107 |
-
@socketio.on('restart_quiz')
|
108 |
-
def restart_quiz():
|
109 |
-
reset_quiz()
|
110 |
-
emit('quiz_reset', room='quiz')
|
111 |
-
start_quiz() # Automatically start the quiz again after reset
|
112 |
-
|
113 |
def generate_chart(answers, options):
|
114 |
counts = [list(answers.values()).count(option) for option in options]
|
115 |
plt.figure(figsize=(6, 4))
|
|
|
47 |
emit('update_participants', {"participants": participants, "count": len(participants)}, room='quiz')
|
48 |
print(f"{username} left the quiz.")
|
49 |
|
50 |
+
@socketio.on('restart_quiz')
|
51 |
+
def restart_quiz():
|
52 |
+
reset_quiz() # Reset the quiz state
|
53 |
+
emit('quiz_reset', room='quiz')
|
54 |
+
start_quiz() # Automatically start the quiz after reset
|
55 |
+
|
56 |
def start_quiz():
|
|
|
57 |
current_question['started'] = True
|
58 |
index = current_question['index']
|
59 |
if index < len(questions):
|
60 |
question = questions[index]
|
61 |
emit('new_question', question, room='quiz')
|
62 |
+
emit('enable_end_quiz', room='quiz') # Enable the "End Quiz" button when the quiz starts
|
63 |
|
64 |
@socketio.on('submit_answer')
|
65 |
def receive_answer(data):
|
|
|
90 |
if current_question['answers'].get(participant["username"]) == correct_answer:
|
91 |
participants[sid]["score"] += 1
|
92 |
|
|
|
|
|
93 |
@socketio.on('next_question')
|
94 |
def next_question():
|
95 |
current_question['index'] += 1
|
|
|
107 |
final_results = calculate_final_results()
|
108 |
emit('display_final_results', final_results, room='quiz')
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
def generate_chart(answers, options):
|
111 |
counts = [list(answers.values()).count(option) for option in options]
|
112 |
plt.figure(figsize=(6, 4))
|
static/script.js
CHANGED
@@ -29,10 +29,6 @@ function submitAnswer(answer) {
|
|
29 |
socket.emit('submit_answer', { answer: answer });
|
30 |
}
|
31 |
|
32 |
-
function startQuiz() {
|
33 |
-
socket.emit('start_quiz');
|
34 |
-
}
|
35 |
-
|
36 |
function checkAnswers() {
|
37 |
socket.emit('check_answers');
|
38 |
}
|
|
|
29 |
socket.emit('submit_answer', { answer: answer });
|
30 |
}
|
31 |
|
|
|
|
|
|
|
|
|
32 |
function checkAnswers() {
|
33 |
socket.emit('check_answers');
|
34 |
}
|
templates/host.html
CHANGED
@@ -10,11 +10,10 @@
|
|
10 |
<div class="container">
|
11 |
<h2>Quiz Host</h2>
|
12 |
<p>Participants connected: <span id="participant-count">0</span></p>
|
13 |
-
<button onclick="
|
14 |
<button onclick="checkAnswers()" class="btn btn-primary mt-2">Check Answers</button>
|
15 |
<button onclick="nextQuestion()" class="btn btn-secondary mt-2">Next Question</button>
|
16 |
<button onclick="endQuiz()" id="end-quiz" class="btn btn-danger mt-2" disabled>End Quiz</button>
|
17 |
-
<button onclick="restartQuiz()" class="btn btn-warning mt-2">Start New Quiz</button>
|
18 |
<h3 id="question-text" class="mt-4"></h3>
|
19 |
<div id="options" class="mt-2"></div>
|
20 |
<div id="results" class="mt-4"></div>
|
|
|
10 |
<div class="container">
|
11 |
<h2>Quiz Host</h2>
|
12 |
<p>Participants connected: <span id="participant-count">0</span></p>
|
13 |
+
<button onclick="restartQuiz()" class="btn btn-success mt-3">Start New Quiz</button>
|
14 |
<button onclick="checkAnswers()" class="btn btn-primary mt-2">Check Answers</button>
|
15 |
<button onclick="nextQuestion()" class="btn btn-secondary mt-2">Next Question</button>
|
16 |
<button onclick="endQuiz()" id="end-quiz" class="btn btn-danger mt-2" disabled>End Quiz</button>
|
|
|
17 |
<h3 id="question-text" class="mt-4"></h3>
|
18 |
<div id="options" class="mt-2"></div>
|
19 |
<div id="results" class="mt-4"></div>
|