Source code for jump_starter.models

from datetime import datetime
from typing import Union

from pydantic import BaseModel, Field


[docs] class Template(BaseModel): """Represents a template for code replacement in the questionnaire."""
[docs] replacement: str
[docs] code: str
[docs] class Answer(BaseModel): """Represents an answer to a question in the questionnaire."""
[docs] answer: str
[docs] tooltip: str = ""
[docs] templates: list[Template] = Field(default_factory=list)
[docs] followups: list[Union["Question", "Switch"]] = Field(default_factory=list)
[docs] commentary: str = ""
[docs] class Question(BaseModel): """Represents a question in the questionnaire."""
[docs] question: str
[docs] variable: str | None = None
[docs] answers: list[Answer]
[docs] class Case(BaseModel): """Represents a case in a switch statement within the questionnaire."""
[docs] value: int | None = None
[docs] questions: list[Union[Question, "Switch"]]
[docs] class Switch(BaseModel): """Represents a switch statement in the questionnaire."""
[docs] switch: str
[docs] cases: list[Case]
# Rebuild models to support self-referencing types and forward references Question.model_rebuild() Answer.model_rebuild() Case.model_rebuild() Switch.model_rebuild()
[docs] class QuestionAnswer(BaseModel): """Represents a user's answer to a question."""
[docs] question: str
[docs] answer: str
[docs] value: int
[docs] class QuestionAnswers(BaseModel): """Represents a collection of user answers to questions."""
[docs] answers: list[QuestionAnswer] = Field(default_factory=list)
[docs] timestamp: datetime = Field(default_factory=datetime.now)
[docs] class Questionnaire(BaseModel): """Represents a questionnaire with an initial template and a list of questions."""
[docs] initial_template: str
[docs] initial_commentary: str = ""
[docs] feedback_url: str | None = None
[docs] questions: list[Question | Switch]