First commit
Browse files- __pycache__/backend.cpython-312.pyc +0 -0
- app.py +10 -8
- static/script.js +5 -1
- templates/host.html +6 -3
__pycache__/backend.cpython-312.pyc
CHANGED
Binary files a/__pycache__/backend.cpython-312.pyc and b/__pycache__/backend.cpython-312.pyc differ
|
|
app.py
CHANGED
@@ -46,18 +46,20 @@ def on_leave():
|
|
46 |
print(f"{username} left the quiz.")
|
47 |
|
48 |
@socketio.on('select_exam')
|
49 |
-
def select_exam(
|
50 |
global selected_questions
|
|
|
|
|
51 |
selected_questions = backend.select_exam(exam_name)
|
52 |
if selected_questions:
|
53 |
-
|
|
|
|
|
54 |
else:
|
55 |
emit('exam_loaded', {"success": False, "exam_name": exam_name}, room=request.sid)
|
56 |
|
57 |
@socketio.on('restart_quiz')
|
58 |
def restart_quiz():
|
59 |
-
reset_quiz()
|
60 |
-
emit('quiz_reset', room='quiz')
|
61 |
start_quiz()
|
62 |
|
63 |
def start_quiz():
|
@@ -73,8 +75,7 @@ def receive_answer(data):
|
|
73 |
username = participants[request.sid]["username"]
|
74 |
answer = data['answer']
|
75 |
current_question['answers'][username] = answer
|
76 |
-
|
77 |
-
emit('all_answers_received', room='quiz')
|
78 |
|
79 |
@socketio.on('check_answers')
|
80 |
def check_answers():
|
@@ -113,9 +114,10 @@ def end_quiz():
|
|
113 |
emit('display_final_results', final_results, room='quiz')
|
114 |
|
115 |
def generate_chart(answers, options):
|
|
|
116 |
counts = [list(answers.values()).count(option) for option in options]
|
117 |
plt.figure(figsize=(6, 4))
|
118 |
-
plt.bar(options, counts)
|
119 |
plt.xlabel('Options')
|
120 |
plt.ylabel('Number of Votes')
|
121 |
plt.title('Results')
|
@@ -138,4 +140,4 @@ def reset_quiz():
|
|
138 |
participant["score"] = 0
|
139 |
|
140 |
if __name__ == '__main__':
|
141 |
-
socketio.run(app, debug=True)
|
|
|
46 |
print(f"{username} left the quiz.")
|
47 |
|
48 |
@socketio.on('select_exam')
|
49 |
+
def select_exam(data):
|
50 |
global selected_questions
|
51 |
+
exam_name = data['exam_name']
|
52 |
+
start_question = data['start_question'] - 1 # Adjust for 0-based indexing
|
53 |
selected_questions = backend.select_exam(exam_name)
|
54 |
if selected_questions:
|
55 |
+
num_questions = len(selected_questions)
|
56 |
+
current_question['index'] = start_question
|
57 |
+
emit('exam_loaded', {"success": True, "exam_name": exam_name, "num_questions": num_questions, "start_question": start_question + 1}, room=request.sid)
|
58 |
else:
|
59 |
emit('exam_loaded', {"success": False, "exam_name": exam_name}, room=request.sid)
|
60 |
|
61 |
@socketio.on('restart_quiz')
|
62 |
def restart_quiz():
|
|
|
|
|
63 |
start_quiz()
|
64 |
|
65 |
def start_quiz():
|
|
|
75 |
username = participants[request.sid]["username"]
|
76 |
answer = data['answer']
|
77 |
current_question['answers'][username] = answer
|
78 |
+
print(f"{username} submitted an answer: {answer}")
|
|
|
79 |
|
80 |
@socketio.on('check_answers')
|
81 |
def check_answers():
|
|
|
114 |
emit('display_final_results', final_results, room='quiz')
|
115 |
|
116 |
def generate_chart(answers, options):
|
117 |
+
letters = ['A', 'B', 'C', 'D']
|
118 |
counts = [list(answers.values()).count(option) for option in options]
|
119 |
plt.figure(figsize=(6, 4))
|
120 |
+
plt.bar(letters[:len(options)], counts)
|
121 |
plt.xlabel('Options')
|
122 |
plt.ylabel('Number of Votes')
|
123 |
plt.title('Results')
|
|
|
140 |
participant["score"] = 0
|
141 |
|
142 |
if __name__ == '__main__':
|
143 |
+
socketio.run(app, debug=True)
|
static/script.js
CHANGED
@@ -25,11 +25,14 @@ function submitForm(event) {
|
|
25 |
|
26 |
function selectExam() {
|
27 |
const examName = document.getElementById('exam-selector').value;
|
28 |
-
|
|
|
29 |
}
|
30 |
|
31 |
socket.on('exam_loaded', (data) => {
|
32 |
if (data.success) {
|
|
|
|
|
33 |
alert(`Exam "${data.exam_name}" loaded successfully!`);
|
34 |
} else {
|
35 |
alert(`Failed to load exam "${data.exam_name}".`);
|
@@ -49,6 +52,7 @@ socket.on('new_question', (data) => {
|
|
49 |
<label for="${letters[index]}">${letters[index]}) ${opt}</label><br>`
|
50 |
).join('');
|
51 |
document.getElementById('options').innerHTML = options;
|
|
|
52 |
});
|
53 |
|
54 |
function checkAnswers() {
|
|
|
25 |
|
26 |
function selectExam() {
|
27 |
const examName = document.getElementById('exam-selector').value;
|
28 |
+
const startQuestion = document.getElementById('start-question').value;
|
29 |
+
socket.emit('select_exam', { exam_name: examName, start_question: parseInt(startQuestion) });
|
30 |
}
|
31 |
|
32 |
socket.on('exam_loaded', (data) => {
|
33 |
if (data.success) {
|
34 |
+
document.getElementById('question-count').textContent =
|
35 |
+
`Exam "${data.exam_name}" loaded with ${data.num_questions} questions. Starting from question ${data.start_question}.`;
|
36 |
alert(`Exam "${data.exam_name}" loaded successfully!`);
|
37 |
} else {
|
38 |
alert(`Failed to load exam "${data.exam_name}".`);
|
|
|
52 |
<label for="${letters[index]}">${letters[index]}) ${opt}</label><br>`
|
53 |
).join('');
|
54 |
document.getElementById('options').innerHTML = options;
|
55 |
+
document.getElementById('end-quiz').disabled = false;
|
56 |
});
|
57 |
|
58 |
function checkAnswers() {
|
templates/host.html
CHANGED
@@ -17,9 +17,12 @@
|
|
17 |
<option value="{{ exam }}">{{ exam }}</option>
|
18 |
{% endfor %}
|
19 |
</select>
|
20 |
-
<
|
21 |
-
<
|
22 |
-
<
|
|
|
|
|
|
|
23 |
<button onclick="endQuiz()" id="end-quiz" class="btn btn-danger mt-2" disabled>End Quiz</button>
|
24 |
<div id="question-section" class="mt-4">
|
25 |
<p id="question-text"></p>
|
|
|
17 |
<option value="{{ exam }}">{{ exam }}</option>
|
18 |
{% endfor %}
|
19 |
</select>
|
20 |
+
<p id="question-count" style="margin-top: 15px;"></p>
|
21 |
+
<label for="start-question" class="mt-3">Select starting question:</label>
|
22 |
+
<input type="range" id="start-question" min="1" max="10" value="1" class="form-range mt-2 mb-4">
|
23 |
+
<button onclick="restartQuiz()" class="btn btn-success mt-3">Start New Quiz</button><br><br>
|
24 |
+
<button onclick="checkAnswers()" class="btn btn-primary mt-2">Check Answers</button><br><br>
|
25 |
+
<button onclick="nextQuestion()" class="btn btn-secondary mt-2">Next Question</button><br><br>
|
26 |
<button onclick="endQuiz()" id="end-quiz" class="btn btn-danger mt-2" disabled>End Quiz</button>
|
27 |
<div id="question-section" class="mt-4">
|
28 |
<p id="question-text"></p>
|