AIdeaText commited on
Commit
d37f895
·
verified ·
1 Parent(s): 1681510

Update modules/database.py

Browse files
Files changed (1) hide show
  1. modules/database.py +38 -4
modules/database.py CHANGED
@@ -247,17 +247,51 @@ def store_semantic_result(username, text, network_diagram):
247
  return False
248
 
249
  ###############################################################################################################
250
- def store_discourse_analysis_result(username, text, graph1, graph2):
 
 
 
 
 
251
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  analysis_document = {
253
  'username': username,
254
  'timestamp': datetime.utcnow(),
255
- 'text': text,
256
- 'graph1': graph1,
257
- 'graph2': graph2,
258
  'analysis_type': 'discourse'
259
  }
 
260
  result = analysis_collection.insert_one(analysis_document)
 
261
  logger.info(f"Análisis discursivo guardado con ID: {result.inserted_id} para el usuario: {username}")
262
  return True
263
  except Exception as e:
 
247
  return False
248
 
249
  ###############################################################################################################
250
+ import io
251
+ import base64
252
+ import matplotlib.pyplot as plt
253
+ from matplotlib.figure import Figure
254
+
255
+ def store_discourse_analysis_result(username, text1, text2, graph1, graph2):
256
  try:
257
+ # Crear una nueva figura combinada
258
+ fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 10))
259
+
260
+ # Añadir la primera imagen con título
261
+ ax1.imshow(graph1.get_figure().canvas.renderer.buffer_rgba())
262
+ ax1.set_title("Documento Patrón: Relaciones semánticas relevantes")
263
+ ax1.axis('off')
264
+
265
+ # Añadir la segunda imagen con título
266
+ ax2.imshow(graph2.get_figure().canvas.renderer.buffer_rgba())
267
+ ax2.set_title("Documento Comparado con el documento patrón: Relaciones semánticas relevantes")
268
+ ax2.axis('off')
269
+
270
+ # Ajustar el diseño
271
+ plt.tight_layout()
272
+
273
+ # Convertir la figura combinada a una imagen base64
274
+ buf = io.BytesIO()
275
+ fig.savefig(buf, format='png')
276
+ buf.seek(0)
277
+ img_str = base64.b64encode(buf.getvalue()).decode('utf-8')
278
+
279
+ # Cerrar las figuras para liberar memoria
280
+ plt.close(fig)
281
+ plt.close(graph1.get_figure())
282
+ plt.close(graph2.get_figure())
283
+
284
  analysis_document = {
285
  'username': username,
286
  'timestamp': datetime.utcnow(),
287
+ 'text1': text1,
288
+ 'text2': text2,
289
+ 'combined_graph': img_str,
290
  'analysis_type': 'discourse'
291
  }
292
+
293
  result = analysis_collection.insert_one(analysis_document)
294
+
295
  logger.info(f"Análisis discursivo guardado con ID: {result.inserted_id} para el usuario: {username}")
296
  return True
297
  except Exception as e: