Spaces:
Sleeping
Sleeping
Update modules/database/discourse_mongo_db.py
Browse files
modules/database/discourse_mongo_db.py
CHANGED
|
@@ -100,48 +100,51 @@ def store_student_discourse_result(username, text1, text2, analysis_result):
|
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
def get_student_discourse_analysis(username, limit=10):
|
| 107 |
"""
|
| 108 |
Recupera los análisis del discurso de un estudiante.
|
| 109 |
-
Args:
|
| 110 |
-
username: Nombre del usuario
|
| 111 |
-
limit: Número máximo de análisis a retornar
|
| 112 |
-
Returns:
|
| 113 |
-
list: Lista de análisis del discurso
|
| 114 |
"""
|
| 115 |
try:
|
|
|
|
| 116 |
collection = get_collection(COLLECTION_NAME)
|
| 117 |
-
if not collection
|
| 118 |
logger.error("No se pudo obtener la colección discourse")
|
| 119 |
return []
|
| 120 |
|
|
|
|
| 121 |
query = {
|
| 122 |
"username": username,
|
| 123 |
"analysis_type": "discourse"
|
| 124 |
}
|
| 125 |
|
| 126 |
-
#
|
| 127 |
projection = {
|
| 128 |
"timestamp": 1,
|
| 129 |
"combined_graph": 1,
|
| 130 |
"_id": 1
|
| 131 |
}
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
|
| 142 |
except Exception as e:
|
| 143 |
logger.error(f"Error recuperando análisis del discurso: {str(e)}")
|
| 144 |
return []
|
|
|
|
|
|
|
| 145 |
|
| 146 |
|
| 147 |
|
|
|
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
+
#################################################################################
|
|
|
|
|
|
|
| 104 |
def get_student_discourse_analysis(username, limit=10):
|
| 105 |
"""
|
| 106 |
Recupera los análisis del discurso de un estudiante.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
"""
|
| 108 |
try:
|
| 109 |
+
# Obtener la colección
|
| 110 |
collection = get_collection(COLLECTION_NAME)
|
| 111 |
+
if collection is None: # Cambiado de if not collection a if collection is None
|
| 112 |
logger.error("No se pudo obtener la colección discourse")
|
| 113 |
return []
|
| 114 |
|
| 115 |
+
# Consulta
|
| 116 |
query = {
|
| 117 |
"username": username,
|
| 118 |
"analysis_type": "discourse"
|
| 119 |
}
|
| 120 |
|
| 121 |
+
# Campos a recuperar
|
| 122 |
projection = {
|
| 123 |
"timestamp": 1,
|
| 124 |
"combined_graph": 1,
|
| 125 |
"_id": 1
|
| 126 |
}
|
| 127 |
|
| 128 |
+
# Ejecutar consulta
|
| 129 |
+
try:
|
| 130 |
+
cursor = collection.find(query, projection).sort("timestamp", -1)
|
| 131 |
+
if limit:
|
| 132 |
+
cursor = cursor.limit(limit)
|
| 133 |
+
|
| 134 |
+
# Convertir cursor a lista
|
| 135 |
+
results = list(cursor)
|
| 136 |
+
logger.info(f"Recuperados {len(results)} análisis del discurso para {username}")
|
| 137 |
+
return results
|
| 138 |
|
| 139 |
+
except Exception as db_error:
|
| 140 |
+
logger.error(f"Error en la consulta a MongoDB: {str(db_error)}")
|
| 141 |
+
return []
|
| 142 |
|
| 143 |
except Exception as e:
|
| 144 |
logger.error(f"Error recuperando análisis del discurso: {str(e)}")
|
| 145 |
return []
|
| 146 |
+
#####################################################################################
|
| 147 |
+
|
| 148 |
|
| 149 |
|
| 150 |
|