Commit e1a145c7 authored by 赵杰's avatar 赵杰

Merge remote-tracking branch 'origin/dev' into dev

parents 0db204af cd18b167
This diff is collapsed.
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name : __init__.py.py
# @Time : 2020/11/23 下午4:11
# @Author : X. Peng
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
......@@ -7,6 +7,8 @@ from app.api.engine import work_dir, pdf_folder, template_folder
from app.service.portfolio_diagnose import PortfolioDiagnose
from app.service.result_service_v2 import UserCustomerResultAdaptor
import numpy as np
from concurrent import futures
import os
# 准备数据
from app.utils.draw import draw_month_return_chart, draw_contribution_chart, draw_combination_chart, \
......@@ -16,9 +18,10 @@ from app.utils.radar_chart import gen_radar_chart
class DataIntegrate:
def __init__(self, ifa_id='USER_INFO15914346866762', customer_id='202009281545001'):
def __init__(self, ifa_id='USER_INFO15914346866762', customer_id='202009281545001', pdf_name=str(uuid.uuid4()) + '.pdf'):
self.user_customer = UserCustomerResultAdaptor(ifa_id, customer_id)
self.customer_name = self.user_customer.customer_real_name
self.pdf_name = pdf_name
self.df = self.user_customer.calculate_total_data()
self.d = self.user_customer.calculate_group_result_data()
# 组合数据
......@@ -92,6 +95,9 @@ class DataIntegrate:
self.single_fund_data_list = []
portfolio_evaluation = self.portfolio_diagnose.old_portfolio_evaluation()
radar_chart_data = self.portfolio_diagnose.single_fund_radar()
with futures.ProcessPoolExecutor(os.cpu_count()) as executor:
res = executor.map(gen_radar_chart, radar_chart_data)
res = list(res)
for i in range(len(portfolio_evaluation)):
if portfolio_evaluation[i]['status'] == '保留':
portfolio_evaluation[i]['status'] = '<div class="self_type fl">保留</div>'
......@@ -105,7 +111,7 @@ class DataIntegrate:
'fund_name': portfolio_evaluation[i]['name'],
'status': portfolio_evaluation[i]['status'],
'evaluation': portfolio_evaluation[i]['data'],
'radar_chart_path': gen_radar_chart(radar_chart_data[i])
'radar_chart_path': res[i]
})
def get_old_compare_pic(self):
......@@ -139,13 +145,23 @@ class DataIntegrate:
self.propose_fund_data_list = []
propose_fund_evaluation = self.portfolio_diagnose.propose_fund_evaluation()
propose_radar_chart_data = self.portfolio_diagnose.propose_fund_radar()
with futures.ProcessPoolExecutor(os.cpu_count()) as executor:
res = executor.map(gen_radar_chart, propose_radar_chart_data)
res = list(res)
for i in range(len(propose_fund_evaluation)):
self.propose_fund_data_list.append({
'fund_name': propose_fund_evaluation[i]['name'],
'status': '增仓',
'evaluation': propose_fund_evaluation[i]['data'],
'radar_chart_path': gen_radar_chart(propose_radar_chart_data[i])
'radar_chart_path': res[i]
})
# for i in range(len(propose_fund_evaluation)):
# self.propose_fund_data_list.append({
# 'fund_name': propose_fund_evaluation[i]['name'],
# 'status': '增仓',
# 'evaluation': propose_fund_evaluation[i]['data'],
# 'radar_chart_path': gen_radar_chart(propose_radar_chart_data[i])
# })
def objectives_performance(self, group_result):
"""目标与业绩"""
......@@ -243,7 +259,6 @@ class DataIntegrate:
# template = env.get_template('monthReport.html') # 获取一个模板文件
template = env.get_template('/v2/monthReportV2.html') # 获取一个模板文件
monthReport_html = template.render(data) # 渲染
# 保存 monthReport_html
# save_file = "app/html/monthReport.html"
# with open(save_file, 'w', encoding="utf-8") as f:
......@@ -252,7 +267,7 @@ class DataIntegrate:
# save_file = "app/html/v2/monthReportV2.html"
# with open(save_file, 'w', encoding="utf-8") as f:
# f.write(monthReport_html)
html_to_pdf(monthReport_html, pdf_folder + str(uuid.uuid4()) + '.pdf')
html_to_pdf(monthReport_html, pdf_folder + self.pdf_name)
......
......@@ -6,15 +6,17 @@
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
import base64
import os
import time
from io import BytesIO
import imgkit
import pyecharts.options as opts
from pyecharts.charts import Radar, Bar
import uuid
from pyecharts.charts import Radar
import cv2
from app.api.engine import work_dir
import numpy as np
def gen_radar_chart(radar_chart_data):
......@@ -24,7 +26,6 @@ def gen_radar_chart(radar_chart_data):
目前无法实现的功能:
1、雷达图周围的图例的 textStyle 暂时无法设置背景颜色
"""
# v1 = [[4300, 10000, 28000, 35000, 50000]]
radar_chart = radar_chart_data['data'][0:5]
v1 = [[data['data'] for data in radar_chart]]
radar = Radar(
......@@ -71,20 +72,26 @@ def gen_radar_chart(radar_chart_data):
legend_opts=opts.LegendOpts(selected_mode=False, is_show=False)
)
html_name = work_dir + '/app/html/' + str(uuid.uuid4()) + '.html'
img_name = work_dir + '/app/html/img/radar_chart_' + str(uuid.uuid4()) + '.png'
radar.render(html_name)
imgkit.from_file(html_name, img_name)
# radar.render("basic_radar_chart.html")
# img_content = work_dir + "/app/html/{}.png".format(str(uuid.uuid4()))
# make_snapshot(snapshot, "basic_radar_chart.html", img_content, delay=2)
html = radar.render_embed()
start = time.time()
image_bin = imgkit.from_string(html, None)
print('propose_fund cost', time.time() - start)
# 读取图片
img = cv2.imread(img_name)
img1 = np.frombuffer(image_bin, np.uint8)
img = cv2.imdecode(img1, cv2.IMREAD_ANYCOLOR)
# 获取宽度和高度
height = len(img)
width = len(img[0])
img = img[0:height, 160:750]
cv2.imwrite(img_name, img)
os.popen('rm -f {}'.format(html_name))
return img_name
img_bin = cv2.imencode(".png", img)[1].tobytes()
img_content = 'data:image/png;base64,' + base64.b64encode(img_bin).decode('utf-8')
return img_content
if __name__ == '__main__':
gen_radar_chart()
\ No newline at end of file
......@@ -38,7 +38,7 @@ class Customer(Base):
def call_month_report(ifauser_id, ifauser_name, customer_id, customer_name):
print('开始制作IFA: {}, 客户: {}的基金月报'.format(ifauser_name, customer_name))
try:
DataIntegrate(ifauser_id, customer_id)
DataIntegrate(ifauser_id, customer_id, '{}_{}_.pdf'.format(ifauser_name, customer_name))
except:
print("发生异常,下一个走起!")
......@@ -51,7 +51,7 @@ with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_order_engine) as tam
tamp_order_session = tamp_order.session
# for ifauser in ifausers:
for ifauser in ifausers[600:1000]:
for ifauser in ifausers:
# 获取某个 ifa 的所有 customer
customers = tamp_order_session.query(Ifa_Customer).\
filter_by(ifa_id = ifauser.id).all()
......
......@@ -68443,3 +68443,83 @@ FROM ifa_customer
WHERE ifa_customer.ifa_id = %(ifa_id_1)s
2020-12-07 18:39:11 Mon sqlalchemy.engine.base.Engine INFO {'ifa_id_1': 'USER_INFO15916074199322'}
2020-12-07 18:39:11 Mon sqlalchemy.engine.base.Engine INFO COMMIT
2020-12-08 14:41:40 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:41:41 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:41:41 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:41:48 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/7061fb02-2c88-4360-9f9f-53d5348f0649t.png
2020-12-08 14:41:48 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:41:48 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:41:48 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:41:55 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/163bd285-dfb2-4a34-a365-f25daa9903f0t.png
2020-12-08 14:41:56 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:41:56 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:41:56 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:42:03 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/5babc6d9-9fe1-45c5-bfcf-1de7d5315f2bt.png
2020-12-08 14:42:03 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:42:03 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:42:03 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:42:08 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/85bcc7df-0546-4649-a481-75457b004fd1t.png
2020-12-08 14:42:09 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:42:09 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:42:09 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:42:17 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/968178d7-7d55-4daa-8504-5429b4f640c3t.png
2020-12-08 14:42:17 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:42:17 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:42:17 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:42:23 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/77e6e5cb-fe0d-482c-8e97-c6425c641ec7t.png
2020-12-08 14:42:23 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:42:23 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:42:23 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:42:40 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/d72e11a1-b132-4aa8-b890-659ce8dde3a8t.png
2020-12-08 14:42:40 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:42:40 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:42:40 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:42:45 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/a589a4aa-1e1b-44b4-99cc-fef10e554858t.png
2020-12-08 14:45:26 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:45:26 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:45:26 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:45:35 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/09ae0a04-12d5-47e4-bc97-e10ad02f604b.png
2020-12-08 14:45:35 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:45:35 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:45:35 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:45:48 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/ac603d8d-ace2-4a18-8fcc-e6f8386aa5d4.png
2020-12-08 14:45:49 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:45:49 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:45:49 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:45:57 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/99759ada-93d4-4063-bdf1-fd8922c7e750.png
2020-12-08 14:45:57 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:45:57 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:45:57 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:46:04 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/4c16f5df-a8ee-47fd-8bfc-13295ec194d9.png
2020-12-08 14:46:04 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:46:04 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:46:04 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:46:13 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/b7aa1949-8665-4e39-8404-d439df7cc7a9.png
2020-12-08 14:46:13 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:46:13 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:46:13 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:46:27 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/e0028133-0145-4bd2-80d9-8316df17f78b.png
2020-12-08 14:46:27 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:46:27 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:46:27 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:46:34 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/54132728-2e62-4060-8fd2-c6f9487980a9.png
2020-12-08 14:46:34 Tue pyecharts.render.snapshot INFO Generating file ...
2020-12-08 14:46:34 Tue snapshot_phantomjs.snapshot INFO phantomjs version: 2.1.1
2020-12-08 14:46:34 Tue snapshot_phantomjs.snapshot INFO Generating file ...
2020-12-08 14:46:41 Tue pyecharts.render.snapshot INFO File saved in /Users/pengxiong/Desktop/fund_report/app/html/1f869841-2090-47ae-9c9d-94e6a514e390.png
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