-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathquiz.py
More file actions
82 lines (65 loc) · 1.87 KB
/
Copy pathquiz.py
File metadata and controls
82 lines (65 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# app/models/quiz.py
from pydantic import BaseModel, Field, HttpUrl
from typing import List, Optional
from bson import ObjectId
from datetime import datetime
import pytz
IST = pytz.timezone("Asia/Kolkata")
class EndQuizRequest(BaseModel):
name: str
class QuizStart(BaseModel):
password: int
name: str
class AnswerSubmission(BaseModel):
name: str
answers: List[str]
# Question model to represent individual question details
class Question(BaseModel):
question: str
choice_A: str
choice_B: str
choice_C: str
choice_D: str
answer: str # Should be one of "A", "B", "C", or "D"
is_correct: Optional[bool] = False
# QuizCreate model – input from client
class QuizCreate(BaseModel):
name: str
subject: str
num_questions: int
# trigger_link: HttpUrl
# questions: List[Question]
topic: str
difficulty_level: int
class QuestionUpdate(BaseModel):
question: str
choice_A: str
choice_B: str
choice_C: str
choice_D: str
answer: str
is_correct: bool
# Main Quiz model – includes fields auto-populated by backend
class Quiz(BaseModel):
id: str = Field(default_factory=lambda: str(ObjectId()), alias="_id")
name: str
subject: str
created_by: str
created_at: datetime = Field(default_factory=datetime.now(IST))
metadata_fields: Optional[dict] = Field(default_factory=dict)
trigger_link: HttpUrl
taken_by: List[str]
num_questions: int
questions: List[Question]
user_responses: List[dict]
is_started: bool = False
start_time: Optional[datetime] = None
end_time: Optional[datetime] = None
exec_time: Optional[float] = None # in seconds
topic: str
difficulty_level: int
password: int
is_executed: bool = False
class Config:
json_encoders = {ObjectId: str, datetime: lambda v: v.isoformat()}
populate_by_name = True