How to use run_pict method in avocado

Best Python code snippet using avocado_python

AAC_DataPlot_Summary_V1.5.py

Source:AAC_DataPlot_Summary_V1.5.py Github

copy

Full Screen

1import pandas as pd2import xlwings as xw3import csv_process4import Histogram5import Boxplot6import Sweep_1 as Sweep7from tkinter import *8from tkinter import filedialog9import tkinter.messagebox10import os11import time12from datetime import datetime13from docx import Document14from docx.shared import Inches, Pt, RGBColor, Cm15from docx.oxml.ns import qn16from docx.enum.text import WD_PARAGRAPH_ALIGNMENT17def run_csv():18 default_dir = r"文件路径"19 filepath_csv = filedialog.askopenfilename(title=u'选择CSV文件', initialdir=(os.path.expanduser(default_dir)))20 text_CSV.delete(0, END)21 text_CSV.insert(END, filepath_csv)22def run_ini():23 default_dir = r"文件路径"24 global filepath_ini25 filepath_ini = filedialog.askopenfilename(title=u'选择配置文件', initialdir=(os.path.expanduser(default_dir)))26 text_ini.delete(0, END)27 text_ini.insert(END, filepath_ini)28def run_pic():29 default_dir = r"文件路径"30 filepath_pic = filedialog.askdirectory(title=u'选择图片路径', initialdir=(os.path.expanduser(default_dir)))31 v.set(filepath_pic)32def run_report():33 pic_path = v.get()34 list_pic = os.listdir(pic_path)35 # pic_name 为图片名称拆分组成的DataFrame(分组名,Config,图类),columns为图片名称36 pic_name = pd.DataFrame()37 for i in list_pic:38 if os.path.isfile(pic_path + '\\' + i):39 list_temp = i.split('-')40 list_temp[2] = int(list_temp[2])41 series_temp = pd.Series(list_temp[0:4])42 pic_name = pd.concat([pic_name, series_temp], axis=1)43 else:44 list_pic.remove(i)45 pic_name.columns = list_pic46 pic_name.sort_values(by=[3, 2, 0, 1], axis=1, inplace=True) # 排序,先按照station,再按照图类别,然后是组的类别,最后是Config47 # pic_name.to_csv('pic_name.csv')48 # sections对应文档中的“节”49 document = Document()50 sec = document.sections[0]51 # 页眉设置52 sec.header_distance = Cm(0.3) # 页眉距离顶端距离53 paragraph = sec.header.paragraphs[0]54 run_header = paragraph.add_run('TestDataPlotSummary developed by AAC Test Team')55 paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT56 run_header.font.name = u'Calibri'57 run_header.font.size = Pt(8)58 run_header._element.rPr.rFonts.set(qn('w:eastAsia'), u'Calibri')59 run_header.font.color.rgb = RGBColor(0, 0, 0)60 run_header.font.italic = True61 # 以下依次设置左、右、上、下页面边距62 distance1 = Inches(0.2)63 distance2 = Inches(0)64 sec.left_margin = distance165 sec.right_margin = distance166 sec.top_margin = distance267 sec.bottom_margin = distance268 # 设置页面的宽度和高度(A4)69 sec.page_width = Inches(11.69)70 sec.page_height = Inches(8.27)71 flag_index = pd.Series(['', '', '', '']) # 上一条运行的图片分类,用于下一次检测是否标题,换行等72 config_qty_tem = 1 # 用于检测是否大于3个config了,换页添加标题73 loop_count = 074 # 循环逻辑:(1)Type不一样,Type标题+Config标题+图片,新建Par-RUN;(2)Config不一样,Config标题+图片,新建Rar-RUN;(3)正常绘图75 for i in pic_name.columns:76 # 主标题设置77 if pic_name[i][3] != flag_index[3]:78 if loop_count > 0: # 第一页不换页79 document.add_page_break()80 page_title = document.add_heading("", level=1)81 page_title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER82 run_pt = page_title.add_run('\n\n\n' + 'TestData Plot Summary Report' + '\n' + pic_name[i][3])83 run_pt.font.name = u'Helvetica'84 run_pt.font.size = Pt(40.5)85 run_pt._element.rPr.rFonts.set(qn('w:eastAsia'), u'Helvetica')86 run_pt.font.color.rgb = RGBColor(0, 0, 0)87 run_pt.font.bold = True88 if pic_name[i][0] != flag_index[0] or (pic_name[i][1] != flag_index[1] and config_qty_tem % 3 == 0): # 图类别89 document.add_page_break()90 page_title = document.add_heading('', level=1)91 page_title.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT92 run_pt = page_title.add_run(pic_name[i][0])93 run_pt.font.name = u'Helvetica'94 run_pt.font.size = Pt(17)95 run_pt._element.rPr.rFonts.set(qn('w:eastAsia'), u'Helvetica')96 run_pt.font.color.rgb = RGBColor(0, 0, 0)97 run_pt.italic = True98 run_pt.font.bold = True99 page_title_2nd = document.add_heading('', level=2)100 page_title_2nd.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT101 run_ct = page_title_2nd.add_run(pic_name[i][1])102 run_ct.font.name = u'Helvetica'103 run_ct.font.size = Pt(12)104 run_ct._element.rPr.rFonts.set(qn('w:eastAsia'), u'Helvetica')105 run_ct.font.color.rgb = RGBColor(0, 0, 0)106 pr_pic = document.add_paragraph()107 run_pict = pr_pic.add_run()108 run_pict.add_picture(pic_path + '\\' + i, height=Inches(2))109 flag_index = pic_name[i]110 config_qty_tem = 1111 elif pic_name[i][1] != flag_index[1]: # Config112 page_title_2nd = document.add_heading('', level=2)113 page_title_2nd.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT114 run_ct = page_title_2nd.add_run(pic_name[i][1])115 run_ct.font.name = u'Helvetica'116 run_ct.font.size = Pt(12)117 run_ct._element.rPr.rFonts.set(qn('w:eastAsia'), u'Helvetica')118 run_ct.font.color.rgb = RGBColor(0, 0, 0)119 pr_pic = document.add_paragraph()120 run_pict = pr_pic.add_run()121 run_pict.add_picture(pic_path + '\\' + i, height=Inches(2))122 flag_index = pic_name[i]123 config_qty_tem = config_qty_tem + 1124 else:125 run_pict.add_picture(pic_path + '\\' + i, height=Inches(2))126 flag_index = pic_name[i]127 loop_count = loop_count + 1128 config_name = entry_config.get()129 report_path = os.path.split(pic_path)[0] + '/' + config_name + f'_Data Summary Report_WD_{now_date}.docx'130 document.save(report_path)131 text_info_line = text_info.index(END).split('.')[0]132 text_info.insert(END, 'Finished Report in ' + report_path + '\n')133 text_info.tag_add('tag2', str(int(text_info_line) - 1) + '.0', text_info_line + '.0') # Finish 打印突出显示134 text_info.tag_config('tag2', background='Cyan1', font=('Times', 10))135 text_info.see(END)136 text_info.update()137def run():138 time_t0 = time.time()139 text_info_line = 2 # 监控text_info已经输入到第几行140 text_info.delete(1.0, END)141 text_info.insert(1.0, 'Start -> Reading CSV File' + '\n')142 text_info.update()143 data_csv, USL, LSL, Overlay, Station, project = csv_process.csv_process(text_CSV.get())144 config_name = entry_config.get()145 data_ini = pd.read_excel(filepath_ini, sheet_name=Station)146 graph_flag = '' # 画什么图147 graph_class = '' # 图的分类标签148 boxplot_data_tem = pd.DataFrame()149 sweep_data_tem = pd.DataFrame()150 USL_tem = []151 LSL_tem = []152 boxplot_X_name = []153 print_info = '' # 显示打印信息154 # 创建保存图片的文件夹155 global pic_dic156 filepath_csv = text_CSV.get()157 pic_dic = os.path.split(filepath_csv)[0] + '/' + 'Saved Photo' + '/'158 pic_dic_0 = os.path.split(filepath_csv)[0] + '/' + 'Saved Photo'159 isExists = os.path.exists(pic_dic)160 if not isExists:161 os.makedirs(pic_dic)162 v.set(pic_dic_0)163 out_data = pd.DataFrame(index=['Item', 'USL', 'LSL', 'Mean', 'STDEV', 'CPK']) # 输出数据表格164 ini_pic_order = 0165 for i in range(len(data_ini['Data Item'])):166 # 画图种类定义+标签167 if data_ini.loc[i, 'Plot Type'] == data_ini.loc[i, 'Plot Type']:168 graph_flag = data_ini.loc[i, 'Plot Type']169 graph_class = data_ini.loc[i, 'Plot Title']170 ini_pic_order = ini_pic_order + 1171 item_name = data_ini.loc[i, 'Data Item']172 find_flag = 0173 for item_ext in LSL.index:174 if item_ext.find(item_name) >= 0:175 find_flag = 1176 break177 if find_flag:178 if graph_flag == 'Histogram' and data_ini.loc[i, 'Monitor'] == data_ini.loc[i, 'Monitor']: # Monitor列判定是否画图179 # USL 配置文件有,则用配置文件,无则用数据USL180 if data_ini.loc[i, 'Upper Limit'] == data_ini.loc[i, 'Upper Limit']:181 USL_histogram = data_ini.loc[i, 'Upper Limit']182 else:183 USL_histogram = USL[item_name]184 # LSL 配置文件有,则用配置文件,无则用数据LSL185 if data_ini.loc[i, 'Lower Limit'] == data_ini.loc[i, 'Lower Limit']:186 LSL_histogram = data_ini.loc[i, 'Lower Limit']187 else:188 LSL_histogram = LSL[item_name]189 print_info, out_his = Histogram.histogram(Station, pic_dic, config_name, graph_class, item_name,190 USL_histogram, LSL_histogram, data_csv[item_name],191 data_ini.loc[i, 'Axis Upper Limit'],192 data_ini.loc[i, 'Axis Lower Limit'], ini_pic_order,193 entry_qty.get())194 out_data = pd.concat([out_data, out_his], axis=1)195 text_info.insert(END, print_info + '\n')196 text_info.see(END)197 text_info_line = text_info_line + 1198 text_info.update()199 elif graph_flag == 'Boxplot' and data_ini.loc[i, 'Monitor'] == data_ini.loc[i, 'Monitor']: # Monitor列判定是否画图200 boxplot_data_tem = pd.concat([boxplot_data_tem, data_csv[item_name]], axis=1)201 if data_ini.loc[i, 'X-Axis Mark'] == data_ini.loc[i, 'X-Axis Mark']:202 boxplot_X_name.append(data_ini.loc[i, 'X-Axis Mark'])203 # USL 配置文件有,则用配置文件,无则用数据USL204 if data_ini.loc[i, 'Upper Limit'] == data_ini.loc[i, 'Upper Limit']:205 USL_tem.append(data_ini.loc[i, 'Upper Limit'])206 else:207 USL_tem.append(USL[item_name])208 # LSL 配置文件有,则用配置文件,无则用数据LSL209 if data_ini.loc[i, 'Lower Limit'] == data_ini.loc[i, 'Lower Limit']:210 LSL_tem.append(data_ini.loc[i, 'Lower Limit'])211 else:212 LSL_tem.append(LSL[item_name])213 if data_ini.loc[i + 1, 'Plot Type'] == data_ini.loc[i + 1, 'Plot Type']:214 print_info, out_box = Boxplot.Boxplot(Station, pic_dic, config_name, graph_class, USL_tem, LSL_tem,215 boxplot_data_tem, data_ini.loc[i, 'Axis Upper Limit'],216 data_ini.loc[i, 'Axis Lower Limit'], boxplot_X_name,217 ini_pic_order, entry_qty.get())218 boxplot_X_name = []219 out_data = pd.concat([out_data, out_box], axis=1)220 text_info.insert(END, print_info + '\n')221 text_info_line = text_info_line + 1222 text_info.see(END)223 text_info.update()224 boxplot_data_tem = pd.DataFrame()225 USL_tem = []226 LSL_tem = []227 elif graph_flag == 'Sweep' and data_ini.loc[i, 'Monitor'] == data_ini.loc[i, 'Monitor']: # Monitor列判定是否画图228 for j in data_csv.columns:229 if j.find(item_name) >= 0:230 sweep_data_tem = pd.concat([sweep_data_tem, data_csv[j]], axis=1)231 USL_tem.append(USL[j])232 LSL_tem.append(LSL[j])233 print_info = Sweep.Sweep(Station, pic_dic, config_name, graph_class, USL_tem, LSL_tem, sweep_data_tem,234 data_ini.loc[i, 'Axis Upper Limit'], data_ini.loc[i, 'Axis Lower Limit'],235 ini_pic_order, entry_qty.get())236 text_info.insert(END, print_info + '\n')237 text_info_line = text_info_line + 1238 text_info.see(END)239 text_info.update()240 sweep_data_tem = pd.DataFrame()241 USL_tem = []242 LSL_tem = []243 else:244 print_info = f'Error -> {item_name} IS not Found on Data !'245 text_info.insert(END, print_info + '\n')246 text_info.tag_add('tag0', str(text_info_line) + '.9',247 str(text_info_line) + '.' + str(9 + len(item_name))) # Error 打印突出显示248 text_info.tag_config('tag0', background='red', font=('Times'))249 text_info_line = text_info_line + 1250 text_info.see(END)251 text_info.update()252 # 保存数据到Excel Table253 save_table_name = project + '_' + Station + f'_Summary Table_{now_date}.xlsx'254 out_data_path = os.path.split(filepath_csv)[0] + '/' + save_table_name255 app = xw.App(visible=False, add_book=False)256 if os.path.exists(out_data_path):257 wb = app.books.open(out_data_path)258 for i in wb.sheets:259 if i.name == entry_config.get():260 wb.sheets[entry_config.get()].delete()261 ws = wb.sheets.add(entry_config.get())262 ws.range('A1').expand('table').value = out_data263 ws.range('A1').api.EntireRow.Delete()264 else:265 wb = app.books.add()266 wb.sheets[0].name = entry_config.get()267 ws = wb.sheets[0]268 ws.range('A1').expand('table').value = out_data269 ws.range('A1').api.EntireRow.Delete()270 wb.save(out_data_path)271 wb.close()272 app.quit()273 time_delta = time.time() - time_t0274 text_info.insert(END, 'Finished All in ' + str(round(time_delta, 1)) + ' Seconds' + '\n')275 text_info.tag_add('tag', str(text_info_line) + '.0', str(text_info_line + 1) + '.0') # Finish 打印突出显示276 text_info.tag_config('tag', background='green', font=('Times', 15))277 text_info.see(END)278 text_info.update()279 text_info_line = text_info_line + 1280# 主窗口281root = Tk()282root.title('AAC DataPlot Summary_1.5')283root.resizable(0, 0)284root.geometry('700x500')285y_start = 0.01286y_interval = 0.07287# Config label288entry_config = Entry(root, font=('Times', 15, 'bold'))289entry_config.place(relx=0.01, rely=y_start, relwidth=0.36, relheight=0.06)290lbe_config = Label(root, text='CONFIG')291lbe_config.place(relx=0.38, rely=y_start, relwidth=0.11, relheight=0.06)292# Qty label293entry_qty = Entry(root, font=('Times', 15, 'bold'))294entry_qty.place(relx=0.51, rely=y_start, relwidth=0.36, relheight=0.06)295lbe_qty = Label(root, text='N Qty')296lbe_qty.place(relx=0.88, rely=y_start, relwidth=0.11, relheight=0.06)297# CSV 文件输入298text_CSV = Entry(root, font=('Helvetica', 10), relief=GROOVE)299text_CSV.place(relx=0.01, rely=y_start + y_interval, relwidth=0.86, relheight=0.06)300btn_CSV = Button(root, text='CSV Path', command=run_csv)301btn_CSV.place(relx=0.88, rely=y_start + y_interval, relwidth=0.11, relheight=0.06)302# 配置文件输入303text_ini = Entry(root, font=('Helvetica', 10))304text_ini.place(relx=0.01, rely=y_start + 2 * y_interval, relwidth=0.86, relheight=0.06)305btn_ini = Button(root, text='INI File', command=run_ini)306btn_ini.place(relx=0.88, rely=y_start + 2 * y_interval, relwidth=0.11, relheight=0.06)307# 图片路径308v = StringVar()309text_pic = Label(root, justify="left", font=('Helvetica', 10), relief=GROOVE, textvariable=v)310text_pic.place(relx=0.01, rely=y_start + 3 * y_interval, relwidth=0.86, relheight=0.06)311lbe_pic = Button(root, text='PIC Path', command=run_pic)312lbe_pic.place(relx=0.88, rely=y_start + 3 * y_interval, relwidth=0.11, relheight=0.06)313# 信息输出框 & 执行按钮314text_info = Text(root, font=('Times', 10))315text_info.place(relx=0.01, rely=y_start + 4 * y_interval, relwidth=0.86, relheight=0.695)316# 信息输出框的滚动条317scroll = Scrollbar()318# 放到窗口的右侧, 填充Y竖直方向319scroll.place(relx=0.8492, rely=y_start + 4 * y_interval + 0.001, relwidth=0.02, relheight=0.695 - 0.002)320scroll.config(command=text_info.yview)321text_info.config(yscrollcommand=scroll.set)322btn_run = Button(root, text='START', command=run)323btn_run.place(relx=0.88, rely=y_start + 4 * y_interval, relwidth=0.11, relheight=0.06)324btn_report = Button(root, text='REPORT', command=run_report)325btn_report.place(relx=0.88, rely=y_start + 5 * y_interval, relwidth=0.11, relheight=0.06)326dt = datetime.now()327now_date = dt.strftime('%Y%m%d')328overdue_date = '20230704'329if now_date > overdue_date:330 tkinter.messagebox.askokcancel(title='Error', message='License Expired !')331 exit()...

Full Screen

Full Screen

run_report.py

Source:run_report.py Github

copy

Full Screen

1import pandas as pd2import os3from docx import Document4from docx.shared import Inches, Pt, RGBColor, Cm5from docx.oxml.ns import qn6from docx.enum.text import WD_PARAGRAPH_ALIGNMENT7from datetime import datetime8def run_report(main_frame):9 pic_path = main_frame.text_pic.text()10 list_pic = os.listdir(pic_path)11 # pic_name 为图片名称拆分组成的DataFrame(分组名,Config,图类),columns为图片名称12 pic_name = pd.DataFrame()13 for i in list_pic:14 if os.path.isfile(pic_path + '\\' + i):15 list_temp = i.split('-')16 list_temp[2] = int(list_temp[2])17 series_temp = pd.Series(list_temp[0:4])18 pic_name = pd.concat([pic_name, series_temp], axis=1)19 else:20 list_pic.remove(i)21 pic_name.columns = list_pic22 pic_name.sort_values(by=[3, 2, 0, 1], axis=1, inplace=True) # 排序,先按照station,再按照图类别,然后是组的类别,最后是Config23 # pic_name.to_csv('pic_name.csv')24 # sections对应文档中的“节”25 document = Document()26 sec = document.sections[0]27 # 页眉设置28 sec.header_distance = Cm(0.3) # 页眉距离顶端距离29 paragraph = sec.header.paragraphs[0]30 run_header = paragraph.add_run('TestDataPlotSummary developed by AAC Test Team')31 paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT32 run_header.font.name = u'Calibri'33 run_header.font.size = Pt(8)34 run_header._element.rPr.rFonts.set(qn('w:eastAsia'), u'Calibri')35 run_header.font.color.rgb = RGBColor(0, 0, 0)36 run_header.font.italic = True37 # 以下依次设置左、右、上、下页面边距38 distance1 = Inches(0.2)39 distance2 = Inches(0)40 sec.left_margin = distance141 sec.right_margin = distance142 sec.top_margin = distance243 sec.bottom_margin = distance244 # 设置页面的宽度和高度(A4)45 sec.page_width = Inches(11.69)46 sec.page_height = Inches(8.27)47 flag_index = pd.Series(['', '', '', '']) # 上一条运行的图片分类,用于下一次检测是否标题,换行等48 config_qty_tem = 1 # 用于检测是否大于3个config了,换页添加标题49 loop_count = 050 # 循环逻辑:(1)Type不一样,Type标题+Config标题+图片,新建Par-RUN;(2)Config不一样,Config标题+图片,新建Rar-RUN;(3)正常绘图51 for i in pic_name.columns:52 # 主标题设置53 if pic_name[i][3] != flag_index[3]:54 if loop_count > 0: # 第一页不换页55 document.add_page_break()56 page_title = document.add_heading("", level=1)57 page_title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER58 run_pt = page_title.add_run('\n\n\n' + 'TestData Plot Summary Report' + '\n' + pic_name[i][3])59 run_pt.font.name = u'Helvetica'60 run_pt.font.size = Pt(40.5)61 run_pt._element.rPr.rFonts.set(qn('w:eastAsia'), u'Helvetica')62 run_pt.font.color.rgb = RGBColor(0, 0, 0)63 run_pt.font.bold = True64 if pic_name[i][0] != flag_index[0] or (pic_name[i][1] != flag_index[1] and config_qty_tem % 3 == 0): # 图类别65 document.add_page_break()66 page_title = document.add_heading('', level=1)67 page_title.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT68 run_pt = page_title.add_run(pic_name[i][0])69 run_pt.font.name = u'Helvetica'70 run_pt.font.size = Pt(17)71 run_pt._element.rPr.rFonts.set(qn('w:eastAsia'), u'Helvetica')72 run_pt.font.color.rgb = RGBColor(0, 0, 0)73 run_pt.italic = True74 run_pt.font.bold = True75 page_title_2nd = document.add_heading('', level=2)76 page_title_2nd.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT77 run_ct = page_title_2nd.add_run(pic_name[i][1])78 run_ct.font.name = u'Helvetica'79 run_ct.font.size = Pt(12)80 run_ct._element.rPr.rFonts.set(qn('w:eastAsia'), u'Helvetica')81 run_ct.font.color.rgb = RGBColor(0, 0, 0)82 pr_pic = document.add_paragraph()83 run_pict = pr_pic.add_run()84 run_pict.add_picture(pic_path + '\\' + i, height=Inches(2))85 flag_index = pic_name[i]86 config_qty_tem = 187 elif pic_name[i][1] != flag_index[1]: # Config88 page_title_2nd = document.add_heading('', level=2)89 page_title_2nd.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT90 run_ct = page_title_2nd.add_run(pic_name[i][1])91 run_ct.font.name = u'Helvetica'92 run_ct.font.size = Pt(12)93 run_ct._element.rPr.rFonts.set(qn('w:eastAsia'), u'Helvetica')94 run_ct.font.color.rgb = RGBColor(0, 0, 0)95 pr_pic = document.add_paragraph()96 run_pict = pr_pic.add_run()97 run_pict.add_picture(pic_path + '\\' + i, height=Inches(2))98 flag_index = pic_name[i]99 config_qty_tem = config_qty_tem + 1100 else:101 run_pict.add_picture(pic_path + '\\' + i, height=Inches(2))102 flag_index = pic_name[i]103 loop_count = loop_count + 1104 dt = datetime.now()105 now_date = dt.strftime('%Y%m%d')106 config_name = main_frame.entry_config.text()107 report_path = os.path.split(pic_path)[0] + '/' + config_name + f'_Data Summary Report_WD_{now_date}.docx'108 document.save(report_path)109 print_info = '<span style="background:blue;">' + 'Finished Report in ' + report_path + '</span>'...

Full Screen

Full Screen

report_generate.py

Source:report_generate.py Github

copy

Full Screen

1import pandas as pd2import os3from docx import Document4from docx.shared import Inches, Pt, RGBColor, Cm5from docx.oxml.ns import qn6from docx.enum.text import WD_ALIGN_PARAGRAPH7document = Document()8# sections对应文档中的“节”9sec = document.sections[0]10# 页眉设置11sec.header_distance = Cm(0.4) #页眉距离顶端距离12paragraph = sec.header.paragraphs[0]13run_header = paragraph.add_run('TestDataPlotSummary developed by AAC Test Team')14paragraph.alignment = WD_ALIGN_PARAGRAPH.RIGHT15run_header.font.name = u'Calibri'16run_header.font.size = Pt(8)17run_header._element.rPr.rFonts.set(qn('w:eastAsia'), u'Calibri')18run_header.font.color.rgb = RGBColor(0,0,0)19run_header.font.italic = True20# 以下依次设置左、右、上、下页面边距21distance1 = Inches(0.3)22distance2 = Inches(0)23sec.left_margin = distance124sec.right_margin = distance125sec.top_margin = distance226sec.bottom_margin = distance227# 设置页面的宽度和高度(A4)28sec.page_width = Inches(11.69)29sec.page_height = Inches(8.27)30# 第一页主标题设置31page_title = document.add_heading("", level=1)32page_title.alignment = WD_ALIGN_PARAGRAPH.CENTER33run_pt = page_title.add_run('\n\n\n' + 'TestData Plot Summary Report')34run_pt.font.name = u'Helvetica'35run_pt.font.size = Pt(40.5)36run_pt._element.rPr.rFonts.set(qn('w:eastAsia'), u'Helvetica')37run_pt.font.color.rgb = RGBColor(0, 0, 0)38run_pt.font.bold = True39pic_path = 'D:\\Python\\pythonProject\\venv\\pic'40list_pic = os.listdir(pic_path)41# pic_name 为图片名称拆分组成的DataFrame(分组名,Config,图类),columns为图片名称42pic_name = pd.DataFrame()43for i in list_pic:44 if os.path.isfile(pic_path + '\\' + i):45 list_temp = i.split('-')46 series_temp = pd.Series(list_temp[0:3])47 pic_name = pd.concat([pic_name,series_temp], axis=1)48 else:49 list_pic.remove(i)50pic_name.columns = list_pic51pic_name.sort_values(by=[2,0,1], axis=1, inplace=True) # 排序,先按照图类别,然后是组的类别,最后是Config52pic_name.to_csv('pic_name.csv')53flag_index = pd.Series(['','',''])54for i in pic_name.columns:55 if pic_name[i][0] != flag_index[0]:56 document.add_page_break()57 page_title = document.add_heading('', level=1)58 page_title.alignment = WD_ALIGN_PARAGRAPH.LEFT59 run_pt = page_title.add_run(pic_name[i][0])60 run_pt.font.name = u'Helvetica'61 run_pt.font.size = Pt(18)62 run_pt._element.rPr.rFonts.set(qn('w:eastAsia'), u'Helvetica')63 run_pt.font.color.rgb = RGBColor(0, 0, 0)64 run_pt.italic = True65 run_pt.font.bold = True66 pr_pic = document.add_paragraph()67 run_pict = pr_pic.add_run()68 if pic_name[i][1] != flag_index[1]:69 page_title_2nd = document.add_heading('', level=2)70 page_title_2nd.alignment = WD_ALIGN_PARAGRAPH.LEFT71 run_ct = page_title_2nd.add_run(pic_name[i][1])72 run_ct.font.name = u'Helvetica'73 run_ct.font.size = Pt(12)74 run_ct._element.rPr.rFonts.set(qn('w:eastAsia'), u'Helvetica')75 run_ct.font.color.rgb = RGBColor(0, 0, 0)76 pr_pic = document.add_paragraph()77 run_pict = pr_pic.add_run()78 run_pict.add_picture(pic_path + '\\' + i,height=Inches(2))79 flag_index = pic_name[i]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful