Update modules/database/semantic_mongo_live_db.py
Browse files
modules/database/semantic_mongo_live_db.py
CHANGED
@@ -39,23 +39,29 @@ def store_student_semantic_live_result(username, text, analysis_result, lang_cod
|
|
39 |
logger.error("Parámetros incompletos para guardar análisis")
|
40 |
return False
|
41 |
|
42 |
-
# 3. Preparar documento
|
43 |
analysis_document = {
|
44 |
'username': username,
|
45 |
'timestamp': datetime.now(timezone.utc),
|
46 |
'text': text[:50000],
|
47 |
'analysis_type': 'semantic_live',
|
48 |
'language': lang_code,
|
49 |
-
|
50 |
-
'
|
|
|
|
|
51 |
}
|
52 |
-
|
53 |
-
# 4. Manejo del gráfico
|
54 |
if 'concept_graph' in analysis_result and analysis_result['concept_graph']:
|
55 |
try:
|
|
|
56 |
if isinstance(analysis_result['concept_graph'], bytes):
|
57 |
-
analysis_document['concept_graph'] =
|
58 |
-
|
|
|
|
|
|
|
59 |
except Exception as e:
|
60 |
logger.error(f"Error procesando gráfico: {str(e)}")
|
61 |
|
|
|
39 |
logger.error("Parámetros incompletos para guardar análisis")
|
40 |
return False
|
41 |
|
42 |
+
# 3. Preparar documento (CORREGIDO)
|
43 |
analysis_document = {
|
44 |
'username': username,
|
45 |
'timestamp': datetime.now(timezone.utc),
|
46 |
'text': text[:50000],
|
47 |
'analysis_type': 'semantic_live',
|
48 |
'language': lang_code,
|
49 |
+
# Extraer datos correctamente del análisis
|
50 |
+
'key_concepts': analysis_result.get('key_concepts', []),
|
51 |
+
'concept_centrality': analysis_result.get('concept_centrality', {}),
|
52 |
+
'concept_graph': None # Inicializar como None
|
53 |
}
|
54 |
+
|
55 |
+
# 4. Manejo del gráfico (CORREGIDO)
|
56 |
if 'concept_graph' in analysis_result and analysis_result['concept_graph']:
|
57 |
try:
|
58 |
+
# Si ya es bytes, usar directamente
|
59 |
if isinstance(analysis_result['concept_graph'], bytes):
|
60 |
+
analysis_document['concept_graph'] = analysis_result['concept_graph']
|
61 |
+
else:
|
62 |
+
# Convertir a bytes si es necesario
|
63 |
+
analysis_document['concept_graph'] = base64.b64decode(
|
64 |
+
analysis_result['concept_graph'])
|
65 |
except Exception as e:
|
66 |
logger.error(f"Error procesando gráfico: {str(e)}")
|
67 |
|