from pyecharts import options as opts
from snapshot_selenium import snapshot as driver
def draw_chart(self, file, save_path):
"""
Front end playback performance use case data statistics chart
file: excel The full path
save_path: html and png Save the directory
"""
data = pandas.read_excel(file, engine='openpyxl')
shape = data.shape
nrows = shape[0]
ncols = shape[1]
# print(f' Current total rows :' + str(nrows)) # Get the number of lines
# print(f' Current total Columns :' + str(ncols)) # Get the number of columns
dt_dates = [] # date
dt_avg_fpss = [] # Average frame rate
dt_fat_fps_nums = [] # Number of fat frames
for i in range(nrows):
dt_date = data.iloc[i, 0]
dt_dates.append(dt_date)
dt_avg_fps = data.iloc[i, 1]
dt_avg_fpss.append(float(dt_avg_fps))
dt_fat_fps_num = data.iloc[i, 2]
dt_fat_fps_nums.append(float(dt_fat_fps_num))
# print(dt_fat_fps_nums)
line = (
Line(init_opts=opts.InitOpts(width='1850px', height='640px'))
.add_xaxis(dt_dates)
.add_yaxis(" Average frame rate ", dt_avg_fpss)
.add_yaxis(" Number of fat frames ", dt_fat_fps_nums)
.set_global_opts(title_opts=opts.TitleOpts(title=" Front end performance test "))
)
line.set_series_opts(
markpoint_opts=opts.MarkPointOpts(
data=[
opts.MarkPointItem(type_='average', name=' Average '),
opts.MarkPointItem(type_='max', name=' Maximum '),
opts.MarkPointItem(type_='min', name=' minimum value ')
]
)
)
# Set the title, etc
line.set_global_opts(title_opts=opts.TitleOpts(' Front end performance tracking curve '),
# show the toolbox
toolbox_opts=opts.ToolboxOpts(),
xaxis_opts=opts.AxisOpts(axislabel_opts={"rotate": 45, "interval": 0})
)
file_name = self.getTestCaseName(file)
html_name = file_name + ".html"
html_save_path = save_path + "\\" + html_name
line.render(html_save_path)
snapshot_save_path = save_path + "\\bar.png"
# Need to install snapshot-selenium perhaps snapshot-phantomjs
make_snapshot(driver, line.render(), snapshot_save_path)
# webbrowser.open(html_name)