Spaces:
Running
Running
Update modules/database/semantic_mongo_db.py
Browse files
modules/database/semantic_mongo_db.py
CHANGED
|
@@ -85,45 +85,51 @@ def store_student_semantic_result(username, text, analysis_result):
|
|
| 85 |
# Asegurarnos de cerrar cualquier figura pendiente
|
| 86 |
plt.close('all')
|
| 87 |
|
|
|
|
| 88 |
def get_student_semantic_analysis(username, limit=10):
|
| 89 |
"""
|
| 90 |
Recupera los análisis semánticos de un estudiante.
|
| 91 |
-
Args:
|
| 92 |
-
username: Nombre del usuario
|
| 93 |
-
limit: Número máximo de análisis a retornar
|
| 94 |
-
Returns:
|
| 95 |
-
list: Lista de análisis semánticos
|
| 96 |
"""
|
| 97 |
try:
|
|
|
|
| 98 |
collection = get_collection(COLLECTION_NAME)
|
| 99 |
-
if not collection
|
| 100 |
logger.error("No se pudo obtener la colección semantic")
|
| 101 |
return []
|
| 102 |
|
|
|
|
| 103 |
query = {
|
| 104 |
"username": username,
|
| 105 |
"analysis_type": "semantic"
|
| 106 |
}
|
| 107 |
|
| 108 |
-
#
|
| 109 |
projection = {
|
| 110 |
"timestamp": 1,
|
| 111 |
"concept_graph": 1,
|
| 112 |
"_id": 1
|
| 113 |
}
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
except Exception as e:
|
| 125 |
logger.error(f"Error recuperando análisis semántico: {str(e)}")
|
| 126 |
return []
|
|
|
|
|
|
|
| 127 |
|
| 128 |
def update_student_semantic_analysis(analysis_id, update_data):
|
| 129 |
"""
|
|
|
|
| 85 |
# Asegurarnos de cerrar cualquier figura pendiente
|
| 86 |
plt.close('all')
|
| 87 |
|
| 88 |
+
####################################################################################
|
| 89 |
def get_student_semantic_analysis(username, limit=10):
|
| 90 |
"""
|
| 91 |
Recupera los análisis semánticos de un estudiante.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
"""
|
| 93 |
try:
|
| 94 |
+
# Obtener la colección
|
| 95 |
collection = get_collection(COLLECTION_NAME)
|
| 96 |
+
if collection is None: # Cambiado de if not collection a if collection is None
|
| 97 |
logger.error("No se pudo obtener la colección semantic")
|
| 98 |
return []
|
| 99 |
|
| 100 |
+
# Consulta
|
| 101 |
query = {
|
| 102 |
"username": username,
|
| 103 |
"analysis_type": "semantic"
|
| 104 |
}
|
| 105 |
|
| 106 |
+
# Campos a recuperar
|
| 107 |
projection = {
|
| 108 |
"timestamp": 1,
|
| 109 |
"concept_graph": 1,
|
| 110 |
"_id": 1
|
| 111 |
}
|
| 112 |
|
| 113 |
+
# Ejecutar consulta
|
| 114 |
+
try:
|
| 115 |
+
cursor = collection.find(query, projection).sort("timestamp", -1)
|
| 116 |
+
if limit:
|
| 117 |
+
cursor = cursor.limit(limit)
|
| 118 |
|
| 119 |
+
# Convertir cursor a lista
|
| 120 |
+
results = list(cursor)
|
| 121 |
+
logger.info(f"Recuperados {len(results)} análisis semánticos para {username}")
|
| 122 |
+
return results
|
| 123 |
+
|
| 124 |
+
except Exception as db_error:
|
| 125 |
+
logger.error(f"Error en la consulta a MongoDB: {str(db_error)}")
|
| 126 |
+
return []
|
| 127 |
|
| 128 |
except Exception as e:
|
| 129 |
logger.error(f"Error recuperando análisis semántico: {str(e)}")
|
| 130 |
return []
|
| 131 |
+
####################################################################################################
|
| 132 |
+
|
| 133 |
|
| 134 |
def update_student_semantic_analysis(analysis_id, update_data):
|
| 135 |
"""
|