Spaces:
Sleeping
Sleeping
Update modules/database/current_situation_mongo_db.py
Browse files
modules/database/current_situation_mongo_db.py
CHANGED
|
@@ -6,6 +6,8 @@ from .mongo_db import get_collection
|
|
| 6 |
logger = logging.getLogger(__name__)
|
| 7 |
COLLECTION_NAME = 'student_current_situation'
|
| 8 |
|
|
|
|
|
|
|
| 9 |
def store_current_situation_result(username, text, metrics, feedback):
|
| 10 |
"""
|
| 11 |
Guarda los resultados del an谩lisis de situaci贸n actual.
|
|
@@ -21,54 +23,32 @@ def store_current_situation_result(username, text, metrics, feedback):
|
|
| 21 |
logger.error("No se pudo obtener la colecci贸n")
|
| 22 |
return False
|
| 23 |
|
| 24 |
-
# Formatear m茅tricas para MongoDB
|
| 25 |
-
formatted_metrics = {
|
| 26 |
-
'vocabulary': {
|
| 27 |
-
'score': metrics['vocabulary']['normalized_score'],
|
| 28 |
-
'details': metrics['vocabulary']['details']
|
| 29 |
-
},
|
| 30 |
-
'structure': {
|
| 31 |
-
'score': metrics['structure']['normalized_score'],
|
| 32 |
-
'details': metrics['structure']['details']
|
| 33 |
-
},
|
| 34 |
-
'cohesion': {
|
| 35 |
-
'score': metrics['cohesion']['normalized_score'],
|
| 36 |
-
'details': metrics['cohesion']['details']
|
| 37 |
-
},
|
| 38 |
-
'clarity': {
|
| 39 |
-
'score': metrics['clarity']['normalized_score'],
|
| 40 |
-
'details': metrics['clarity']['details']
|
| 41 |
-
}
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
# Crear documento
|
| 45 |
document = {
|
| 46 |
'username': username,
|
| 47 |
'timestamp': datetime.now(timezone.utc).isoformat(),
|
| 48 |
'text': text,
|
| 49 |
-
'metrics':
|
| 50 |
-
'feedback': feedback,
|
| 51 |
'analysis_type': 'current_situation'
|
| 52 |
}
|
| 53 |
|
| 54 |
-
# Insertar documento
|
| 55 |
result = collection.insert_one(document)
|
| 56 |
if result.inserted_id:
|
| 57 |
logger.info(f"""
|
| 58 |
-
An谩lisis guardado
|
| 59 |
- Usuario: {username}
|
| 60 |
- ID: {result.inserted_id}
|
| 61 |
-
- Longitud
|
| 62 |
-
- M茅tricas: {formatted_metrics}
|
| 63 |
""")
|
| 64 |
|
| 65 |
# Verificar almacenamiento
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
return True
|
| 69 |
-
else:
|
| 70 |
logger.warning("Verificaci贸n de almacenamiento fall贸")
|
| 71 |
-
|
|
|
|
| 72 |
|
| 73 |
logger.error("No se pudo insertar el documento")
|
| 74 |
return False
|
|
|
|
| 6 |
logger = logging.getLogger(__name__)
|
| 7 |
COLLECTION_NAME = 'student_current_situation'
|
| 8 |
|
| 9 |
+
# En modules/database/current_situation_mongo_db.py
|
| 10 |
+
|
| 11 |
def store_current_situation_result(username, text, metrics, feedback):
|
| 12 |
"""
|
| 13 |
Guarda los resultados del an谩lisis de situaci贸n actual.
|
|
|
|
| 23 |
logger.error("No se pudo obtener la colecci贸n")
|
| 24 |
return False
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# Crear documento
|
| 27 |
document = {
|
| 28 |
'username': username,
|
| 29 |
'timestamp': datetime.now(timezone.utc).isoformat(),
|
| 30 |
'text': text,
|
| 31 |
+
'metrics': metrics,
|
| 32 |
+
'feedback': feedback or {},
|
| 33 |
'analysis_type': 'current_situation'
|
| 34 |
}
|
| 35 |
|
| 36 |
+
# Insertar documento y verificar
|
| 37 |
result = collection.insert_one(document)
|
| 38 |
if result.inserted_id:
|
| 39 |
logger.info(f"""
|
| 40 |
+
An谩lisis de situaci贸n actual guardado:
|
| 41 |
- Usuario: {username}
|
| 42 |
- ID: {result.inserted_id}
|
| 43 |
+
- Longitud texto: {len(text)}
|
|
|
|
| 44 |
""")
|
| 45 |
|
| 46 |
# Verificar almacenamiento
|
| 47 |
+
storage_verified = verify_storage(username)
|
| 48 |
+
if not storage_verified:
|
|
|
|
|
|
|
| 49 |
logger.warning("Verificaci贸n de almacenamiento fall贸")
|
| 50 |
+
|
| 51 |
+
return True
|
| 52 |
|
| 53 |
logger.error("No se pudo insertar el documento")
|
| 54 |
return False
|