✨ Added new Question-Type: TextAnswers!
This commit is contained in:
@@ -115,21 +115,19 @@ class QuizQuestionType(str, Enum):
|
||||
RANGE = "RANGE"
|
||||
VOTING = "VOTING"
|
||||
SLIDE = "SLIDE"
|
||||
|
||||
|
||||
class SlideElementTypes(str, Enum):
|
||||
TEXT = "TEXT"
|
||||
HEADLINE = "HEADLINE"
|
||||
IMAGE = "IMAGE"
|
||||
RECTANGLE = "RECTANGLE"
|
||||
CIRCLE = "CIRCLE"
|
||||
|
||||
|
||||
class TextQuizAnswer(BaseModel):
|
||||
answer: str
|
||||
case_sensitive: bool
|
||||
|
||||
|
||||
class QuizQuestion(BaseModel):
|
||||
question: str
|
||||
time: str # in Secs
|
||||
type: None | QuizQuestionType = QuizQuestionType.ABCD
|
||||
answers: list[ABCDQuizAnswer] | RangeQuizAnswer | list[VotingQuizAnswer] | str
|
||||
answers: list[ABCDQuizAnswer] | RangeQuizAnswer | list[TextQuizAnswer] | list[VotingQuizAnswer] | str
|
||||
image: str | None = None
|
||||
|
||||
@validator("answers")
|
||||
@@ -140,6 +138,8 @@ class QuizQuestion(BaseModel):
|
||||
raise ValueError("Answer must be from type RangeQuizAnswer if type is RANGE")
|
||||
if values["type"] == QuizQuestionType.VOTING and type(v[0]) != VotingQuizAnswer:
|
||||
raise ValueError("Answer must be from type VotingQuizAnswer if type is VOTING")
|
||||
if values["type"] == QuizQuestionType.TEXT and type(v[0]) != TextQuizAnswer:
|
||||
raise ValueError("Answer must be from type TextQuizAnswer if type is TEXT")
|
||||
if values["type"] == QuizQuestionType.SLIDE and type(v[0]) != str:
|
||||
raise ValueError("Answer must be from type SlideElement if type is SLIDE")
|
||||
return v
|
||||
|
||||
@@ -209,6 +209,7 @@ class RangeQuizAnswerWithoutSolution(BaseModel):
|
||||
|
||||
class ReturnQuestion(QuizQuestion):
|
||||
answers: list[ABCDQuizAnswerWithoutSolution] | RangeQuizAnswerWithoutSolution | list[VotingQuizAnswer]
|
||||
type: QuizQuestionType = QuizQuestionType.ABCD
|
||||
|
||||
@validator("answers")
|
||||
def answers_not_none_if_abcd_type(cls, v, values):
|
||||
@@ -226,7 +227,7 @@ class ReturnQuestion(QuizQuestion):
|
||||
async def set_question_number(sid, data: str):
|
||||
# data is just a number (as a str) of the question
|
||||
session = await sio.get_session(sid)
|
||||
print("set_question_number", data, session)
|
||||
# print("set_question_number", data, session)
|
||||
if session["admin"]:
|
||||
game_pin = session["game_pin"]
|
||||
game_data = PlayGame.parse_raw(await redis.get(f"game:{session['game_pin']}"))
|
||||
@@ -246,7 +247,8 @@ async def set_question_number(sid, data: str):
|
||||
if game_data.questions[int(float(data))].type == QuizQuestionType.VOTING:
|
||||
for i in range(len(temp_return["answers"])):
|
||||
temp_return["answers"][i] = VotingQuizAnswer(**temp_return["answers"][i])
|
||||
print("emitting")
|
||||
temp_return["type"] = game_data.questions[int(float(data))].type
|
||||
# print("emitting")
|
||||
await sio.emit(
|
||||
"set_question_number",
|
||||
{
|
||||
@@ -301,6 +303,17 @@ async def submit_answer(sid: str, data: dict):
|
||||
answer_right = True
|
||||
elif game_data.questions[int(float(data.question_index))].type == QuizQuestionType.VOTING:
|
||||
answer_right = False
|
||||
elif game_data.questions[int(float(data.question_index))].type == QuizQuestionType.TEXT:
|
||||
answer_right = False
|
||||
for q in game_data.questions[int(float(data.question_index))].answers:
|
||||
if q.case_sensitive:
|
||||
if data.answer == q.answer:
|
||||
answer_right = True
|
||||
break
|
||||
else:
|
||||
if data.answer.lower() == q.answer.lower():
|
||||
answer_right = True
|
||||
break
|
||||
else:
|
||||
raise NotImplementedError
|
||||
latency = int(float((await sio.get_session(sid))["ping"]))
|
||||
|
||||
Reference in New Issue
Block a user