|
|
|
|
|
from datetime import datetime, timezone |
|
import logging |
|
from .mongo_db import get_collection, insert_document, find_documents |
|
|
|
logger = logging.getLogger(__name__) |
|
COLLECTION_NAME = 'student_current_situation' |
|
|
|
|
|
def store_current_situation_result(username, text, metrics, feedback): |
|
""" |
|
Guarda los resultados del análisis de situación actual. |
|
""" |
|
try: |
|
|
|
if not all([username, text, metrics]): |
|
logger.error("Faltan parámetros requeridos") |
|
return False |
|
|
|
collection = get_collection('student_current_situation') |
|
if collection is None: |
|
logger.error("No se pudo obtener la colección") |
|
return False |
|
|
|
|
|
formatted_metrics = { |
|
'vocabulary': { |
|
'score': metrics['vocabulary']['normalized_score'], |
|
'details': metrics['vocabulary']['details'] |
|
}, |
|
'structure': { |
|
'score': metrics['structure']['normalized_score'], |
|
'details': metrics['structure']['details'] |
|
}, |
|
'cohesion': { |
|
'score': metrics['cohesion']['normalized_score'], |
|
'details': metrics['cohesion']['details'] |
|
}, |
|
'clarity': { |
|
'score': metrics['clarity']['normalized_score'], |
|
'details': metrics['clarity']['details'] |
|
} |
|
} |
|
|
|
|
|
document = { |
|
'username': username, |
|
'timestamp': datetime.now(timezone.utc).isoformat(), |
|
'text': text, |
|
'metrics': metrics, |
|
'feedback': feedback, |
|
'analysis_type': 'current_situation' |
|
} |
|
|
|
|
|
result = collection.insert_one(document) |
|
|
|
if result.inserted_id: |
|
logger.info(f""" |
|
Análisis guardado exitosamente: |
|
- Usuario: {username} |
|
- ID: {result.inserted_id} |
|
- Longitud del texto: {len(text)} |
|
- Métricas: {formatted_metrics} |
|
""") |
|
return True |
|
|
|
logger.error("No se pudo insertar el documento") |
|
return False |
|
|
|
except Exception as e: |
|
logger.error(f"Error guardando análisis de situación actual: {str(e)}") |
|
return False |