ruslanmv commited on
Commit
b2165cc
·
1 Parent(s): 98898c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -1,4 +1,3 @@
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
@@ -66,7 +65,7 @@ def start_quiz():
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')
72
  def restart_quiz():
@@ -116,8 +115,11 @@ def next_question():
116
 
117
  @socketio.on('end_quiz')
118
  def end_quiz():
119
- final_results = calculate_final_results()
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
 
 
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
 
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=request.sid) # Enable "End Quiz" for the host
69
 
70
  @socketio.on('restart_quiz')
71
  def restart_quiz():
 
115
 
116
  @socketio.on('end_quiz')
117
  def end_quiz():
118
+ if current_question['started']: # Ensure the quiz has started before ending it
119
+ final_results = calculate_final_results()
120
+ emit('display_final_results', final_results, room='quiz')
121
+ reset_quiz() # Reset the quiz state
122
+
123
 
124
  def generate_chart(answers, options):
125
  letters = [chr(65 + i) for i in range(len(options))] # Dynamically generate letters for options