ruslanmv commited on
Commit
98898c2
·
1 Parent(s): e676f90
Files changed (2) hide show
  1. app.py +5 -4
  2. static/script.js +5 -4
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from flask import Flask, render_template, request
2
  from flask_socketio import SocketIO, emit, join_room, leave_room
3
  import backend # Import backend functions
@@ -63,8 +64,8 @@ def start_quiz():
63
  if participants and selected_questions:
64
  current_question['started'] = True
65
  emit('new_question', selected_questions[current_question['index']], room='quiz')
66
- # Also emit the question to the host
67
- emit('new_question', selected_questions[current_question['index']], room=request.sid)
68
  emit('enable_end_quiz', room='quiz')
69
 
70
  @socketio.on('restart_quiz')
@@ -108,7 +109,7 @@ def next_question():
108
  emit('clear_results', room='quiz')
109
  emit('new_question', question, room='quiz')
110
  # Also emit the question to the host
111
- emit('new_question', question, room=request.sid)
112
  else:
113
  final_results = calculate_final_results()
114
  emit('display_final_results', final_results, room='quiz')
@@ -119,7 +120,7 @@ def end_quiz():
119
  emit('display_final_results', final_results, room='quiz')
120
 
121
  def generate_chart(answers, options):
122
- letters = [chr(65 + i) for i in range(len(options))]
123
  counts = [list(answers.values()).count(option) for option in options]
124
  plt.figure(figsize=(6, 4))
125
  plt.bar(letters, counts)
 
1
+ # app.py
2
  from flask import Flask, render_template, request
3
  from flask_socketio import SocketIO, emit, join_room, leave_room
4
  import backend # Import backend functions
 
64
  if participants and selected_questions:
65
  current_question['started'] = True
66
  emit('new_question', selected_questions[current_question['index']], room='quiz')
67
+ # Also emit the question to the host
68
+ emit('new_question', selected_questions[current_question['index']], room=request.sid)
69
  emit('enable_end_quiz', room='quiz')
70
 
71
  @socketio.on('restart_quiz')
 
109
  emit('clear_results', room='quiz')
110
  emit('new_question', question, room='quiz')
111
  # Also emit the question to the host
112
+ emit('new_question', question, room=request.sid)
113
  else:
114
  final_results = calculate_final_results()
115
  emit('display_final_results', final_results, room='quiz')
 
120
  emit('display_final_results', final_results, room='quiz')
121
 
122
  def generate_chart(answers, options):
123
+ letters = [chr(65 + i) for i in range(len(options))] # Dynamically generate letters for options
124
  counts = [list(answers.values()).count(option) for option in options]
125
  plt.figure(figsize=(6, 4))
126
  plt.bar(letters, counts)
static/script.js CHANGED
@@ -72,10 +72,11 @@ socket.on('quiz_loaded', (data) => {
72
  socket.on('new_question', (data) => {
73
  document.getElementById('waiting-message').style.display = 'none';
74
  document.getElementById('question-text').innerText = data.question;
75
- const letters = ['a', 'b', 'c', 'd'];
 
76
  const options = data.options.map((opt, index) =>
77
  `<input type="radio" id="${letters[index]}" name="answer" value="${opt}">
78
- <label for="${letters[index]}">${letters[index]}) ${opt}</label><br>`
79
  ).join('');
80
  document.getElementById('options').innerHTML = options;
81
  });
@@ -87,7 +88,7 @@ socket.on('display_results', (data) => {
87
  });
88
 
89
  socket.on('enable_end_quiz', () => {
90
- document.getElementById('end-quiz').disabled = false;
91
  });
92
 
93
  socket.on('clear_results', () => {
@@ -112,4 +113,4 @@ socket.on('quiz_reset', () => {
112
  document.getElementById('final-results').style.display = 'none';
113
  document.getElementById('quiz-content').style.display = 'block';
114
  document.getElementById('waiting-message').style.display = 'block';
115
- });
 
72
  socket.on('new_question', (data) => {
73
  document.getElementById('waiting-message').style.display = 'none';
74
  document.getElementById('question-text').innerText = data.question;
75
+ // Dynamically generate letters for options (up to 'h')
76
+ const letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
77
  const options = data.options.map((opt, index) =>
78
  `<input type="radio" id="${letters[index]}" name="answer" value="${opt}">
79
+ <label for="${letters[index]}">${letters[index]}) ${opt}</label><br>`
80
  ).join('');
81
  document.getElementById('options').innerHTML = options;
82
  });
 
88
  });
89
 
90
  socket.on('enable_end_quiz', () => {
91
+ document.getElementById('end-quiz').disabled = false; // Enable the "End Quiz" button
92
  });
93
 
94
  socket.on('clear_results', () => {
 
113
  document.getElementById('final-results').style.display = 'none';
114
  document.getElementById('quiz-content').style.display = 'block';
115
  document.getElementById('waiting-message').style.display = 'block';
116
+ });