Fixed more or less reading import, attempted to do listening

This commit is contained in:
Carlos-Mesquita
2024-11-10 06:46:58 +00:00
parent 6909d75eb6
commit afeaf118c6
33 changed files with 3712 additions and 86 deletions

32
app/mappers/listening.py Normal file
View File

@@ -0,0 +1,32 @@
from typing import Dict, Any
from app.dtos.exams.listening import TrueFalseExercise, MultipleChoiceExercise, WriteBlanksExercise, ListeningExam, \
ListeningSection
class ListeningMapper:
@staticmethod
def map_to_test_model(response: Dict[str, Any]) -> ListeningExam:
sections = []
for section in response.get('sections', []):
section_exercises = []
for exercise in section['exercises']:
exercise_type = exercise['type']
if exercise_type == 'trueFalse':
section_exercises.append(TrueFalseExercise(**exercise))
elif exercise_type == 'multipleChoice':
section_exercises.append(MultipleChoiceExercise(**exercise))
elif exercise_type == 'writeBlanks':
section_exercises.append(WriteBlanksExercise(**exercise))
else:
raise ValueError(f"Unknown exercise type: {exercise_type}")
sections.append(ListeningSection(exercises=section_exercises))
return ListeningExam(
sections=sections,
minTimer=response.get('minTimer'),
module="listening"
)

View File

@@ -3,7 +3,7 @@ from typing import Dict, Any
from app.dtos.exams.reading import (
Part, Exam, Context, FillBlanksExercise,
TrueFalseExercise, MatchSentencesExercise,
WriteBlanksExercise
WriteBlanksExercise, MultipleChoice
)
@@ -20,13 +20,18 @@ class ReadingMapper:
'fillBlanks': FillBlanksExercise,
'trueFalse': TrueFalseExercise,
'matchSentences': MatchSentencesExercise,
'writeBlanks': WriteBlanksExercise
'writeBlanks': WriteBlanksExercise,
'multipleChoice': MultipleChoice,
}
exercises = []
for exercise in part_exercises:
exercise_type = exercise['type']
exercises.append(model_map[exercise_type](**exercise))
if exercise_type in model_map:
model_class = model_map[exercise_type]
exercises.append(model_class(**exercise))
else:
raise ValueError(f"Unknown exercise type: {exercise_type}")
part_kwargs = {
"exercises": exercises,