Feat: first step in assessment aggregate

This commit is contained in:
Bertrand Benjamin 2022-12-20 07:18:48 +01:00
parent c4fcb6a0ef
commit e496d86828
2 changed files with 124 additions and 0 deletions

View File

@ -0,0 +1,68 @@
from __future__ import annotations
from dataclasses import dataclass
from datetime import date
from typing import Optional
from backend.model.student import Tribe
class Assessment:
def __init__(self, name: str, tribe: Tribe, term: int) -> None:
self.tribe = tribe
self.term = term
self.name = name
self.exercises = []
def register_exercise(self, exercise: Exercise):
self.exercises.append(exercise)
@property
def questions(self):
return sum([exercise.questions for exercise in self.exercises])
class Exercise:
def __init__(self, name: str, assessment: Assessment, date: Optional[date]) -> None:
self.name = name
self.assessment = assessment
self.date = date
self.questions = []
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
class Question:
def __init__(
self,
name: str,
exercise: Exercise,
description: str,
skill: Skill,
domain: Domain,
is_leveled: bool,
scale: int,
) -> None:
self.name = name
self.exercise = exercise
self.exercise.register_question(self)
self.description = description
self.skill = skill
self.domain = domain
self.is_leveled = is_leveled
self.scale = scale

View File

@ -0,0 +1,56 @@
from backend.model.assessment import Assessment, Domain, Exercise, Question, Skill
from backend.model.student import Tribe
def build_tribe():
return Tribe("plop", "2nd")
def build_tribe_assessment():
tribe = build_tribe()
assessment = Assessment("DS1", tribe, 1)
return tribe, assessment
def build_tribe_assessment_exercise():
tribe, assessment = build_tribe_assessment()
exercise = Exercise("ex1", assessment, "today")
return tribe, assessment, exercise
def build_skills():
return [Skill("search", "Searching and finding")]
def build_domains():
return [Domain("function", "Functions are great")]
def build_tribe_assessment_exercise_question():
tribe, assessment, exercise = build_tribe_assessment_exercise()
skills = build_skills()
domains = build_domains()
question = Question(
"a",
exercise,
description="desc",
skill=skills[0],
domain=domains[0],
is_leveled=True,
scale=1,
)
return tribe, assessment, exercise, question
def test_assessement_register_exercise():
tribe, assessment, exercise = build_tribe_assessment_exercise()
assert len(assessment.exercises) == 1
assert assessment.exercises[0] == exercise
def test_exercise_register_question():
tribe, assessment, exercise, question = build_tribe_assessment_exercise_question()
assert len(exercise.questions) == 1
assert exercise.questions[0] == question