Update modules/database/database.py
Browse files- modules/database/database.py +19 -2
modules/database/database.py
CHANGED
@@ -7,6 +7,7 @@ from pymongo import MongoClient
|
|
7 |
import certifi
|
8 |
from datetime import datetime
|
9 |
import io
|
|
|
10 |
import base64
|
11 |
import matplotlib.pyplot as plt
|
12 |
from matplotlib.figure import Figure
|
@@ -294,16 +295,31 @@ def store_discourse_analysis_result(username, text1, text2, analysis_result):
|
|
294 |
|
295 |
try:
|
296 |
# Convertir los grafos individuales a imágenes base64
|
297 |
-
buf1 =
|
298 |
analysis_result['graph1'].savefig(buf1, format='png')
|
299 |
buf1.seek(0)
|
300 |
img_str1 = base64.b64encode(buf1.getvalue()).decode('utf-8')
|
301 |
|
302 |
-
buf2 =
|
303 |
analysis_result['graph2'].savefig(buf2, format='png')
|
304 |
buf2.seek(0)
|
305 |
img_str2 = base64.b64encode(buf2.getvalue()).decode('utf-8')
|
306 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
# Crear el documento para guardar
|
308 |
analysis_document = {
|
309 |
'username': username,
|
@@ -312,6 +328,7 @@ def store_discourse_analysis_result(username, text1, text2, analysis_result):
|
|
312 |
'text2': text2,
|
313 |
'graph1': img_str1,
|
314 |
'graph2': img_str2,
|
|
|
315 |
'analysis_type': 'discourse'
|
316 |
}
|
317 |
|
|
|
7 |
import certifi
|
8 |
from datetime import datetime
|
9 |
import io
|
10 |
+
from io import BytesIO
|
11 |
import base64
|
12 |
import matplotlib.pyplot as plt
|
13 |
from matplotlib.figure import Figure
|
|
|
295 |
|
296 |
try:
|
297 |
# Convertir los grafos individuales a imágenes base64
|
298 |
+
buf1 = BytesIO()
|
299 |
analysis_result['graph1'].savefig(buf1, format='png')
|
300 |
buf1.seek(0)
|
301 |
img_str1 = base64.b64encode(buf1.getvalue()).decode('utf-8')
|
302 |
|
303 |
+
buf2 = BytesIO()
|
304 |
analysis_result['graph2'].savefig(buf2, format='png')
|
305 |
buf2.seek(0)
|
306 |
img_str2 = base64.b64encode(buf2.getvalue()).decode('utf-8')
|
307 |
|
308 |
+
# Crear una imagen combinada
|
309 |
+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 10))
|
310 |
+
ax1.imshow(plt.imread(BytesIO(base64.b64decode(img_str1))))
|
311 |
+
ax1.axis('off')
|
312 |
+
ax1.set_title("Documento 1: Relaciones Conceptuales")
|
313 |
+
ax2.imshow(plt.imread(BytesIO(base64.b64decode(img_str2))))
|
314 |
+
ax2.axis('off')
|
315 |
+
ax2.set_title("Documento 2: Relaciones Conceptuales")
|
316 |
+
|
317 |
+
buf_combined = BytesIO()
|
318 |
+
fig.savefig(buf_combined, format='png')
|
319 |
+
buf_combined.seek(0)
|
320 |
+
img_str_combined = base64.b64encode(buf_combined.getvalue()).decode('utf-8')
|
321 |
+
plt.close(fig)
|
322 |
+
|
323 |
# Crear el documento para guardar
|
324 |
analysis_document = {
|
325 |
'username': username,
|
|
|
328 |
'text2': text2,
|
329 |
'graph1': img_str1,
|
330 |
'graph2': img_str2,
|
331 |
+
'combined_graph': img_str_combined,
|
332 |
'analysis_type': 'discourse'
|
333 |
}
|
334 |
|