Commit 08101add authored by pengxiong's avatar pengxiong

报告图片存文件

parent 7a4b6c5c
......@@ -7,6 +7,7 @@
# @Software : PyCharm
# -----------------------------------------------------------------------------
import base64
import uuid
from urllib import parse
from io import BytesIO
......@@ -18,6 +19,7 @@ from matplotlib import ticker
from matplotlib.ticker import FuncFormatter
from matplotlib.font_manager import FontProperties
from app.api.engine import template_folder
matplotlib.use('Agg')
# 中文字体初始化
......@@ -91,11 +93,14 @@ def draw_month_return_chart(xlabels, product_list, cumulative):
ax2.legend(loc='upper center', fontsize=fontsize)
# plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png', bbox_inches='tight')
imgdata.seek(0) # rewind the data
month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return month_return_img
# imgdata = BytesIO()
# fig.savefig(imgdata, format='png', bbox_inches='tight')
# imgdata.seek(0) # rewind the data
# month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
filename = str(uuid.uuid4()) + '.png'
filepath = template_folder + '/temp_img/' + filename
fig.savefig(filepath, format='png', bbox_inches='tight')
return filename
def draw_contribution_chart(xlabels, product_list, cumulative):
......@@ -154,11 +159,15 @@ def draw_contribution_chart(xlabels, product_list, cumulative):
ax2.text(a*1.1, b *1.05, '%.2f' % b + '%', ha='center', va='bottom', fontsize=fontsize, color='#B40A15')
ax2.legend(loc='upper left', fontsize=fontsize)
imgdata = BytesIO()
fig.savefig(imgdata, format='png', bbox_inches='tight')
imgdata.seek(0) # rewind the data
month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return month_return_img
# imgdata = BytesIO()
# fig.savefig(imgdata, format='png', bbox_inches='tight')
# imgdata.seek(0) # rewind the data
# month_return_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
# return month_return_img
filename = str(uuid.uuid4()) + '.png'
filepath = template_folder + '/temp_img/' + filename
fig.savefig(filepath, format='png', bbox_inches='tight')
return filename
# def draw_contribution_chart(xlabels, product_list, cumulative):
# """贡献分解图"""
......@@ -294,11 +303,15 @@ def draw_old_combination_chart(xlabels, origin_combination, index):
ax3.legend(loc='upper right', fontsize=fontsize)
# plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png', bbox_inches='tight')
imgdata.seek(0) # rewind the data
return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return return_compare_img
# imgdata = BytesIO()
# fig.savefig(imgdata, format='png', bbox_inches='tight')
# imgdata.seek(0) # rewind the data
# return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
# return return_compare_img
filename = str(uuid.uuid4()) + '.png'
filepath = template_folder + '/temp_img/' + filename
fig.savefig(filepath, format='png', bbox_inches='tight')
return filename
def draw_combination_chart(xlabels, new_combination, origin_combination, index):
......@@ -340,11 +353,15 @@ def draw_combination_chart(xlabels, new_combination, origin_combination, index):
ax3.legend(loc='upper right', fontsize=fontsize)
# plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png', bbox_inches='tight')
imgdata.seek(0) # rewind the data
return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return return_compare_img
# imgdata = BytesIO()
# fig.savefig(imgdata, format='png', bbox_inches='tight')
# imgdata.seek(0) # rewind the data
# return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
# return return_compare_img
filename = str(uuid.uuid4()) + '.png'
filepath = template_folder + '/temp_img/' + filename
fig.savefig(filepath, format='png', bbox_inches='tight')
return filename
def draw_index_combination_chart(compare_data):
......@@ -392,11 +409,15 @@ def draw_index_combination_chart(compare_data):
# ax3.legend()
# plt.show()
imgdata = BytesIO()
fig.savefig(imgdata, format='png', bbox_inches='tight')
imgdata.seek(0) # rewind the data
return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
return return_compare_img
# imgdata = BytesIO()
# fig.savefig(imgdata, format='png', bbox_inches='tight')
# imgdata.seek(0) # rewind the data
# return_compare_img = 'data:image/png;base64,' + base64.b64encode(imgdata.getvalue()).decode('utf-8')
# return return_compare_img
filename = str(uuid.uuid4()) + '.png'
filepath = template_folder + '/temp_img/' + filename
fig.savefig(filepath, format='png', bbox_inches='tight')
return filename
if __name__ == '__main__':
# xlabels = ('2020-1', '2020-2', '2020-3', '2020-4', '2020-5', '2020-6', '2020-7', '2020-8', '2020-9', '2020-10', '2020-11', '2020-12')
......
......@@ -138,14 +138,6 @@ class DataIntegrate:
res.append(r)
for i in range(len(portfolio_evaluation)):
if portfolio_evaluation[i]['status'] == '保留':
portfolio_evaluation[i]['status'] = '<div class="self_type fl">保留</div>'
elif portfolio_evaluation[i]['status'] == '增仓':
portfolio_evaluation[i]['status'] = '<div class="self_type fl red">增仓</div>'
elif portfolio_evaluation[i]['status'] == '换仓':
portfolio_evaluation[i]['status'] = '<div class="self_type fl green">换仓</div>'
elif portfolio_evaluation[i]['status'] == '减仓':
portfolio_evaluation[i]['status'] = '<div class="self_type fl green">减仓</div>'
single_fund_data_list.append({
'fund_name': portfolio_evaluation[i]['name'],
'status': portfolio_evaluation[i]['status'],
......
......@@ -9,6 +9,7 @@
import base64
import os
import time
import uuid
from io import BytesIO
import imgkit
......@@ -18,6 +19,8 @@ from pyecharts.charts import Radar
import cv2
import numpy as np
from app.api.engine import template_folder
def gen_radar_chart(radar_chart_data):
"""
......@@ -88,9 +91,15 @@ def gen_radar_chart(radar_chart_data):
width = len(img[0])
img = img[0:height, 160:750]
img_bin = cv2.imencode(".png", img)[1].tobytes()
img_content = 'data:image/png;base64,' + base64.b64encode(img_bin).decode('utf-8')
return img_content
# img_bin = cv2.imencode(".png", img)[1].tobytes()
# img_content = 'data:image/png;base64,' + base64.b64encode(img_bin).decode('utf-8')
# return img_content
filename = str(uuid.uuid4()) + '.png'
filepath = template_folder + '/temp_img/' + filename
cv2.imwrite(filepath, img)
return filename
if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment