Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
F
fund_report
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
彭熊
fund_report
Commits
08101add
Commit
08101add
authored
Jan 14, 2021
by
pengxiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
报告图片存文件
parent
7a4b6c5c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
36 deletions
+58
-36
draw.py
app/utils/draw.py
+46
-25
jinjia2html_v2.py
app/utils/jinjia2html_v2.py
+0
-8
radar_chart.py
app/utils/radar_chart.py
+12
-3
No files found.
app/utils/draw.py
View file @
08101add
...
...
@@ -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
,
'
%.2
f'
%
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')
...
...
app/utils/jinjia2html_v2.py
View file @
08101add
...
...
@@ -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'
],
...
...
app/utils/radar_chart.py
View file @
08101add
...
...
@@ -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__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment