Spaces:
Runtime error
Runtime error
Commit
·
d13b59f
1
Parent(s):
d9ce431
Add application file
Browse files- .gradio/certificate.pem +31 -0
- __pycache__/admin_interface.cpython-312.pyc +0 -0
- __pycache__/leaderboards.cpython-312.pyc +0 -0
- __pycache__/player_interface.cpython-312.pyc +0 -0
- __pycache__/quiz_manager.cpython-312.pyc +0 -0
- admin_interface.py +231 -0
- app.py +25 -0
- leaderboards.py +250 -0
- player_interface.py +454 -0
- quiz_data/quiz_193449.json +225 -0
- quiz_data/quiz_620321.json +5 -0
- quiz_data/quiz_655067.json +5 -0
- quiz_data/quiz_772319.json +9 -0
- quiz_data/quiz_854464.json +228 -0
- quiz_data/quiz_925005.json +210 -0
- quiz_manager.py +106 -0
- qursioms.csv +21 -0
- requirements.txt +1 -0
.gradio/certificate.pem
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN CERTIFICATE-----
|
| 2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
| 3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
| 4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
| 5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
| 6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
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ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ
|
| 22 |
+
3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK
|
| 23 |
+
NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
|
| 24 |
+
ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
|
| 25 |
+
TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
|
| 26 |
+
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
| 27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
| 28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
| 29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
| 30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
| 31 |
+
-----END CERTIFICATE-----
|
__pycache__/admin_interface.cpython-312.pyc
ADDED
|
Binary file (13.7 kB). View file
|
|
|
__pycache__/leaderboards.cpython-312.pyc
ADDED
|
Binary file (11.1 kB). View file
|
|
|
__pycache__/player_interface.cpython-312.pyc
ADDED
|
Binary file (17.8 kB). View file
|
|
|
__pycache__/quiz_manager.cpython-312.pyc
ADDED
|
Binary file (6.89 kB). View file
|
|
|
admin_interface.py
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import os
|
| 4 |
+
from quiz_manager import quiz_manager
|
| 5 |
+
|
| 6 |
+
class AdminInterface:
|
| 7 |
+
def __init__(self):
|
| 8 |
+
self.current_game_pin = None
|
| 9 |
+
|
| 10 |
+
def create_new_quiz(self, quiz_name):
|
| 11 |
+
"""Create a new quiz and generate a game pin."""
|
| 12 |
+
try:
|
| 13 |
+
game_pin = quiz_manager.create_quiz(quiz_name)
|
| 14 |
+
self.current_game_pin = game_pin
|
| 15 |
+
return f"Quiz created successfully! Game Pin: {game_pin}", game_pin
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return f"Error creating quiz: {str(e)}", None
|
| 18 |
+
|
| 19 |
+
def set_current_quiz(self, game_pin):
|
| 20 |
+
"""Set the current game pin."""
|
| 21 |
+
if game_pin in quiz_manager.quizzes:
|
| 22 |
+
self.current_game_pin = game_pin
|
| 23 |
+
return f"Current quiz set to: {game_pin}"
|
| 24 |
+
else:
|
| 25 |
+
return f"Invalid Game Pin: {game_pin}"
|
| 26 |
+
|
| 27 |
+
def add_question(self, question_text, option1, option2, option3, option4, correct_answer):
|
| 28 |
+
"""Add a question to the current quiz."""
|
| 29 |
+
if not self.current_game_pin:
|
| 30 |
+
return "Please create or select a quiz first!"
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
options = [option1.strip(), option2.strip(), option3.strip(), option4.strip()]
|
| 34 |
+
if correct_answer not in options:
|
| 35 |
+
return "Correct answer must be one of the options."
|
| 36 |
+
quiz_manager.add_question(self.current_game_pin, question_text, options, correct_answer)
|
| 37 |
+
return "Question added successfully!"
|
| 38 |
+
except Exception as e:
|
| 39 |
+
return f"Error adding question: {str(e)}"
|
| 40 |
+
|
| 41 |
+
def load_questions_from_csv(self, csv_file):
|
| 42 |
+
"""Load questions from a CSV file for the current quiz."""
|
| 43 |
+
if not self.current_game_pin:
|
| 44 |
+
return "Please create or select a quiz first!"
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
df = pd.read_csv(csv_file.name)
|
| 48 |
+
if 'question' not in df.columns or 'option1' not in df.columns or 'option2' not in df.columns or 'option3' not in df.columns or 'option4' not in df.columns or 'correct_answer' not in df.columns:
|
| 49 |
+
return "CSV file must contain columns: question, option1, option2, option3, option4, correct_answer"
|
| 50 |
+
|
| 51 |
+
success_count = 0
|
| 52 |
+
fail_count = 0
|
| 53 |
+
fail_reasons = []
|
| 54 |
+
|
| 55 |
+
for index, row in df.iterrows():
|
| 56 |
+
question_text = row['question']
|
| 57 |
+
options = [row['option1'].strip(), row['option2'].strip(), row['option3'].strip(), row['option4'].strip()]
|
| 58 |
+
correct_answer = row['correct_answer'].strip()
|
| 59 |
+
|
| 60 |
+
if correct_answer not in options:
|
| 61 |
+
fail_count += 1
|
| 62 |
+
fail_reasons.append(f"Row {index + 2}: Correct answer '{correct_answer}' not in options.")
|
| 63 |
+
continue
|
| 64 |
+
|
| 65 |
+
try:
|
| 66 |
+
quiz_manager.add_question(self.current_game_pin, question_text, options, correct_answer)
|
| 67 |
+
success_count += 1
|
| 68 |
+
except Exception as e:
|
| 69 |
+
fail_count += 1
|
| 70 |
+
fail_reasons.append(f"Row {index + 2}: Error adding question - {str(e)}")
|
| 71 |
+
|
| 72 |
+
message = f"Successfully added {success_count} questions. Failed to add {fail_count} questions."
|
| 73 |
+
if fail_reasons:
|
| 74 |
+
message += "\nDetails:\n" + "\n".join(fail_reasons)
|
| 75 |
+
return message
|
| 76 |
+
except Exception as e:
|
| 77 |
+
return f"Error loading CSV file: {str(e)}"
|
| 78 |
+
finally:
|
| 79 |
+
if csv_file:
|
| 80 |
+
os.remove(csv_file.name) # Clean up temporary file
|
| 81 |
+
|
| 82 |
+
def add_contestant(self, contestant_name):
|
| 83 |
+
"""Add a contestant to the current quiz."""
|
| 84 |
+
if not self.current_game_pin:
|
| 85 |
+
return "Please create or select a quiz first!"
|
| 86 |
+
|
| 87 |
+
try:
|
| 88 |
+
quiz_manager.initialize_player_score(self.current_game_pin, contestant_name)
|
| 89 |
+
return f"{contestant_name} added to the quiz!"
|
| 90 |
+
except Exception as e:
|
| 91 |
+
return f"Error adding contestant: {str(e)}"
|
| 92 |
+
|
| 93 |
+
def record_contestant_answer(self, contestant_name, question_number, selected_answer):
|
| 94 |
+
"""Record a contestant's answer."""
|
| 95 |
+
if not self.current_game_pin:
|
| 96 |
+
return "Please create or select a quiz first!"
|
| 97 |
+
|
| 98 |
+
try:
|
| 99 |
+
quiz = quiz_manager.get_quiz(self.current_game_pin)
|
| 100 |
+
if not quiz or not quiz['questions'] or question_number > len(quiz['questions']) or question_number < 1:
|
| 101 |
+
return "Invalid question number."
|
| 102 |
+
|
| 103 |
+
correct_answer = quiz['questions'][question_number - 1]['correct_answer']
|
| 104 |
+
is_correct = selected_answer == correct_answer
|
| 105 |
+
quiz_manager.record_answer(self.current_game_pin, contestant_name, is_correct)
|
| 106 |
+
return f"Answer recorded for {contestant_name} for Question {question_number}."
|
| 107 |
+
except Exception as e:
|
| 108 |
+
return f"Error recording answer: {str(e)}"
|
| 109 |
+
|
| 110 |
+
def get_leaderboard(self):
|
| 111 |
+
"""Retrieve the current leaderboard."""
|
| 112 |
+
if not self.current_game_pin:
|
| 113 |
+
return "Please create or select a quiz first!"
|
| 114 |
+
|
| 115 |
+
try:
|
| 116 |
+
leaderboard = quiz_manager.get_leaderboard(self.current_game_pin)
|
| 117 |
+
if not leaderboard:
|
| 118 |
+
return "No scores recorded yet."
|
| 119 |
+
# Format leaderboard for display
|
| 120 |
+
leaderboard_str = "Current Leaderboard:\n"
|
| 121 |
+
for i, (name, data) in enumerate(leaderboard, 1):
|
| 122 |
+
leaderboard_str += f"{i}. {name}: {data['score']} points\n"
|
| 123 |
+
return leaderboard_str
|
| 124 |
+
except Exception as e:
|
| 125 |
+
return f"Error retrieving leaderboard: {str(e)}"
|
| 126 |
+
|
| 127 |
+
def create_admin_interface(self):
|
| 128 |
+
"""Create the Gradio interface for admin."""
|
| 129 |
+
with gr.Blocks() as admin_interface:
|
| 130 |
+
gr.Markdown("## Quiz Admin Panel")
|
| 131 |
+
|
| 132 |
+
current_game_pin_state = gr.State(None)
|
| 133 |
+
|
| 134 |
+
with gr.Row():
|
| 135 |
+
with gr.Column():
|
| 136 |
+
with gr.Accordion("Create New Quiz"):
|
| 137 |
+
quiz_name_input = gr.Textbox(label="Quiz Name")
|
| 138 |
+
create_quiz_btn = gr.Button("Create Quiz")
|
| 139 |
+
create_quiz_output = gr.Textbox(label="Quiz Creation Status")
|
| 140 |
+
game_pin_output = gr.Textbox(label="Game Pin", interactive=False)
|
| 141 |
+
|
| 142 |
+
create_quiz_results = create_quiz_btn.click(
|
| 143 |
+
fn=self.create_new_quiz,
|
| 144 |
+
inputs=quiz_name_input,
|
| 145 |
+
outputs=[create_quiz_output, game_pin_output]
|
| 146 |
+
)
|
| 147 |
+
create_quiz_results.then(lambda pin: pin, inputs=game_pin_output, outputs=current_game_pin_state)
|
| 148 |
+
|
| 149 |
+
with gr.Accordion("Select Existing Quiz"):
|
| 150 |
+
existing_pin_input = gr.Textbox(label="Enter Game Pin")
|
| 151 |
+
select_quiz_btn = gr.Button("Select Quiz")
|
| 152 |
+
select_quiz_output = gr.Textbox(label="Quiz Selection Status")
|
| 153 |
+
select_quiz_btn.click(
|
| 154 |
+
fn=self.set_current_quiz,
|
| 155 |
+
inputs=existing_pin_input,
|
| 156 |
+
outputs=select_quiz_output
|
| 157 |
+
).then(lambda pin: pin, inputs=existing_pin_input, outputs=current_game_pin_state)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
with gr.Column():
|
| 162 |
+
with gr.Accordion("Add Question"):
|
| 163 |
+
question_text = gr.Textbox(label="Question Text")
|
| 164 |
+
option1 = gr.Textbox(label="Option 1")
|
| 165 |
+
option2 = gr.Textbox(label="Option 2")
|
| 166 |
+
option3 = gr.Textbox(label="Option 3")
|
| 167 |
+
option4 = gr.Textbox(label="Option 4")
|
| 168 |
+
correct_answer = gr.Dropdown(
|
| 169 |
+
choices=["Option 1", "Option 2", "Option 3", "Option 4"],
|
| 170 |
+
label="Correct Answer"
|
| 171 |
+
)
|
| 172 |
+
add_question_btn = gr.Button("Add Question")
|
| 173 |
+
add_question_output = gr.Textbox(label="Add Question Status")
|
| 174 |
+
|
| 175 |
+
add_question_btn.click(
|
| 176 |
+
fn=self.add_question,
|
| 177 |
+
inputs=[question_text, option1, option2, option3, option4, correct_answer],
|
| 178 |
+
outputs=add_question_output,
|
| 179 |
+
# requires=current_game_pin_state # Conditional execution based on state
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
with gr.Accordion("Upload Questions from CSV"):
|
| 183 |
+
csv_upload = gr.File(file_types=[".csv"])
|
| 184 |
+
upload_btn = gr.Button("Upload CSV")
|
| 185 |
+
upload_output = gr.Textbox(label="CSV Upload Status")
|
| 186 |
+
upload_btn.click(
|
| 187 |
+
fn=self.load_questions_from_csv,
|
| 188 |
+
inputs=csv_upload,
|
| 189 |
+
outputs=upload_output,
|
| 190 |
+
# requires=current_game_pin_state
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
with gr.Accordion("Manage Contestants"):
|
| 194 |
+
with gr.Row():
|
| 195 |
+
contestant_name = gr.Textbox(label="Contestant Name")
|
| 196 |
+
add_contestant_btn = gr.Button("Add Contestant")
|
| 197 |
+
add_contestant_output = gr.Textbox(label="Add Contestant Status")
|
| 198 |
+
add_contestant_btn.click(
|
| 199 |
+
fn=self.add_contestant,
|
| 200 |
+
inputs=contestant_name,
|
| 201 |
+
outputs=add_contestant_output,
|
| 202 |
+
# requires=current_game_pin_state
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
with gr.Row():
|
| 206 |
+
answer_contestant_name = gr.Textbox(label="Contestant Name")
|
| 207 |
+
question_number = gr.Number(label="Question Number", precision=0)
|
| 208 |
+
selected_answer = gr.Textbox(label="Selected Answer")
|
| 209 |
+
record_answer_btn = gr.Button("Record Answer")
|
| 210 |
+
record_answer_output = gr.Textbox(label="Record Answer Status")
|
| 211 |
+
record_answer_btn.click(
|
| 212 |
+
fn=self.record_contestant_answer,
|
| 213 |
+
inputs=[answer_contestant_name, question_number, selected_answer],
|
| 214 |
+
outputs=record_answer_output,
|
| 215 |
+
# requires=current_game_pin_state
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
with gr.Accordion("Leaderboard"):
|
| 219 |
+
get_leaderboard_btn = gr.Button("Get Leaderboard")
|
| 220 |
+
leaderboard_output = gr.Textbox(label="Leaderboard")
|
| 221 |
+
get_leaderboard_btn.click(
|
| 222 |
+
fn=self.get_leaderboard,
|
| 223 |
+
outputs=leaderboard_output,
|
| 224 |
+
# requires=current_game_pin_state
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
return admin_interface
|
| 228 |
+
|
| 229 |
+
# Create and launch the admin interface
|
| 230 |
+
admin_interface = AdminInterface()
|
| 231 |
+
admin_gradio_interface = admin_interface.create_admin_interface()
|
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from admin_interface import admin_gradio_interface
|
| 3 |
+
from player_interface import player_gradio_interface
|
| 4 |
+
from leaderboards import leaderboard_gradio_interface
|
| 5 |
+
|
| 6 |
+
def main():
|
| 7 |
+
# Create a tabbed interface with Admin and Player interfaces
|
| 8 |
+
with gr.Blocks() as app:
|
| 9 |
+
gr.Markdown("# Quiz Game")
|
| 10 |
+
|
| 11 |
+
with gr.Tabs():
|
| 12 |
+
with gr.TabItem("Player", id="player"):
|
| 13 |
+
player_gradio_interface.render()
|
| 14 |
+
|
| 15 |
+
with gr.TabItem("Admin", id="admin"):
|
| 16 |
+
admin_gradio_interface.render()
|
| 17 |
+
|
| 18 |
+
with gr.TabItem("Leaderboard", id="leaderboard"):
|
| 19 |
+
leaderboard_gradio_interface.render()
|
| 20 |
+
|
| 21 |
+
# Launch the app
|
| 22 |
+
app.launch(share=True)
|
| 23 |
+
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
main()
|
leaderboards.py
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
import gradio as gr
|
| 3 |
+
import pandas as pd
|
| 4 |
+
# Assuming quiz_manager is in a separate file named quiz_manager.py
|
| 5 |
+
# and has a 'quizzes' attribute and 'get_leaderboard' method.
|
| 6 |
+
from quiz_manager import quiz_manager
|
| 7 |
+
|
| 8 |
+
class LeaderboardInterface:
|
| 9 |
+
def __init__(self):
|
| 10 |
+
self.current_game_pin = None
|
| 11 |
+
# Create the interface once and store it
|
| 12 |
+
self.leaderboard_gradio_interface = self.create_leaderboard_interface()
|
| 13 |
+
|
| 14 |
+
def set_current_quiz(self, game_pin):
|
| 15 |
+
"""Set the current game pin."""
|
| 16 |
+
# Assuming quiz_manager.quizzes is a dictionary holding quiz data
|
| 17 |
+
if game_pin in quiz_manager.quizzes:
|
| 18 |
+
self.current_game_pin = game_pin
|
| 19 |
+
# Update the dropdown choices after setting quiz
|
| 20 |
+
return f"Current quiz set to: {game_pin}"
|
| 21 |
+
else:
|
| 22 |
+
# Reset current_game_pin if the pin is invalid
|
| 23 |
+
self.current_game_pin = None
|
| 24 |
+
return f"Invalid Game Pin: {game_pin}"
|
| 25 |
+
|
| 26 |
+
def get_current_contestants(self):
|
| 27 |
+
"""Get list of contestants for the current quiz."""
|
| 28 |
+
if not self.current_game_pin:
|
| 29 |
+
return []
|
| 30 |
+
try:
|
| 31 |
+
# Try getting the leaderboard first, which seems to have the player data
|
| 32 |
+
leaderboard = quiz_manager.get_leaderboard(self.current_game_pin)
|
| 33 |
+
if isinstance(leaderboard, dict):
|
| 34 |
+
# If leaderboard is a dictionary of player names to scores
|
| 35 |
+
return list(leaderboard.keys())
|
| 36 |
+
elif isinstance(leaderboard, list):
|
| 37 |
+
# If leaderboard is a list of player data
|
| 38 |
+
players = []
|
| 39 |
+
if leaderboard and isinstance(leaderboard[0], dict):
|
| 40 |
+
# If list of dicts with 'name' key
|
| 41 |
+
if 'name' in leaderboard[0]:
|
| 42 |
+
return [player['name'] for player in leaderboard]
|
| 43 |
+
# If list of dicts with player name as keys
|
| 44 |
+
else:
|
| 45 |
+
for player_data in leaderboard:
|
| 46 |
+
players.extend(list(player_data.keys()))
|
| 47 |
+
elif leaderboard and isinstance(leaderboard[0], (list, tuple)):
|
| 48 |
+
# If list of tuples/lists with [name, score_data]
|
| 49 |
+
return [player[0] for player in leaderboard]
|
| 50 |
+
|
| 51 |
+
return players
|
| 52 |
+
|
| 53 |
+
# Fallback to original method if leaderboard approach doesn't work
|
| 54 |
+
quiz = quiz_manager.get_quiz(self.current_game_pin)
|
| 55 |
+
if quiz and 'players' in quiz:
|
| 56 |
+
return list(quiz['players'].keys())
|
| 57 |
+
|
| 58 |
+
# If no players found, return empty list
|
| 59 |
+
return []
|
| 60 |
+
except Exception as e:
|
| 61 |
+
print(f"Error getting contestants: {e}")
|
| 62 |
+
return []
|
| 63 |
+
|
| 64 |
+
def add_contestant(self, contestant_name):
|
| 65 |
+
"""Add a contestant to the current quiz."""
|
| 66 |
+
if not self.current_game_pin:
|
| 67 |
+
return "Please create or select a quiz first!"
|
| 68 |
+
|
| 69 |
+
try:
|
| 70 |
+
quiz_manager.initialize_player_score(self.current_game_pin, contestant_name)
|
| 71 |
+
return f"{contestant_name} added to the quiz!"
|
| 72 |
+
except Exception as e:
|
| 73 |
+
return f"Error adding contestant: {str(e)}"
|
| 74 |
+
|
| 75 |
+
def record_contestant_answer(self, contestant_name, question_number, selected_answer):
|
| 76 |
+
"""Record a contestant's answer."""
|
| 77 |
+
if not self.current_game_pin:
|
| 78 |
+
return "Please create or select a quiz first!"
|
| 79 |
+
|
| 80 |
+
try:
|
| 81 |
+
quiz = quiz_manager.get_quiz(self.current_game_pin)
|
| 82 |
+
if not quiz or not quiz['questions'] or question_number > len(quiz['questions']) or question_number < 1:
|
| 83 |
+
return "Invalid question number."
|
| 84 |
+
|
| 85 |
+
correct_answer = quiz['questions'][question_number - 1]['correct_answer']
|
| 86 |
+
is_correct = selected_answer == correct_answer
|
| 87 |
+
quiz_manager.record_answer(self.current_game_pin, contestant_name, is_correct)
|
| 88 |
+
return f"Answer recorded for {contestant_name} for Question {question_number}."
|
| 89 |
+
except Exception as e:
|
| 90 |
+
return f"Error recording answer: {str(e)}"
|
| 91 |
+
|
| 92 |
+
def get_leaderboard(self):
|
| 93 |
+
"""Retrieve the current leaderboard."""
|
| 94 |
+
if not self.current_game_pin:
|
| 95 |
+
return "Please select a quiz first!"
|
| 96 |
+
|
| 97 |
+
try:
|
| 98 |
+
# quiz_manager needs a get_leaderboard method that takes the game_pin
|
| 99 |
+
leaderboard = quiz_manager.get_leaderboard(self.current_game_pin)
|
| 100 |
+
if not leaderboard:
|
| 101 |
+
return f"No scores recorded yet for Game Pin: {self.current_game_pin}"
|
| 102 |
+
|
| 103 |
+
# Format leaderboard for display
|
| 104 |
+
leaderboard_str = f"Leaderboard for Game Pin: {self.current_game_pin}\n\n"
|
| 105 |
+
|
| 106 |
+
# Check if leaderboard is a dictionary or a list
|
| 107 |
+
if isinstance(leaderboard, dict):
|
| 108 |
+
# If it's a dictionary, process it the original way
|
| 109 |
+
sorted_leaderboard = sorted(leaderboard.items(), key=lambda item: item[1]['score'], reverse=True)
|
| 110 |
+
for i, (name, data) in enumerate(sorted_leaderboard, 1):
|
| 111 |
+
leaderboard_str += f"{i}. {name}: {data['score']} points\n"
|
| 112 |
+
elif isinstance(leaderboard, list):
|
| 113 |
+
# If it's a list, assuming it's a list of dictionaries with 'name' and 'score' keys
|
| 114 |
+
# or a list of tuples/lists with [name, score_data]
|
| 115 |
+
sorted_leaderboard = []
|
| 116 |
+
|
| 117 |
+
# Handle different possible formats of list items
|
| 118 |
+
if leaderboard and isinstance(leaderboard[0], dict):
|
| 119 |
+
# If list of dicts with 'name' and 'score' keys
|
| 120 |
+
if 'name' in leaderboard[0] and 'score' in leaderboard[0]:
|
| 121 |
+
sorted_leaderboard = sorted(leaderboard, key=lambda item: item['score'], reverse=True)
|
| 122 |
+
for i, player in enumerate(sorted_leaderboard, 1):
|
| 123 |
+
leaderboard_str += f"{i}. {player['name']}: {player['score']} points\n"
|
| 124 |
+
# If list of dicts with player name as key and score data as value
|
| 125 |
+
else:
|
| 126 |
+
for i, player_data in enumerate(leaderboard, 1):
|
| 127 |
+
for name, data in player_data.items():
|
| 128 |
+
if isinstance(data, dict) and 'score' in data:
|
| 129 |
+
leaderboard_str += f"{i}. {name}: {data['score']} points\n"
|
| 130 |
+
else:
|
| 131 |
+
leaderboard_str += f"{i}. {name}: {data} points\n"
|
| 132 |
+
elif leaderboard and isinstance(leaderboard[0], (list, tuple)):
|
| 133 |
+
# If list of tuples/lists with [name, score_data]
|
| 134 |
+
sorted_leaderboard = sorted(leaderboard, key=lambda item: item[1]['score'] if isinstance(item[1], dict) else item[1], reverse=True)
|
| 135 |
+
for i, (name, data) in enumerate(sorted_leaderboard, 1):
|
| 136 |
+
if isinstance(data, dict) and 'score' in data:
|
| 137 |
+
leaderboard_str += f"{i}. {name}: {data['score']} points\n"
|
| 138 |
+
else:
|
| 139 |
+
leaderboard_str += f"{i}. {name}: {data} points\n"
|
| 140 |
+
else:
|
| 141 |
+
# Fallback for other list formats
|
| 142 |
+
leaderboard_str += "Leaderboard format not recognized.\n"
|
| 143 |
+
leaderboard_str += f"Raw data: {leaderboard}\n"
|
| 144 |
+
else:
|
| 145 |
+
leaderboard_str += "Leaderboard format not recognized.\n"
|
| 146 |
+
leaderboard_str += f"Raw data: {leaderboard}\n"
|
| 147 |
+
|
| 148 |
+
return leaderboard_str
|
| 149 |
+
except Exception as e:
|
| 150 |
+
return f"Error retrieving leaderboard: {str(e)}"
|
| 151 |
+
|
| 152 |
+
# Function to update dropdown choices
|
| 153 |
+
def refresh_contestant_dropdown(self):
|
| 154 |
+
"""Return an update for the contestant dropdown."""
|
| 155 |
+
contestants = self.get_current_contestants()
|
| 156 |
+
# Add some debug info
|
| 157 |
+
print(f"Found contestants: {contestants}")
|
| 158 |
+
return gr.update(choices=contestants)
|
| 159 |
+
|
| 160 |
+
def create_leaderboard_interface(self):
|
| 161 |
+
"""Create the Gradio interface for the leaderboard."""
|
| 162 |
+
with gr.Blocks() as leaderboard_interface:
|
| 163 |
+
gr.Markdown("## Leaderboard")
|
| 164 |
+
|
| 165 |
+
# Section to Select Quiz to View Leaderboard (already exists)
|
| 166 |
+
with gr.Accordion("Select Quiz to View Leaderboard"):
|
| 167 |
+
existing_pin_input = gr.Textbox(label="Enter Game Pin")
|
| 168 |
+
select_quiz_btn = gr.Button("Select Quiz")
|
| 169 |
+
select_quiz_output = gr.Textbox(label="Quiz Selection Status", interactive=False)
|
| 170 |
+
|
| 171 |
+
select_quiz_btn.click(
|
| 172 |
+
fn=self.set_current_quiz,
|
| 173 |
+
inputs=existing_pin_input,
|
| 174 |
+
outputs=select_quiz_output
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
# Section to Add Contestant
|
| 178 |
+
with gr.Accordion("Add Contestant", open=False): # Start closed
|
| 179 |
+
contestant_name_input = gr.Textbox(label="Contestant Name")
|
| 180 |
+
add_contestant_btn = gr.Button("Add Contestant")
|
| 181 |
+
add_contestant_output = gr.Textbox(label="Add Contestant Status", interactive=False)
|
| 182 |
+
|
| 183 |
+
add_contestant_btn.click(
|
| 184 |
+
fn=self.add_contestant,
|
| 185 |
+
inputs=contestant_name_input,
|
| 186 |
+
outputs=add_contestant_output
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
# Section to Record Contestant Answer
|
| 190 |
+
with gr.Accordion("Record Answer", open=False): # Start closed
|
| 191 |
+
# Changed from Textbox to Dropdown with initial empty list
|
| 192 |
+
record_contestant_name_input = gr.Dropdown(
|
| 193 |
+
label="Contestant Name",
|
| 194 |
+
choices=[], # Start with empty list
|
| 195 |
+
interactive=True
|
| 196 |
+
)
|
| 197 |
+
question_number_input = gr.Number(label="Question Number", precision=0) # Use Number for question number
|
| 198 |
+
selected_answer_input = gr.Textbox(label="Selected Answer")
|
| 199 |
+
record_answer_btn = gr.Button("Record Answer")
|
| 200 |
+
record_answer_output = gr.Textbox(label="Record Answer Status", interactive=False)
|
| 201 |
+
|
| 202 |
+
# Refresh button to update contestant list
|
| 203 |
+
refresh_btn = gr.Button("Refresh Contestant List")
|
| 204 |
+
|
| 205 |
+
refresh_btn.click(
|
| 206 |
+
fn=self.refresh_contestant_dropdown,
|
| 207 |
+
outputs=record_contestant_name_input
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
record_answer_btn.click(
|
| 211 |
+
fn=self.record_contestant_answer,
|
| 212 |
+
inputs=[record_contestant_name_input, question_number_input, selected_answer_input],
|
| 213 |
+
outputs=record_answer_output
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
# Also update dropdown when selecting a quiz
|
| 217 |
+
select_quiz_btn.click(
|
| 218 |
+
fn=self.refresh_contestant_dropdown,
|
| 219 |
+
outputs=record_contestant_name_input
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
# Also update dropdown when adding a contestant
|
| 223 |
+
add_contestant_btn.click(
|
| 224 |
+
fn=self.refresh_contestant_dropdown,
|
| 225 |
+
outputs=record_contestant_name_input
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
# Section to View Leaderboard (already exists)
|
| 229 |
+
leaderboard_output = gr.Textbox(label="Current Leaderboard", interactive=False)
|
| 230 |
+
view_leaderboard_btn = gr.Button("View Leaderboard")
|
| 231 |
+
|
| 232 |
+
view_leaderboard_btn.click(
|
| 233 |
+
fn=self.get_leaderboard,
|
| 234 |
+
outputs=leaderboard_output
|
| 235 |
+
)
|
| 236 |
+
|
| 237 |
+
return leaderboard_interface
|
| 238 |
+
|
| 239 |
+
# This automatically creates the Gradio interface within the instance
|
| 240 |
+
leaderboard_interface_instance = LeaderboardInterface()
|
| 241 |
+
|
| 242 |
+
# To access the Gradio interface object:
|
| 243 |
+
leaderboard_gradio_interface = leaderboard_interface_instance.leaderboard_gradio_interface
|
| 244 |
+
|
| 245 |
+
# You can now use leaderboard_gradio_interface, for example, to launch it:
|
| 246 |
+
# leaderboard_gradio_interface.launch()
|
| 247 |
+
|
| 248 |
+
# If this file is imported into another script that launches the main app,
|
| 249 |
+
# you would typically just use leaderboard_gradio_interface
|
| 250 |
+
# as one of the blocks to include in the main layout.
|
player_interface.py
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# player_interface.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from quiz_manager import quiz_manager # Assuming quiz_manager exists and is accessible
|
| 5 |
+
|
| 6 |
+
class PlayerInterface:
|
| 7 |
+
def __init__(self):
|
| 8 |
+
self.current_game_pin = None
|
| 9 |
+
self.current_question_index = -1
|
| 10 |
+
self.current_quiz_data = None
|
| 11 |
+
self.player_name = None
|
| 12 |
+
self.total_questions = 0
|
| 13 |
+
|
| 14 |
+
def join_game(self, game_pin, player_name):
|
| 15 |
+
"""Validate the game pin and allow player to join."""
|
| 16 |
+
try:
|
| 17 |
+
if game_pin not in quiz_manager.quizzes:
|
| 18 |
+
print("JOIN_GAME: Invalid pin")
|
| 19 |
+
# Return updates for all relevant components on failure
|
| 20 |
+
return (
|
| 21 |
+
f"Invalid game pin: {game_pin}. Please try again.",
|
| 22 |
+
gr.update(choices=[], visible=False), # Hide and clear dropdown
|
| 23 |
+
gr.update(visible=False), # Hide next button row
|
| 24 |
+
gr.update(visible=False), # Hide question area
|
| 25 |
+
gr.update(visible=False) # Hide leaderboard area initially (added this output)
|
| 26 |
+
)
|
| 27 |
+
self.current_game_pin = game_pin
|
| 28 |
+
self.current_quiz_data = quiz_manager.quizzes[game_pin]
|
| 29 |
+
self.player_name = player_name
|
| 30 |
+
# Assuming initialize_player_score is a method in quiz_manager
|
| 31 |
+
quiz_manager.initialize_player_score(game_pin, player_name)
|
| 32 |
+
self.total_questions = len(self.current_quiz_data.get('questions', [])) # Safely get questions
|
| 33 |
+
question_numbers = list(range(1, self.total_questions + 1))
|
| 34 |
+
print("JOIN_GAME: Success")
|
| 35 |
+
print(f"JOIN_GAME: current_game_pin = {self.current_game_pin}")
|
| 36 |
+
print(f"JOIN_GAME: current_quiz_data = {self.current_quiz_data}")
|
| 37 |
+
print(f"JOIN_GAME: total_questions = {self.total_questions}")
|
| 38 |
+
|
| 39 |
+
# Return updates for all relevant components on success
|
| 40 |
+
return (
|
| 41 |
+
f"Joined game {game_pin} successfully, {player_name}!",
|
| 42 |
+
gr.update(choices=question_numbers, visible=True, value=None), # Update choices, make visible, reset value
|
| 43 |
+
gr.update(visible=True), # Show next button row
|
| 44 |
+
gr.update(visible=False), # Keep question area hidden initially
|
| 45 |
+
gr.update(visible=True) # Show leaderboard area (assuming it should appear after joining)
|
| 46 |
+
)
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print(f"JOIN_GAME: Error - {str(e)}")
|
| 49 |
+
# Return updates for all relevant components on error
|
| 50 |
+
return (
|
| 51 |
+
f"Error joining game: {str(e)}",
|
| 52 |
+
gr.update(choices=[], visible=False),
|
| 53 |
+
gr.update(visible=False),
|
| 54 |
+
gr.update(visible=False),
|
| 55 |
+
gr.update(visible=False)
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def show_question(self):
|
| 60 |
+
"""Prepare updates for displaying the current question."""
|
| 61 |
+
print("SHOW_QUESTION: Called")
|
| 62 |
+
# Prepare default updates for components
|
| 63 |
+
default_question_text = "No question loaded."
|
| 64 |
+
default_options_update = gr.update(choices=[], value=None)
|
| 65 |
+
default_prompt_label_update = gr.update(value="")
|
| 66 |
+
default_question_area_update = gr.update(visible=True)
|
| 67 |
+
default_submit_btn_update = gr.update(visible=True)
|
| 68 |
+
default_answer_output_update = gr.update(value="")
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
if not self.current_quiz_data or self.current_question_index == -1:
|
| 72 |
+
print("SHOW_QUESTION: No quiz data or invalid index")
|
| 73 |
+
# Return default updates
|
| 74 |
+
return (
|
| 75 |
+
default_question_text,
|
| 76 |
+
default_options_update,
|
| 77 |
+
default_prompt_label_update,
|
| 78 |
+
default_question_area_update,
|
| 79 |
+
default_submit_btn_update,
|
| 80 |
+
default_answer_output_update # Include update for answer_output
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# Ensure questions key exists and index is valid
|
| 84 |
+
questions = self.current_quiz_data.get('questions', [])
|
| 85 |
+
if not questions or self.current_question_index < 0 or self.current_question_index >= len(questions):
|
| 86 |
+
print("SHOW_QUESTION: Invalid question data or index out of bounds")
|
| 87 |
+
return (
|
| 88 |
+
"Error loading question data.",
|
| 89 |
+
default_options_update,
|
| 90 |
+
default_prompt_label_update,
|
| 91 |
+
default_question_area_update,
|
| 92 |
+
default_submit_btn_update,
|
| 93 |
+
default_answer_output_update
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
question_data = questions[self.current_question_index]
|
| 98 |
+
options = question_data.get('options', [])
|
| 99 |
+
question_text = question_data.get('text', 'Error loading question text')
|
| 100 |
+
print(f"SHOW_QUESTION: Displaying question - index: {self.current_question_index}, text: {question_text}")
|
| 101 |
+
print(f"SHOW_QUESTION: Options: {options}")
|
| 102 |
+
|
| 103 |
+
# Return specific updates for the current question
|
| 104 |
+
return (
|
| 105 |
+
f"Question {self.current_question_index + 1}: {question_text}", # Update question_display value
|
| 106 |
+
gr.update(choices=options, value=None, label="Answer Choices"), # Update options_radio choices, reset value, set static label
|
| 107 |
+
gr.update(value="Select your answer:"), # Update options_prompt_label value
|
| 108 |
+
gr.update(visible=True), # Update question_area visibility
|
| 109 |
+
gr.update(visible=True), # Update submit_btn visibility
|
| 110 |
+
gr.update(value="") # Clear answer_output value
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# The methods next_step, next_question, previous_question, and
|
| 114 |
+
# select_question_by_number now just need to call show_question
|
| 115 |
+
# and return its result, as show_question prepares all the necessary updates.
|
| 116 |
+
|
| 117 |
+
def next_step(self):
|
| 118 |
+
print("NEXT_STEP: Called")
|
| 119 |
+
if self.current_quiz_data and self.total_questions > 0:
|
| 120 |
+
self.current_question_index = 0
|
| 121 |
+
result = self.show_question()
|
| 122 |
+
print(f"NEXT_STEP: Showing question - index: {self.current_question_index}")
|
| 123 |
+
# show_question now returns 6 updates, return them directly
|
| 124 |
+
return result
|
| 125 |
+
else:
|
| 126 |
+
print("NEXT_STEP: No questions available")
|
| 127 |
+
# Return default updates if no questions
|
| 128 |
+
return (
|
| 129 |
+
"No questions available.",
|
| 130 |
+
gr.update(choices=[], value=None, label="Answer Choices"),
|
| 131 |
+
gr.update(value=""),
|
| 132 |
+
gr.update(visible=False),
|
| 133 |
+
gr.update(visible=False),
|
| 134 |
+
gr.update(value="")
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def next_question(self):
|
| 139 |
+
"""Move to the next question."""
|
| 140 |
+
print("NEXT_QUESTION: Called")
|
| 141 |
+
if not self.current_quiz_data:
|
| 142 |
+
print("NEXT_QUESTION: No quiz data")
|
| 143 |
+
# Return default updates
|
| 144 |
+
return (
|
| 145 |
+
"Please join a game first.",
|
| 146 |
+
gr.update(choices=[], value=None, label="Answer Choices"),
|
| 147 |
+
gr.update(value=""),
|
| 148 |
+
gr.update(visible=False),
|
| 149 |
+
gr.update(visible=False),
|
| 150 |
+
gr.update(value="")
|
| 151 |
+
)
|
| 152 |
+
if self.current_question_index < len(self.current_quiz_data.get('questions', [])) - 1:
|
| 153 |
+
self.current_question_index += 1
|
| 154 |
+
result = self.show_question()
|
| 155 |
+
print(f"NEXT_QUESTION: Showing question - index: {self.current_question_index}")
|
| 156 |
+
# show_question now returns 6 updates, return them directly
|
| 157 |
+
return result
|
| 158 |
+
else:
|
| 159 |
+
print("NEXT_QUESTION: Quiz finished")
|
| 160 |
+
# Return updates for quiz finished state
|
| 161 |
+
return (
|
| 162 |
+
"Quiz finished!",
|
| 163 |
+
gr.update(choices=[], value=None, label="Answer Choices"),
|
| 164 |
+
gr.update(value=""),
|
| 165 |
+
gr.update(visible=False), # Hide question area
|
| 166 |
+
gr.update(visible=False), # Hide submit button
|
| 167 |
+
gr.update(value="")
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
def previous_question(self):
|
| 171 |
+
"""Move to the previous question."""
|
| 172 |
+
print("PREVIOUS_QUESTION: Called")
|
| 173 |
+
if not self.current_quiz_data:
|
| 174 |
+
print("PREVIOUS_QUESTION: No quiz data")
|
| 175 |
+
# Return default updates
|
| 176 |
+
return (
|
| 177 |
+
"Please join a game first.",
|
| 178 |
+
gr.update(choices=[], value=None, label="Answer Choices"),
|
| 179 |
+
gr.update(value=""),
|
| 180 |
+
gr.update(visible=False),
|
| 181 |
+
gr.update(visible=False),
|
| 182 |
+
gr.update(value="")
|
| 183 |
+
)
|
| 184 |
+
if self.current_question_index > 0:
|
| 185 |
+
self.current_question_index -= 1
|
| 186 |
+
result = self.show_question()
|
| 187 |
+
print(f"PREVIOUS_QUESTION: Showing question - index: {self.current_question_index}")
|
| 188 |
+
# show_question now returns 6 updates, return them directly
|
| 189 |
+
return result
|
| 190 |
+
else:
|
| 191 |
+
print("PREVIOUS_QUESTION: First question")
|
| 192 |
+
# Return updates for first question state
|
| 193 |
+
return (
|
| 194 |
+
"This is the first question.",
|
| 195 |
+
gr.update(choices=[], value=None, label="Answer Choices"),
|
| 196 |
+
gr.update(value=""),
|
| 197 |
+
gr.update(visible=False),
|
| 198 |
+
gr.update(visible=False),
|
| 199 |
+
gr.update(value="")
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def select_question_by_number(self, question_number):
|
| 204 |
+
"""Select a specific question by its number."""
|
| 205 |
+
print(f"SELECT_QUESTION_BY_NUMBER: Called with {question_number}")
|
| 206 |
+
# Handle case where question_number might be None from dropdown reset
|
| 207 |
+
if question_number is None:
|
| 208 |
+
print("SELECT_QUESTION_BY_NUMBER: question_number is None")
|
| 209 |
+
return (
|
| 210 |
+
"", # Clear question text
|
| 211 |
+
gr.update(choices=[], value=None, label="Answer Choices"), # Clear options
|
| 212 |
+
gr.update(value=""), # Clear prompt label
|
| 213 |
+
gr.update(visible=False), # Hide question area
|
| 214 |
+
gr.update(visible=False), # Hide submit button
|
| 215 |
+
gr.update(value="") # Clear answer output
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
if not self.current_quiz_data:
|
| 219 |
+
print("SELECT_QUESTION_BY_NUMBER: No quiz data")
|
| 220 |
+
# Return default updates
|
| 221 |
+
return (
|
| 222 |
+
"Please join a game first.",
|
| 223 |
+
gr.update(choices=[], value=None, label="Answer Choices"),
|
| 224 |
+
gr.update(value=""),
|
| 225 |
+
gr.update(visible=False),
|
| 226 |
+
gr.update(visible=False),
|
| 227 |
+
gr.update(value="")
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
questions = self.current_quiz_data.get('questions', [])
|
| 231 |
+
index = question_number - 1
|
| 232 |
+
if 0 <= index < len(questions):
|
| 233 |
+
self.current_question_index = index
|
| 234 |
+
result = self.show_question()
|
| 235 |
+
print(f"SELECT_QUESTION_BY_NUMBER: Showing question - index: {self.current_question_index}")
|
| 236 |
+
# show_question now returns 6 updates, return them directly
|
| 237 |
+
return result
|
| 238 |
+
else:
|
| 239 |
+
print("SELECT_QUESTION_BY_NUMBER: Invalid question number")
|
| 240 |
+
# Return updates for invalid number
|
| 241 |
+
return (
|
| 242 |
+
"Invalid question number.",
|
| 243 |
+
gr.update(choices=[], value=None, label="Answer Choices"),
|
| 244 |
+
gr.update(value=""),
|
| 245 |
+
gr.update(visible=False),
|
| 246 |
+
gr.update(visible=False),
|
| 247 |
+
gr.update(value="")
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def submit_answer(self, selected_option):
|
| 252 |
+
"""Submit the player's answer for the current question."""
|
| 253 |
+
if not self.current_quiz_data or self.current_question_index == -1:
|
| 254 |
+
return "Please select a question first."
|
| 255 |
+
# Ensure selected_option is not None if the user submits without selecting
|
| 256 |
+
if selected_option is None:
|
| 257 |
+
return "Please select an answer."
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
questions = self.current_quiz_data.get('questions', [])
|
| 261 |
+
if not questions or self.current_question_index < 0 or self.current_question_index >= len(questions):
|
| 262 |
+
return "Error submitting answer: Invalid question data."
|
| 263 |
+
|
| 264 |
+
current_question = questions[self.current_question_index]
|
| 265 |
+
correct_answer = current_question.get('correct_answer')
|
| 266 |
+
# Handle cases where correct_answer might be missing
|
| 267 |
+
if correct_answer is None:
|
| 268 |
+
return "Error submitting answer: Correct answer not defined for this question."
|
| 269 |
+
|
| 270 |
+
is_correct = selected_option == correct_answer
|
| 271 |
+
|
| 272 |
+
# Assuming record_answer is a method in quiz_manager
|
| 273 |
+
if self.current_game_pin and self.player_name:
|
| 274 |
+
quiz_manager.record_answer(self.current_game_pin, self.player_name, is_correct)
|
| 275 |
+
|
| 276 |
+
return "Correct!" if is_correct else f"Incorrect. The correct answer was: {correct_answer}"
|
| 277 |
+
|
| 278 |
+
def get_leaderboard(self):
|
| 279 |
+
"""Retrieve and display the leaderboard."""
|
| 280 |
+
print("GET_LEADERBOARD: Called")
|
| 281 |
+
if not self.current_game_pin:
|
| 282 |
+
print("GET_LEADERBOARD: No game pin")
|
| 283 |
+
return "Please join a game first."
|
| 284 |
+
# Assuming get_leaderboard is a method in quiz_manager that returns a LIST of tuples or lists
|
| 285 |
+
# where each element is something like (player_name, {'score': score_value, ...})
|
| 286 |
+
leaderboard = quiz_manager.get_leaderboard(self.current_game_pin)
|
| 287 |
+
|
| 288 |
+
if not leaderboard:
|
| 289 |
+
print("GET_LEADERBOARD: No scores recorded")
|
| 290 |
+
return "No scores recorded yet."
|
| 291 |
+
|
| 292 |
+
leaderboard_str = "### Leaderboard:\n"
|
| 293 |
+
# Sort leaderboard by score in descending order
|
| 294 |
+
# Removed .items() because 'leaderboard' is a list
|
| 295 |
+
try:
|
| 296 |
+
sorted_leaderboard = sorted(leaderboard, key=lambda item: item[1].get('score', 0), reverse=True)
|
| 297 |
+
for i, (name, data) in enumerate(sorted_leaderboard, 1):
|
| 298 |
+
score = data.get('score', 0) # Safely get score
|
| 299 |
+
leaderboard_str += f"{i}. {name}: {score} points\n"
|
| 300 |
+
print("GET_LEADERBOARD: Leaderboard generated")
|
| 301 |
+
return leaderboard_str
|
| 302 |
+
except (TypeError, IndexError, AttributeError) as e:
|
| 303 |
+
# Catch potential errors if the list elements are not in the expected format
|
| 304 |
+
print(f"GET_LEADERBOARD: Error processing leaderboard data - {str(e)}")
|
| 305 |
+
return f"Error displaying leaderboard data: {str(e)}. Please check the format returned by quiz_manager.get_leaderboard."
|
| 306 |
+
|
| 307 |
+
def create_player_interface(self):
|
| 308 |
+
"""Create the Gradio interface for players with a step-by-step layout."""
|
| 309 |
+
with gr.Blocks() as player_interface:
|
| 310 |
+
gr.Markdown("## Quiz Player Dashboard")
|
| 311 |
+
|
| 312 |
+
# --- Join Game Section ---
|
| 313 |
+
with gr.Row():
|
| 314 |
+
game_pin_input = gr.Textbox(label="Enter Game Pin")
|
| 315 |
+
player_name_input = gr.Textbox(label="Your Name")
|
| 316 |
+
join_btn = gr.Button("Join Game")
|
| 317 |
+
join_output = gr.Textbox(label="Join Status", interactive=False)
|
| 318 |
+
# question_dropdown visibility and choices updated by join_game
|
| 319 |
+
question_dropdown = gr.Dropdown(label="Select Question", choices=[], visible=False, interactive=True)
|
| 320 |
+
|
| 321 |
+
# --- Initial Next Button (to start the quiz) ---
|
| 322 |
+
# Initially hidden, made visible after joining
|
| 323 |
+
next_button_row = gr.Row(visible=False)
|
| 324 |
+
with next_button_row:
|
| 325 |
+
# This button will trigger showing the first question via next_step
|
| 326 |
+
next_btn = gr.Button("Start Quiz")
|
| 327 |
+
|
| 328 |
+
# --- Question Area (initially hidden) ---
|
| 329 |
+
# Made visible when a question is loaded
|
| 330 |
+
question_area = gr.Column(visible=False)
|
| 331 |
+
with question_area:
|
| 332 |
+
question_display = gr.Markdown(label="Question Text") # Label can be static here
|
| 333 |
+
options_prompt_label = gr.Label(label="") # Label to show "Select your answer:"
|
| 334 |
+
options_radio = gr.Radio(label="Answer Choices") # Static label for the radio group
|
| 335 |
+
submit_btn = gr.Button("Submit Answer")
|
| 336 |
+
answer_output = gr.Textbox(label="Answer Result", interactive=False)
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
# --- Navigation Buttons ---
|
| 340 |
+
with gr.Row():
|
| 341 |
+
prev_question_btn = gr.Button("Previous Question")
|
| 342 |
+
next_question_btn = gr.Button("Next Question")
|
| 343 |
+
|
| 344 |
+
# --- Leaderboard Area (initially hidden, shown after joining) ---
|
| 345 |
+
leaderboard_area = gr.Column(visible=False)
|
| 346 |
+
with leaderboard_area:
|
| 347 |
+
leaderboard_output = gr.Markdown(label="Leaderboard Results")
|
| 348 |
+
get_leaderboard_btn = gr.Button("Refresh Leaderboard")
|
| 349 |
+
|
| 350 |
+
# --- Interactions ---
|
| 351 |
+
|
| 352 |
+
# Join Game interaction
|
| 353 |
+
# join_game returns 5 outputs: join_status, dropdown_update, next_btn_row_update, question_area_update (initial hide), leaderboard_area_update
|
| 354 |
+
join_btn.click(
|
| 355 |
+
fn=self.join_game,
|
| 356 |
+
inputs=[game_pin_input, player_name_input],
|
| 357 |
+
outputs=[
|
| 358 |
+
join_output,
|
| 359 |
+
question_dropdown,
|
| 360 |
+
next_button_row,
|
| 361 |
+
question_area,
|
| 362 |
+
leaderboard_area # Map to the leaderboard area visibility
|
| 363 |
+
]
|
| 364 |
+
)
|
| 365 |
+
|
| 366 |
+
# Start Quiz button interaction (uses next_step to show the first question)
|
| 367 |
+
# next_step calls show_question, which returns 6 updates
|
| 368 |
+
next_btn.click(
|
| 369 |
+
fn=self.next_step,
|
| 370 |
+
outputs=[
|
| 371 |
+
question_display, # Updates with question text
|
| 372 |
+
options_radio, # Updates with choices and value=None
|
| 373 |
+
options_prompt_label, # Updates with "Select your answer:"
|
| 374 |
+
question_area, # Updates visibility
|
| 375 |
+
submit_btn, # Updates visibility
|
| 376 |
+
answer_output # Clears answer output
|
| 377 |
+
]
|
| 378 |
+
)
|
| 379 |
+
|
| 380 |
+
# Question Dropdown interaction
|
| 381 |
+
# select_question_by_number calls show_question, which returns 6 updates
|
| 382 |
+
question_dropdown.change(
|
| 383 |
+
fn=self.select_question_by_number,
|
| 384 |
+
inputs=question_dropdown,
|
| 385 |
+
outputs=[
|
| 386 |
+
question_display,
|
| 387 |
+
options_radio,
|
| 388 |
+
options_prompt_label,
|
| 389 |
+
question_area,
|
| 390 |
+
submit_btn,
|
| 391 |
+
answer_output
|
| 392 |
+
]
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
+
# Next Question button interaction
|
| 396 |
+
# next_question calls show_question, which returns 6 updates
|
| 397 |
+
next_question_btn.click(
|
| 398 |
+
fn=self.next_question,
|
| 399 |
+
outputs=[
|
| 400 |
+
question_display,
|
| 401 |
+
options_radio,
|
| 402 |
+
options_prompt_label,
|
| 403 |
+
question_area,
|
| 404 |
+
submit_btn,
|
| 405 |
+
answer_output
|
| 406 |
+
]
|
| 407 |
+
)
|
| 408 |
+
|
| 409 |
+
# Previous Question button interaction
|
| 410 |
+
# previous_question calls show_question, which returns 6 updates
|
| 411 |
+
prev_question_btn.click(
|
| 412 |
+
fn=self.previous_question,
|
| 413 |
+
outputs=[
|
| 414 |
+
question_display,
|
| 415 |
+
options_radio,
|
| 416 |
+
options_prompt_label,
|
| 417 |
+
question_area,
|
| 418 |
+
submit_btn,
|
| 419 |
+
answer_output
|
| 420 |
+
]
|
| 421 |
+
)
|
| 422 |
+
|
| 423 |
+
# Submit Answer button interaction
|
| 424 |
+
submit_btn.click(
|
| 425 |
+
fn=self.submit_answer,
|
| 426 |
+
inputs=options_radio, # Input is the selected value from the radio button
|
| 427 |
+
outputs=answer_output, # Output is the result of the submission
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
# Refresh Leaderboard button interaction
|
| 431 |
+
get_leaderboard_btn.click(
|
| 432 |
+
fn=self.get_leaderboard,
|
| 433 |
+
outputs=leaderboard_output,
|
| 434 |
+
)
|
| 435 |
+
|
| 436 |
+
# The leaderboard visibility is handled by the join_game outputs now,
|
| 437 |
+
# so the separate .then() listener is not needed here.
|
| 438 |
+
|
| 439 |
+
return player_interface
|
| 440 |
+
|
| 441 |
+
# --- How to use this class ---
|
| 442 |
+
|
| 443 |
+
# Create the PlayerInterface instance
|
| 444 |
+
player_interface_instance = PlayerInterface()
|
| 445 |
+
|
| 446 |
+
# To access the Gradio interface object:
|
| 447 |
+
player_gradio_interface = player_interface_instance.create_player_interface()
|
| 448 |
+
|
| 449 |
+
# You can now use player_gradio_interface, for example, to launch it:
|
| 450 |
+
# player_gradio_interface.launch()
|
| 451 |
+
|
| 452 |
+
# If this file is imported into another script that launches the main app,
|
| 453 |
+
# you would typically just use player_gradio_interface
|
| 454 |
+
# as one of the blocks to include in the main layout.
|
quiz_data/quiz_193449.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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "KL",
|
| 3 |
+
"questions": [
|
| 4 |
+
{
|
| 5 |
+
"text": "What is the capital of France?",
|
| 6 |
+
"options": [
|
| 7 |
+
"London",
|
| 8 |
+
"Berlin",
|
| 9 |
+
"Paris",
|
| 10 |
+
"Madrid"
|
| 11 |
+
],
|
| 12 |
+
"correct_answer": "Paris"
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"text": "Which planet is known as the Red Planet?",
|
| 16 |
+
"options": [
|
| 17 |
+
"Mars",
|
| 18 |
+
"Jupiter",
|
| 19 |
+
"Venus",
|
| 20 |
+
"Saturn"
|
| 21 |
+
],
|
| 22 |
+
"correct_answer": "Mars"
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"text": "What is the chemical symbol for water?",
|
| 26 |
+
"options": [
|
| 27 |
+
"Wa",
|
| 28 |
+
"H2O",
|
| 29 |
+
"Wo",
|
| 30 |
+
"HO2"
|
| 31 |
+
],
|
| 32 |
+
"correct_answer": "H2O"
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"text": "Who painted the Mona Lisa?",
|
| 36 |
+
"options": [
|
| 37 |
+
"Vincent van Gogh",
|
| 38 |
+
"Leonardo da Vinci",
|
| 39 |
+
"Pablo Picasso",
|
| 40 |
+
"Claude Monet"
|
| 41 |
+
],
|
| 42 |
+
"correct_answer": "Leonardo da Vinci"
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"text": "What is the largest mammal in the world?",
|
| 46 |
+
"options": [
|
| 47 |
+
"African Elephant",
|
| 48 |
+
"Blue Whale",
|
| 49 |
+
"Giraffe",
|
| 50 |
+
"Polar Bear"
|
| 51 |
+
],
|
| 52 |
+
"correct_answer": "Blue Whale"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"text": "How many continents are there?",
|
| 56 |
+
"options": [
|
| 57 |
+
"Five",
|
| 58 |
+
"Six",
|
| 59 |
+
"Seven",
|
| 60 |
+
"Eight"
|
| 61 |
+
],
|
| 62 |
+
"correct_answer": "Seven"
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"text": "What is the currency of Japan?",
|
| 66 |
+
"options": [
|
| 67 |
+
"Yuan",
|
| 68 |
+
"Won",
|
| 69 |
+
"Dollar",
|
| 70 |
+
"Yen"
|
| 71 |
+
],
|
| 72 |
+
"correct_answer": "Yen"
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"text": "What is the tallest mountain in the world?",
|
| 76 |
+
"options": [
|
| 77 |
+
"K2",
|
| 78 |
+
"Mount Everest",
|
| 79 |
+
"Kangchenjunga",
|
| 80 |
+
"Lhotse"
|
| 81 |
+
],
|
| 82 |
+
"correct_answer": "Mount Everest"
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"text": "What is the speed of light in a vacuum (approximately)?",
|
| 86 |
+
"options": [
|
| 87 |
+
"300000 km/s",
|
| 88 |
+
"150000 km/s",
|
| 89 |
+
"450000 km/s",
|
| 90 |
+
"200000 km/s"
|
| 91 |
+
],
|
| 92 |
+
"correct_answer": "300000 km/s"
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"text": "What is the powerhouse of the cell?",
|
| 96 |
+
"options": [
|
| 97 |
+
"Nucleus",
|
| 98 |
+
"Mitochondria",
|
| 99 |
+
"Ribosome",
|
| 100 |
+
"Endoplasmic Reticulum"
|
| 101 |
+
],
|
| 102 |
+
"correct_answer": "Mitochondria"
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"text": "What is the chemical symbol for gold?",
|
| 106 |
+
"options": [
|
| 107 |
+
"Au",
|
| 108 |
+
"Ag",
|
| 109 |
+
"Go",
|
| 110 |
+
"Gd"
|
| 111 |
+
],
|
| 112 |
+
"correct_answer": "Au"
|
| 113 |
+
},
|
| 114 |
+
{
|
| 115 |
+
"text": "Who wrote the play \"Hamlet\"?",
|
| 116 |
+
"options": [
|
| 117 |
+
"William Shakespeare",
|
| 118 |
+
"Jane Austen",
|
| 119 |
+
"Charles Dickens",
|
| 120 |
+
"George Orwell"
|
| 121 |
+
],
|
| 122 |
+
"correct_answer": "William Shakespeare"
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"text": "What is the largest ocean on Earth?",
|
| 126 |
+
"options": [
|
| 127 |
+
"Atlantic Ocean",
|
| 128 |
+
"Indian Ocean",
|
| 129 |
+
"Arctic Ocean",
|
| 130 |
+
"Pacific Ocean"
|
| 131 |
+
],
|
| 132 |
+
"correct_answer": "Pacific Ocean"
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"text": "What is the boiling point of water at standard pressure?",
|
| 136 |
+
"options": [
|
| 137 |
+
"100\u00b0C",
|
| 138 |
+
"0\u00b0C",
|
| 139 |
+
"50\u00b0C",
|
| 140 |
+
"212\u00b0F"
|
| 141 |
+
],
|
| 142 |
+
"correct_answer": "100\u00b0C"
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
"text": "What is the main gas in Earth's atmosphere?",
|
| 146 |
+
"options": [
|
| 147 |
+
"Oxygen",
|
| 148 |
+
"Carbon Dioxide",
|
| 149 |
+
"Nitrogen",
|
| 150 |
+
"Hydrogen"
|
| 151 |
+
],
|
| 152 |
+
"correct_answer": "Nitrogen"
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"text": "Who developed the theory of relativity?",
|
| 156 |
+
"options": [
|
| 157 |
+
"Isaac Newton",
|
| 158 |
+
"Albert Einstein",
|
| 159 |
+
"Galileo Galilei",
|
| 160 |
+
"Stephen Hawking"
|
| 161 |
+
],
|
| 162 |
+
"correct_answer": "Albert Einstein"
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
"text": "What is the smallest prime number?",
|
| 166 |
+
"options": [
|
| 167 |
+
"0",
|
| 168 |
+
"1",
|
| 169 |
+
"2",
|
| 170 |
+
"3"
|
| 171 |
+
],
|
| 172 |
+
"correct_answer": "2"
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"text": "What is the capital of Australia?",
|
| 176 |
+
"options": [
|
| 177 |
+
"Sydney",
|
| 178 |
+
"Melbourne",
|
| 179 |
+
"Canberra",
|
| 180 |
+
"Perth"
|
| 181 |
+
],
|
| 182 |
+
"correct_answer": "Canberra"
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"text": "What type of animal is a dolphin?",
|
| 186 |
+
"options": [
|
| 187 |
+
"Fish",
|
| 188 |
+
"Mammal",
|
| 189 |
+
"Reptile",
|
| 190 |
+
"Amphibian"
|
| 191 |
+
],
|
| 192 |
+
"correct_answer": "Mammal"
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
"text": "What is the name of Earth's natural satellite?",
|
| 196 |
+
"options": [
|
| 197 |
+
"Mars",
|
| 198 |
+
"Venus",
|
| 199 |
+
"Moon",
|
| 200 |
+
"Titan"
|
| 201 |
+
],
|
| 202 |
+
"correct_answer": "Moon"
|
| 203 |
+
}
|
| 204 |
+
],
|
| 205 |
+
"leaderboard": {
|
| 206 |
+
"John": {
|
| 207 |
+
"score": 6
|
| 208 |
+
},
|
| 209 |
+
"Johhnn": {
|
| 210 |
+
"score": 0
|
| 211 |
+
},
|
| 212 |
+
"Jommk": {
|
| 213 |
+
"score": 0
|
| 214 |
+
},
|
| 215 |
+
"": {
|
| 216 |
+
"score": 0
|
| 217 |
+
},
|
| 218 |
+
"hjjjh": {
|
| 219 |
+
"score": 1
|
| 220 |
+
},
|
| 221 |
+
"JOHN": {
|
| 222 |
+
"score": 0
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
}
|
quiz_data/quiz_620321.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "193449",
|
| 3 |
+
"questions": [],
|
| 4 |
+
"leaderboard": {}
|
| 5 |
+
}
|
quiz_data/quiz_655067.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "193449",
|
| 3 |
+
"questions": [],
|
| 4 |
+
"leaderboard": {}
|
| 5 |
+
}
|
quiz_data/quiz_772319.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "quiz",
|
| 3 |
+
"questions": [],
|
| 4 |
+
"leaderboard": {
|
| 5 |
+
"John": {
|
| 6 |
+
"score": 0
|
| 7 |
+
}
|
| 8 |
+
}
|
| 9 |
+
}
|
quiz_data/quiz_854464.json
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "JOHN",
|
| 3 |
+
"questions": [
|
| 4 |
+
{
|
| 5 |
+
"text": "What is the capital of France?",
|
| 6 |
+
"options": [
|
| 7 |
+
"London",
|
| 8 |
+
"Berlin",
|
| 9 |
+
"Paris",
|
| 10 |
+
"Madrid"
|
| 11 |
+
],
|
| 12 |
+
"correct_answer": "Paris"
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"text": "Which planet is known as the Red Planet?",
|
| 16 |
+
"options": [
|
| 17 |
+
"Mars",
|
| 18 |
+
"Jupiter",
|
| 19 |
+
"Venus",
|
| 20 |
+
"Saturn"
|
| 21 |
+
],
|
| 22 |
+
"correct_answer": "Mars"
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"text": "What is the chemical symbol for water?",
|
| 26 |
+
"options": [
|
| 27 |
+
"Wa",
|
| 28 |
+
"H2O",
|
| 29 |
+
"Wo",
|
| 30 |
+
"HO2"
|
| 31 |
+
],
|
| 32 |
+
"correct_answer": "H2O"
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"text": "Who painted the Mona Lisa?",
|
| 36 |
+
"options": [
|
| 37 |
+
"Vincent van Gogh",
|
| 38 |
+
"Leonardo da Vinci",
|
| 39 |
+
"Pablo Picasso",
|
| 40 |
+
"Claude Monet"
|
| 41 |
+
],
|
| 42 |
+
"correct_answer": "Leonardo da Vinci"
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"text": "What is the largest mammal in the world?",
|
| 46 |
+
"options": [
|
| 47 |
+
"African Elephant",
|
| 48 |
+
"Blue Whale",
|
| 49 |
+
"Giraffe",
|
| 50 |
+
"Polar Bear"
|
| 51 |
+
],
|
| 52 |
+
"correct_answer": "Blue Whale"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"text": "How many continents are there?",
|
| 56 |
+
"options": [
|
| 57 |
+
"Five",
|
| 58 |
+
"Six",
|
| 59 |
+
"Seven",
|
| 60 |
+
"Eight"
|
| 61 |
+
],
|
| 62 |
+
"correct_answer": "Seven"
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"text": "What is the currency of Japan?",
|
| 66 |
+
"options": [
|
| 67 |
+
"Yuan",
|
| 68 |
+
"Won",
|
| 69 |
+
"Dollar",
|
| 70 |
+
"Yen"
|
| 71 |
+
],
|
| 72 |
+
"correct_answer": "Yen"
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"text": "What is the tallest mountain in the world?",
|
| 76 |
+
"options": [
|
| 77 |
+
"K2",
|
| 78 |
+
"Mount Everest",
|
| 79 |
+
"Kangchenjunga",
|
| 80 |
+
"Lhotse"
|
| 81 |
+
],
|
| 82 |
+
"correct_answer": "Mount Everest"
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"text": "What is the speed of light in a vacuum (approximately)?",
|
| 86 |
+
"options": [
|
| 87 |
+
"300000 km/s",
|
| 88 |
+
"150000 km/s",
|
| 89 |
+
"450000 km/s",
|
| 90 |
+
"200000 km/s"
|
| 91 |
+
],
|
| 92 |
+
"correct_answer": "300000 km/s"
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"text": "What is the powerhouse of the cell?",
|
| 96 |
+
"options": [
|
| 97 |
+
"Nucleus",
|
| 98 |
+
"Mitochondria",
|
| 99 |
+
"Ribosome",
|
| 100 |
+
"Endoplasmic Reticulum"
|
| 101 |
+
],
|
| 102 |
+
"correct_answer": "Mitochondria"
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"text": "What is the chemical symbol for gold?",
|
| 106 |
+
"options": [
|
| 107 |
+
"Au",
|
| 108 |
+
"Ag",
|
| 109 |
+
"Go",
|
| 110 |
+
"Gd"
|
| 111 |
+
],
|
| 112 |
+
"correct_answer": "Au"
|
| 113 |
+
},
|
| 114 |
+
{
|
| 115 |
+
"text": "Who wrote the play \"Hamlet\"?",
|
| 116 |
+
"options": [
|
| 117 |
+
"William Shakespeare",
|
| 118 |
+
"Jane Austen",
|
| 119 |
+
"Charles Dickens",
|
| 120 |
+
"George Orwell"
|
| 121 |
+
],
|
| 122 |
+
"correct_answer": "William Shakespeare"
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"text": "What is the largest ocean on Earth?",
|
| 126 |
+
"options": [
|
| 127 |
+
"Atlantic Ocean",
|
| 128 |
+
"Indian Ocean",
|
| 129 |
+
"Arctic Ocean",
|
| 130 |
+
"Pacific Ocean"
|
| 131 |
+
],
|
| 132 |
+
"correct_answer": "Pacific Ocean"
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"text": "What is the boiling point of water at standard pressure?",
|
| 136 |
+
"options": [
|
| 137 |
+
"100\u00b0C",
|
| 138 |
+
"0\u00b0C",
|
| 139 |
+
"50\u00b0C",
|
| 140 |
+
"212\u00b0F"
|
| 141 |
+
],
|
| 142 |
+
"correct_answer": "100\u00b0C"
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
"text": "What is the main gas in Earth's atmosphere?",
|
| 146 |
+
"options": [
|
| 147 |
+
"Oxygen",
|
| 148 |
+
"Carbon Dioxide",
|
| 149 |
+
"Nitrogen",
|
| 150 |
+
"Hydrogen"
|
| 151 |
+
],
|
| 152 |
+
"correct_answer": "Nitrogen"
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"text": "Who developed the theory of relativity?",
|
| 156 |
+
"options": [
|
| 157 |
+
"Isaac Newton",
|
| 158 |
+
"Albert Einstein",
|
| 159 |
+
"Galileo Galilei",
|
| 160 |
+
"Stephen Hawking"
|
| 161 |
+
],
|
| 162 |
+
"correct_answer": "Albert Einstein"
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
"text": "What is the smallest prime number?",
|
| 166 |
+
"options": [
|
| 167 |
+
"0",
|
| 168 |
+
"1",
|
| 169 |
+
"2",
|
| 170 |
+
"3"
|
| 171 |
+
],
|
| 172 |
+
"correct_answer": "2"
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"text": "What is the capital of Australia?",
|
| 176 |
+
"options": [
|
| 177 |
+
"Sydney",
|
| 178 |
+
"Melbourne",
|
| 179 |
+
"Canberra",
|
| 180 |
+
"Perth"
|
| 181 |
+
],
|
| 182 |
+
"correct_answer": "Canberra"
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"text": "What type of animal is a dolphin?",
|
| 186 |
+
"options": [
|
| 187 |
+
"Fish",
|
| 188 |
+
"Mammal",
|
| 189 |
+
"Reptile",
|
| 190 |
+
"Amphibian"
|
| 191 |
+
],
|
| 192 |
+
"correct_answer": "Mammal"
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
"text": "What is the name of Earth's natural satellite?",
|
| 196 |
+
"options": [
|
| 197 |
+
"Mars",
|
| 198 |
+
"Venus",
|
| 199 |
+
"Moon",
|
| 200 |
+
"Titan"
|
| 201 |
+
],
|
| 202 |
+
"correct_answer": "Moon"
|
| 203 |
+
}
|
| 204 |
+
],
|
| 205 |
+
"leaderboard": {
|
| 206 |
+
"GKJ": {
|
| 207 |
+
"score": 0
|
| 208 |
+
},
|
| 209 |
+
"JOHN": {
|
| 210 |
+
"score": 0
|
| 211 |
+
},
|
| 212 |
+
"JOOHN": {
|
| 213 |
+
"score": 0
|
| 214 |
+
},
|
| 215 |
+
"hffd": {
|
| 216 |
+
"score": 0
|
| 217 |
+
},
|
| 218 |
+
"g": {
|
| 219 |
+
"score": 0
|
| 220 |
+
},
|
| 221 |
+
"t": {
|
| 222 |
+
"score": 0
|
| 223 |
+
},
|
| 224 |
+
"": {
|
| 225 |
+
"score": 0
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
}
|
quiz_data/quiz_925005.json
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "Mol",
|
| 3 |
+
"questions": [
|
| 4 |
+
{
|
| 5 |
+
"text": "What is the capital of France?",
|
| 6 |
+
"options": [
|
| 7 |
+
"London",
|
| 8 |
+
"Berlin",
|
| 9 |
+
"Paris",
|
| 10 |
+
"Madrid"
|
| 11 |
+
],
|
| 12 |
+
"correct_answer": "Paris"
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"text": "Which planet is known as the Red Planet?",
|
| 16 |
+
"options": [
|
| 17 |
+
"Mars",
|
| 18 |
+
"Jupiter",
|
| 19 |
+
"Venus",
|
| 20 |
+
"Saturn"
|
| 21 |
+
],
|
| 22 |
+
"correct_answer": "Mars"
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"text": "What is the chemical symbol for water?",
|
| 26 |
+
"options": [
|
| 27 |
+
"Wa",
|
| 28 |
+
"H2O",
|
| 29 |
+
"Wo",
|
| 30 |
+
"HO2"
|
| 31 |
+
],
|
| 32 |
+
"correct_answer": "H2O"
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"text": "Who painted the Mona Lisa?",
|
| 36 |
+
"options": [
|
| 37 |
+
"Vincent van Gogh",
|
| 38 |
+
"Leonardo da Vinci",
|
| 39 |
+
"Pablo Picasso",
|
| 40 |
+
"Claude Monet"
|
| 41 |
+
],
|
| 42 |
+
"correct_answer": "Leonardo da Vinci"
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"text": "What is the largest mammal in the world?",
|
| 46 |
+
"options": [
|
| 47 |
+
"African Elephant",
|
| 48 |
+
"Blue Whale",
|
| 49 |
+
"Giraffe",
|
| 50 |
+
"Polar Bear"
|
| 51 |
+
],
|
| 52 |
+
"correct_answer": "Blue Whale"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"text": "How many continents are there?",
|
| 56 |
+
"options": [
|
| 57 |
+
"Five",
|
| 58 |
+
"Six",
|
| 59 |
+
"Seven",
|
| 60 |
+
"Eight"
|
| 61 |
+
],
|
| 62 |
+
"correct_answer": "Seven"
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"text": "What is the currency of Japan?",
|
| 66 |
+
"options": [
|
| 67 |
+
"Yuan",
|
| 68 |
+
"Won",
|
| 69 |
+
"Dollar",
|
| 70 |
+
"Yen"
|
| 71 |
+
],
|
| 72 |
+
"correct_answer": "Yen"
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"text": "What is the tallest mountain in the world?",
|
| 76 |
+
"options": [
|
| 77 |
+
"K2",
|
| 78 |
+
"Mount Everest",
|
| 79 |
+
"Kangchenjunga",
|
| 80 |
+
"Lhotse"
|
| 81 |
+
],
|
| 82 |
+
"correct_answer": "Mount Everest"
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"text": "What is the speed of light in a vacuum (approximately)?",
|
| 86 |
+
"options": [
|
| 87 |
+
"300000 km/s",
|
| 88 |
+
"150000 km/s",
|
| 89 |
+
"450000 km/s",
|
| 90 |
+
"200000 km/s"
|
| 91 |
+
],
|
| 92 |
+
"correct_answer": "300000 km/s"
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"text": "What is the powerhouse of the cell?",
|
| 96 |
+
"options": [
|
| 97 |
+
"Nucleus",
|
| 98 |
+
"Mitochondria",
|
| 99 |
+
"Ribosome",
|
| 100 |
+
"Endoplasmic Reticulum"
|
| 101 |
+
],
|
| 102 |
+
"correct_answer": "Mitochondria"
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"text": "What is the chemical symbol for gold?",
|
| 106 |
+
"options": [
|
| 107 |
+
"Au",
|
| 108 |
+
"Ag",
|
| 109 |
+
"Go",
|
| 110 |
+
"Gd"
|
| 111 |
+
],
|
| 112 |
+
"correct_answer": "Au"
|
| 113 |
+
},
|
| 114 |
+
{
|
| 115 |
+
"text": "Who wrote the play \"Hamlet\"?",
|
| 116 |
+
"options": [
|
| 117 |
+
"William Shakespeare",
|
| 118 |
+
"Jane Austen",
|
| 119 |
+
"Charles Dickens",
|
| 120 |
+
"George Orwell"
|
| 121 |
+
],
|
| 122 |
+
"correct_answer": "William Shakespeare"
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"text": "What is the largest ocean on Earth?",
|
| 126 |
+
"options": [
|
| 127 |
+
"Atlantic Ocean",
|
| 128 |
+
"Indian Ocean",
|
| 129 |
+
"Arctic Ocean",
|
| 130 |
+
"Pacific Ocean"
|
| 131 |
+
],
|
| 132 |
+
"correct_answer": "Pacific Ocean"
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"text": "What is the boiling point of water at standard pressure?",
|
| 136 |
+
"options": [
|
| 137 |
+
"100\u00b0C",
|
| 138 |
+
"0\u00b0C",
|
| 139 |
+
"50\u00b0C",
|
| 140 |
+
"212\u00b0F"
|
| 141 |
+
],
|
| 142 |
+
"correct_answer": "100\u00b0C"
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
"text": "What is the main gas in Earth's atmosphere?",
|
| 146 |
+
"options": [
|
| 147 |
+
"Oxygen",
|
| 148 |
+
"Carbon Dioxide",
|
| 149 |
+
"Nitrogen",
|
| 150 |
+
"Hydrogen"
|
| 151 |
+
],
|
| 152 |
+
"correct_answer": "Nitrogen"
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"text": "Who developed the theory of relativity?",
|
| 156 |
+
"options": [
|
| 157 |
+
"Isaac Newton",
|
| 158 |
+
"Albert Einstein",
|
| 159 |
+
"Galileo Galilei",
|
| 160 |
+
"Stephen Hawking"
|
| 161 |
+
],
|
| 162 |
+
"correct_answer": "Albert Einstein"
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
"text": "What is the smallest prime number?",
|
| 166 |
+
"options": [
|
| 167 |
+
"0",
|
| 168 |
+
"1",
|
| 169 |
+
"2",
|
| 170 |
+
"3"
|
| 171 |
+
],
|
| 172 |
+
"correct_answer": "2"
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"text": "What is the capital of Australia?",
|
| 176 |
+
"options": [
|
| 177 |
+
"Sydney",
|
| 178 |
+
"Melbourne",
|
| 179 |
+
"Canberra",
|
| 180 |
+
"Perth"
|
| 181 |
+
],
|
| 182 |
+
"correct_answer": "Canberra"
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"text": "What type of animal is a dolphin?",
|
| 186 |
+
"options": [
|
| 187 |
+
"Fish",
|
| 188 |
+
"Mammal",
|
| 189 |
+
"Reptile",
|
| 190 |
+
"Amphibian"
|
| 191 |
+
],
|
| 192 |
+
"correct_answer": "Mammal"
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
"text": "What is the name of Earth's natural satellite?",
|
| 196 |
+
"options": [
|
| 197 |
+
"Mars",
|
| 198 |
+
"Venus",
|
| 199 |
+
"Moon",
|
| 200 |
+
"Titan"
|
| 201 |
+
],
|
| 202 |
+
"correct_answer": "Moon"
|
| 203 |
+
}
|
| 204 |
+
],
|
| 205 |
+
"leaderboard": {
|
| 206 |
+
"John": {
|
| 207 |
+
"score": 0
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
}
|
quiz_manager.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
from collections import defaultdict
|
| 5 |
+
|
| 6 |
+
class QuizManager:
|
| 7 |
+
def __init__(self, data_dir="quiz_data"):
|
| 8 |
+
self.quizzes = self.load_quizzes(data_dir)
|
| 9 |
+
self.data_dir = data_dir
|
| 10 |
+
os.makedirs(self.data_dir, exist_ok=True)
|
| 11 |
+
|
| 12 |
+
def _get_quiz_file_path(self, game_pin):
|
| 13 |
+
return os.path.join(self.data_dir, f"quiz_{game_pin}.json")
|
| 14 |
+
|
| 15 |
+
def _get_leaderboard_file_path(self, game_pin):
|
| 16 |
+
return os.path.join(self.data_dir, f"leaderboard_{game_pin}.json")
|
| 17 |
+
|
| 18 |
+
def _generate_unique_pin(self):
|
| 19 |
+
"""Generates a unique 6-digit game pin."""
|
| 20 |
+
while True:
|
| 21 |
+
pin = str(random.randint(100000, 999999))
|
| 22 |
+
if pin not in self.quizzes:
|
| 23 |
+
return pin
|
| 24 |
+
|
| 25 |
+
def create_quiz(self, name):
|
| 26 |
+
"""Creates a new quiz and returns a unique game pin."""
|
| 27 |
+
game_pin = self._generate_unique_pin()
|
| 28 |
+
self.quizzes[game_pin] = {"name": name, "questions": [], "leaderboard": defaultdict(lambda: {"score": 0})}
|
| 29 |
+
self._save_quiz_data(game_pin)
|
| 30 |
+
return game_pin
|
| 31 |
+
|
| 32 |
+
def add_question(self, game_pin, text, options, correct_answer):
|
| 33 |
+
"""Adds a question to a specific quiz."""
|
| 34 |
+
if game_pin in self.quizzes:
|
| 35 |
+
self.quizzes[game_pin]["questions"].append({
|
| 36 |
+
"text": text,
|
| 37 |
+
"options": options,
|
| 38 |
+
"correct_answer": correct_answer
|
| 39 |
+
})
|
| 40 |
+
self._save_quiz_data(game_pin)
|
| 41 |
+
else:
|
| 42 |
+
raise ValueError("Invalid game pin.")
|
| 43 |
+
|
| 44 |
+
def get_quiz(self, game_pin):
|
| 45 |
+
"""Retrieves a quiz by its game pin."""
|
| 46 |
+
return self.quizzes.get(game_pin)
|
| 47 |
+
|
| 48 |
+
def load_quizzes(self, data_dir):
|
| 49 |
+
"""Loads quiz data from JSON files in the specified directory."""
|
| 50 |
+
quizzes = {}
|
| 51 |
+
os.makedirs(data_dir, exist_ok=True)
|
| 52 |
+
for filename in os.listdir(data_dir):
|
| 53 |
+
if filename.startswith("quiz_") and filename.endswith(".json"):
|
| 54 |
+
filepath = os.path.join(data_dir, filename)
|
| 55 |
+
try:
|
| 56 |
+
with open(filepath, 'r') as f:
|
| 57 |
+
data = json.load(f)
|
| 58 |
+
pin = filename.split("_")[1].split(".")[0]
|
| 59 |
+
quizzes[pin] = data
|
| 60 |
+
except Exception as e:
|
| 61 |
+
print(f"Error loading quiz from {filename}: {e}")
|
| 62 |
+
return quizzes
|
| 63 |
+
|
| 64 |
+
def _save_quiz_data(self, game_pin):
|
| 65 |
+
"""Saves the quiz data to a JSON file."""
|
| 66 |
+
filepath = self._get_quiz_file_path(game_pin)
|
| 67 |
+
try:
|
| 68 |
+
with open(filepath, 'w') as f:
|
| 69 |
+
json.dump(self.quizzes[game_pin], f, indent=4)
|
| 70 |
+
except Exception as e:
|
| 71 |
+
print(f"Error saving quiz data for {game_pin}: {e}")
|
| 72 |
+
|
| 73 |
+
def initialize_player_score(self, game_pin, player_name):
|
| 74 |
+
"""Initializes a player's score for a given quiz."""
|
| 75 |
+
if game_pin in self.quizzes:
|
| 76 |
+
if player_name not in self.quizzes[game_pin]["leaderboard"]:
|
| 77 |
+
self.quizzes[game_pin]["leaderboard"][player_name] = {"score": 0}
|
| 78 |
+
self._save_quiz_data(game_pin)
|
| 79 |
+
else:
|
| 80 |
+
raise ValueError("Invalid game pin.")
|
| 81 |
+
|
| 82 |
+
def record_answer(self, game_pin, player_name, is_correct):
|
| 83 |
+
"""Records a player's answer and updates their score."""
|
| 84 |
+
if game_pin in self.quizzes and player_name in self.quizzes[game_pin]["leaderboard"]:
|
| 85 |
+
if is_correct:
|
| 86 |
+
self.quizzes[game_pin]["leaderboard"][player_name]["score"] += 1
|
| 87 |
+
self._save_quiz_data(game_pin)
|
| 88 |
+
elif game_pin not in self.quizzes:
|
| 89 |
+
raise ValueError("Invalid game pin.")
|
| 90 |
+
elif player_name not in self.quizzes[game_pin]["leaderboard"]:
|
| 91 |
+
raise ValueError(f"Player '{player_name}' not found in game '{game_pin}'.")
|
| 92 |
+
|
| 93 |
+
def get_leaderboard(self, game_pin):
|
| 94 |
+
"""Retrieves the leaderboard for a given quiz, sorted by score."""
|
| 95 |
+
if game_pin in self.quizzes:
|
| 96 |
+
leaderboard = sorted(
|
| 97 |
+
self.quizzes[game_pin]["leaderboard"].items(),
|
| 98 |
+
key=lambda item: item[1]["score"],
|
| 99 |
+
reverse=True
|
| 100 |
+
)
|
| 101 |
+
return leaderboard
|
| 102 |
+
else:
|
| 103 |
+
raise ValueError("Invalid game pin.")
|
| 104 |
+
|
| 105 |
+
# Instantiate the quiz manager
|
| 106 |
+
quiz_manager = QuizManager()
|
qursioms.csv
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
question,option1,option2,option3,option4,correct_answer
|
| 2 |
+
What is the capital of France?,London,Berlin,Paris,Madrid,Paris
|
| 3 |
+
Which planet is known as the Red Planet?,Mars,Jupiter,Venus,Saturn,Mars
|
| 4 |
+
What is the chemical symbol for water?,Wa,H2O,Wo,HO2,H2O
|
| 5 |
+
Who painted the Mona Lisa?,Vincent van Gogh,Leonardo da Vinci,Pablo Picasso,Claude Monet,Leonardo da Vinci
|
| 6 |
+
What is the largest mammal in the world?,African Elephant,Blue Whale,Giraffe,Polar Bear,Blue Whale
|
| 7 |
+
How many continents are there?,Five,Six,Seven,Eight,Seven
|
| 8 |
+
What is the currency of Japan?,Yuan,Won,Dollar,Yen,Yen
|
| 9 |
+
What is the tallest mountain in the world?,K2,Mount Everest,Kangchenjunga,Lhotse,Mount Everest
|
| 10 |
+
What is the speed of light in a vacuum (approximately)?,300000 km/s,150000 km/s,450000 km/s,200000 km/s,300000 km/s
|
| 11 |
+
What is the powerhouse of the cell?,Nucleus,Mitochondria,Ribosome,Endoplasmic Reticulum,Mitochondria
|
| 12 |
+
What is the chemical symbol for gold?,Au,Ag,Go,Gd,Au
|
| 13 |
+
Who wrote the play "Hamlet"?,William Shakespeare,Jane Austen,Charles Dickens,George Orwell,William Shakespeare
|
| 14 |
+
What is the largest ocean on Earth?,Atlantic Ocean,Indian Ocean,Arctic Ocean,Pacific Ocean,Pacific Ocean
|
| 15 |
+
What is the boiling point of water at standard pressure?,100°C,0°C,50°C,212°F,100°C
|
| 16 |
+
What is the main gas in Earth's atmosphere?,Oxygen,Carbon Dioxide,Nitrogen,Hydrogen,Nitrogen
|
| 17 |
+
Who developed the theory of relativity?,Isaac Newton,Albert Einstein,Galileo Galilei,Stephen Hawking,Albert Einstein
|
| 18 |
+
What is the smallest prime number?,0,1,2,3,2
|
| 19 |
+
What is the capital of Australia?,Sydney,Melbourne,Canberra,Perth,Canberra
|
| 20 |
+
What type of animal is a dolphin?,Fish,Mammal,Reptile,Amphibian,Mammal
|
| 21 |
+
What is the name of Earth's natural satellite?,Mars,Venus,Moon,Titan,Moon
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio
|