Update modules/database/current_situation_mongo_db.py
Browse files
modules/database/current_situation_mongo_db.py
CHANGED
@@ -9,6 +9,10 @@ COLLECTION_NAME = 'student_current_situation'
|
|
9 |
|
10 |
# En modules/database/current_situation_mongo_db.py
|
11 |
def store_current_situation_result(username, text, metrics, feedback):
|
|
|
|
|
|
|
|
|
12 |
"""
|
13 |
Guarda los resultados del an谩lisis de situaci贸n actual.
|
14 |
"""
|
@@ -71,4 +75,38 @@ def store_current_situation_result(username, text, metrics, feedback):
|
|
71 |
|
72 |
except Exception as e:
|
73 |
logger.error(f"Error guardando an谩lisis de situaci贸n actual: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
return False
|
|
|
9 |
|
10 |
# En modules/database/current_situation_mongo_db.py
|
11 |
def store_current_situation_result(username, text, metrics, feedback):
|
12 |
+
success = store_current_situation_result(username, text, metrics, feedback)
|
13 |
+
if success:
|
14 |
+
verify_storage(username) #Verificar que se guarda correctamente
|
15 |
+
return success
|
16 |
"""
|
17 |
Guarda los resultados del an谩lisis de situaci贸n actual.
|
18 |
"""
|
|
|
75 |
|
76 |
except Exception as e:
|
77 |
logger.error(f"Error guardando an谩lisis de situaci贸n actual: {str(e)}")
|
78 |
+
return False
|
79 |
+
|
80 |
+
def verify_storage(username):
|
81 |
+
"""
|
82 |
+
Verifica que los datos se est谩n guardando correctamente.
|
83 |
+
"""
|
84 |
+
try:
|
85 |
+
collection = get_collection(COLLECTION_NAME)
|
86 |
+
if collection is None:
|
87 |
+
return False
|
88 |
+
|
89 |
+
# Buscar documentos recientes del usuario
|
90 |
+
recent_docs = collection.find({
|
91 |
+
'username': username,
|
92 |
+
'timestamp': {
|
93 |
+
'$gte': (datetime.now(timezone.utc) - timedelta(minutes=5)).isoformat()
|
94 |
+
}
|
95 |
+
}).sort('timestamp', -1).limit(1)
|
96 |
+
|
97 |
+
docs = list(recent_docs)
|
98 |
+
if docs:
|
99 |
+
logger.info(f"""
|
100 |
+
脷ltimo documento guardado:
|
101 |
+
- ID: {docs[0]['_id']}
|
102 |
+
- Timestamp: {docs[0]['timestamp']}
|
103 |
+
- M茅tricas guardadas: {bool(docs[0].get('metrics'))}
|
104 |
+
""")
|
105 |
+
return True
|
106 |
+
|
107 |
+
logger.warning(f"No se encontraron documentos recientes para {username}")
|
108 |
+
return False
|
109 |
+
|
110 |
+
except Exception as e:
|
111 |
+
logger.error(f"Error verificando almacenamiento: {str(e)}")
|
112 |
return False
|