Eval Update
This commit is contained in:
@@ -25,10 +25,6 @@ class GradeController(IGradeController):
|
|||||||
self,
|
self,
|
||||||
task: int, dto: WritingGradeTaskDTO, background_tasks: BackgroundTasks
|
task: int, dto: WritingGradeTaskDTO, background_tasks: BackgroundTasks
|
||||||
):
|
):
|
||||||
await self._evaluation_service.create_evaluation(
|
|
||||||
dto.userId, dto.sessionId, dto.exerciseId, EvaluationType.WRITING, task
|
|
||||||
)
|
|
||||||
|
|
||||||
await self._evaluation_service.begin_evaluation(
|
await self._evaluation_service.begin_evaluation(
|
||||||
dto.userId, dto.sessionId, task, dto.exerciseId, EvaluationType.WRITING, dto, background_tasks
|
dto.userId, dto.sessionId, task, dto.exerciseId, EvaluationType.WRITING, dto, background_tasks
|
||||||
)
|
)
|
||||||
@@ -79,10 +75,6 @@ class GradeController(IGradeController):
|
|||||||
|
|
||||||
ex_type = EvaluationType.SPEAKING if task == 2 else EvaluationType.SPEAKING_INTERACTIVE
|
ex_type = EvaluationType.SPEAKING if task == 2 else EvaluationType.SPEAKING_INTERACTIVE
|
||||||
|
|
||||||
await self._evaluation_service.create_evaluation(
|
|
||||||
user_id, session_id, exercise_id, ex_type, task
|
|
||||||
)
|
|
||||||
|
|
||||||
await self._evaluation_service.begin_evaluation(
|
await self._evaluation_service.begin_evaluation(
|
||||||
user_id, session_id, task, exercise_id, ex_type, items, background_tasks
|
user_id, session_id, task, exercise_id, ex_type, items, background_tasks
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,17 +6,6 @@ from ielts_be.dtos.evaluation import EvaluationType
|
|||||||
|
|
||||||
class IEvaluationService(ABC):
|
class IEvaluationService(ABC):
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def create_evaluation(
|
|
||||||
self,
|
|
||||||
user_id: str,
|
|
||||||
session_id: str,
|
|
||||||
exercise_id: str,
|
|
||||||
eval_type: EvaluationType,
|
|
||||||
task: int
|
|
||||||
):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def begin_evaluation(
|
async def begin_evaluation(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Union, List
|
from typing import Union, List, Dict
|
||||||
|
|
||||||
from fastapi import BackgroundTasks
|
from fastapi import BackgroundTasks
|
||||||
|
|
||||||
@@ -18,26 +18,6 @@ class EvaluationService(IEvaluationService):
|
|||||||
self._speaking_service = speaking_service
|
self._speaking_service = speaking_service
|
||||||
self._logger = logging.getLogger(__name__)
|
self._logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
async def create_evaluation(
|
|
||||||
self,
|
|
||||||
user_id: str,
|
|
||||||
session_id: str,
|
|
||||||
exercise_id: str,
|
|
||||||
eval_type: EvaluationType,
|
|
||||||
task: int
|
|
||||||
):
|
|
||||||
await self._db.save_to_db(
|
|
||||||
"evaluation",
|
|
||||||
{
|
|
||||||
"user": user_id,
|
|
||||||
"session_id": session_id,
|
|
||||||
"exercise_id": exercise_id,
|
|
||||||
"type": eval_type,
|
|
||||||
"task": task,
|
|
||||||
"status": "pending"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
async def begin_evaluation(
|
async def begin_evaluation(
|
||||||
self,
|
self,
|
||||||
user_id: str, session_id: str, task: int,
|
user_id: str, session_id: str, task: int,
|
||||||
@@ -71,34 +51,58 @@ class EvaluationService(IEvaluationService):
|
|||||||
solution
|
solution
|
||||||
)
|
)
|
||||||
|
|
||||||
await self._db.update(
|
eval_res = await self._db.find(
|
||||||
"evaluation",
|
"evaluation",
|
||||||
{
|
{
|
||||||
"user": user_id,
|
"user": user_id,
|
||||||
"exercise_id": exercise_id,
|
"exercise_id": exercise_id,
|
||||||
"session_id": session_id,
|
"session_id": session_id,
|
||||||
},
|
|
||||||
{
|
|
||||||
"$set": {
|
|
||||||
"status": "completed",
|
|
||||||
"result": result,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if len(eval_res) > 0:
|
||||||
|
await self._db.update(
|
||||||
|
"evaluation",
|
||||||
|
{
|
||||||
|
"user": user_id,
|
||||||
|
"exercise_id": exercise_id,
|
||||||
|
"session_id": session_id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$set": {
|
||||||
|
"status": "completed",
|
||||||
|
"result": result,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self._logger.info("Skipping evaluation write to db since the record was removed.")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(f"Error processing evaluation {session_id} - {exercise_id}: {str(e)}")
|
eval_res = await self._db.find(
|
||||||
await self._db.update(
|
|
||||||
"evaluation",
|
"evaluation",
|
||||||
{
|
{
|
||||||
"user": user_id,
|
"user": user_id,
|
||||||
"exercise_id": exercise_id,
|
"exercise_id": exercise_id,
|
||||||
"session_id": session_id
|
"session_id": session_id,
|
||||||
},
|
|
||||||
{
|
|
||||||
"$set": {
|
|
||||||
"status": "error",
|
|
||||||
"error": str(e),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if len(eval_res) > 0:
|
||||||
|
self._logger.error(f"Error processing evaluation {session_id} - {exercise_id}: {str(e)}")
|
||||||
|
await self._db.update(
|
||||||
|
"evaluation",
|
||||||
|
{
|
||||||
|
"user": user_id,
|
||||||
|
"exercise_id": exercise_id,
|
||||||
|
"session_id": session_id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$set": {
|
||||||
|
"status": "error",
|
||||||
|
"error": str(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self._logger.info("Skipping evaluation write to db since the record was removed.")
|
||||||
|
|||||||
Reference in New Issue
Block a user