Added suport for speaking exercises in training content
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
@@ -196,10 +197,16 @@ class TrainingContentService:
|
|||||||
self._get_reading_solutions(stat, exam))
|
self._get_reading_solutions(stat, exam))
|
||||||
elif module == "writing":
|
elif module == "writing":
|
||||||
exercises[session_key][module][exam_id]["exercises"].extend(
|
exercises[session_key][module][exam_id]["exercises"].extend(
|
||||||
self._get_writing_prompts_and_answers(stat, exam))
|
self._get_writing_prompts_and_answers(stat, exam)
|
||||||
|
)
|
||||||
|
elif module == "speaking":
|
||||||
|
exercises[session_key][module][exam_id]["exercises"].extend(
|
||||||
|
self._get_speaking_solutions(stat, exam)
|
||||||
|
)
|
||||||
elif module == "level": # same structure as listening
|
elif module == "level": # same structure as listening
|
||||||
exercises[session_key][module][exam_id]["exercises"].extend(
|
exercises[session_key][module][exam_id]["exercises"].extend(
|
||||||
self._get_listening_solutions(stat, exam))
|
self._get_listening_solutions(stat, exam)
|
||||||
|
)
|
||||||
|
|
||||||
exam_map[session_key]["score"] = round((exam_total_correct / exam_total_questions) * 100)
|
exam_map[session_key]["score"] = round((exam_total_correct / exam_total_questions) * 100)
|
||||||
exam_map[session_key]["module"] = module
|
exam_map[session_key]["module"] = module
|
||||||
@@ -243,7 +250,7 @@ class TrainingContentService:
|
|||||||
"solution": exercise["solutions"],
|
"solution": exercise["solutions"],
|
||||||
"answer": stat["solutions"]
|
"answer": stat["solutions"]
|
||||||
})
|
})
|
||||||
if stat["type"] == "multipleChoice":
|
elif stat["type"] == "multipleChoice":
|
||||||
result.append({
|
result.append({
|
||||||
"question": exercise["prompt"],
|
"question": exercise["prompt"],
|
||||||
"exercise": exercise["questions"],
|
"exercise": exercise["questions"],
|
||||||
@@ -253,6 +260,35 @@ class TrainingContentService:
|
|||||||
self._logger.warning(f"Malformed stat object: {str(e)}")
|
self._logger.warning(f"Malformed stat object: {str(e)}")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def _get_speaking_solutions(self, stat, exam):
|
||||||
|
result = {}
|
||||||
|
try:
|
||||||
|
result = {
|
||||||
|
"comments": {
|
||||||
|
key: value['comment'] for key, value in stat['solutions'][0]['evaluation']['task_response'].items()}
|
||||||
|
,
|
||||||
|
"exercises": {}
|
||||||
|
}
|
||||||
|
|
||||||
|
for exercise in exam["exercises"]:
|
||||||
|
if exercise["id"] == stat["exercise"]:
|
||||||
|
if stat["type"] == "interactiveSpeaking":
|
||||||
|
for i in range(len(exercise["prompts"])):
|
||||||
|
result["exercises"][f"exercise_{i+1}"] = {
|
||||||
|
"question": exercise["prompts"][i]["text"]
|
||||||
|
}
|
||||||
|
for i in range(len(exercise["prompts"])):
|
||||||
|
answer = stat['solutions'][0]["evaluation"].get(f'transcript_{i+1}', '')
|
||||||
|
result["exercises"][f"exercise_{i+1}"]["answer"] = answer
|
||||||
|
elif stat["type"] == "speaking":
|
||||||
|
result["exercises"]["exercise_1"] = {
|
||||||
|
"question": exercise["text"],
|
||||||
|
"answer": stat['solutions'][0]["evaluation"].get(f'transcript', '')
|
||||||
|
}
|
||||||
|
except KeyError as e:
|
||||||
|
self._logger.warning(f"Malformed stat object: {str(e)}")
|
||||||
|
return [result]
|
||||||
|
|
||||||
def _get_reading_solutions(self, stat, exam):
|
def _get_reading_solutions(self, stat, exam):
|
||||||
result = []
|
result = []
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user