recopytex/backend/model/assessment.py

70 lines
1.3 KiB
Python

from __future__ import annotations
from dataclasses import dataclass, field
from datetime import date
from typing import TYPE_CHECKING, Optional
if TYPE_CHECKING:
from backend.model.tribe import Tribe
@dataclass
class Assessment:
name: str
tribe: Tribe
term: int
exercises: list[Exercise] = field(default_factory=list)
def __post_init__(self) -> None:
self.tribe.register_assessment(self)
def register_exercise(self, exercise: Exercise):
self.exercises.append(exercise)
@property
def questions(self):
return sum([exercise.questions for exercise in self.exercises])
@dataclass
class Exercise:
name: str
assessment: Assessment
date: Optional[date]
questions: list[Question] = field(default_factory=list)
def __post_init__(self) -> None:
self.assessment.register_exercise(self)
def register_question(self, question: Question):
self.questions.append(question)
@dataclass(frozen=True)
class Domain:
name: str
description: str
@dataclass(frozen=True)
class Skill:
name: str
description: str
@dataclass
class Question:
name: str
exercise: Exercise
description: str
skill: Skill
domain: Domain
is_leveled: bool
scale: int
def __post_init__(
self,
) -> None:
self.exercise.register_question(self)