Eval Update

This commit is contained in:
Carlos-Mesquita
2024-12-28 03:31:17 +00:00
parent 984ecbb824
commit f0453d06c7
3 changed files with 41 additions and 56 deletions

View File

@@ -6,17 +6,6 @@ from ielts_be.dtos.evaluation import EvaluationType
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
async def begin_evaluation(
self,

View File

@@ -1,5 +1,5 @@
import logging
from typing import Union, List
from typing import Union, List, Dict
from fastapi import BackgroundTasks
@@ -18,26 +18,6 @@ class EvaluationService(IEvaluationService):
self._speaking_service = speaking_service
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(
self,
user_id: str, session_id: str, task: int,
@@ -71,34 +51,58 @@ class EvaluationService(IEvaluationService):
solution
)
await self._db.update(
eval_res = await self._db.find(
"evaluation",
{
"user": user_id,
"exercise_id": exercise_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:
self._logger.error(f"Error processing evaluation {session_id} - {exercise_id}: {str(e)}")
await self._db.update(
eval_res = await self._db.find(
"evaluation",
{
"user": user_id,
"exercise_id": exercise_id,
"session_id": session_id
},
{
"$set": {
"status": "error",
"error": str(e),
}
"session_id": session_id,
}
)
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.")