diff --git a/aio/README.md b/aio/README.md index 2d04416..45d1df6 100644 --- a/aio/README.md +++ b/aio/README.md @@ -181,3 +181,12 @@ v0.1.4(2024/06/06) 4. 修改了layout.xlsx布局,增加了duration/trqH/STO字段,以及额外的RC行,整体扩展了区域 5. 更改label/entry/optionmenu等控件的生成方式,使用循环实现,更加简洁和容易维护(暂未实现) 6. 支持工业/协作两条产品线的电机电流数据处理,包括单轴,场景,max/avg计算 + +v0.1.5(2024/06/12) +1. [aio.py]: 主界面切换不同功能时保持placehold一致 +2. [brake.py]: 由于制动采集模板和内容的更改,适配了新的数据,更新了算法 +3. [layout.xlsx]: 添加了各个功能的流程图 +4. [aio.py]: 重新调整界面配色 +5. [aio.py]: 修改了write2textbox函数,定制化显示每一行的颜色,针对每一行可自定义输出内容颜色 +6. [brake.py/iso.py/current.py]: 由于第 5 点的更改,同时修改了其他文件相关引用的部分 +7. [aio.py]: 更改label/entry/optionmenu等控件的生成方式,使用循环实现,更加简洁和容易维护 \ No newline at end of file diff --git a/aio/aio.py b/aio/aio.py index 64af908..9028b34 100644 --- a/aio/aio.py +++ b/aio/aio.py @@ -12,7 +12,7 @@ customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue" customtkinter.set_widget_scaling(1.1) # widget dimensions and text size customtkinter.set_window_scaling(1.1) # window geometry dimensions -socket.setdefaulttimeout(10) +socket.setdefaulttimeout(1) class App(customtkinter.CTk): @@ -26,6 +26,7 @@ class App(customtkinter.CTk): # self.iconbitmap('./icon.ico') self.geometry("1180x550+30+30") self.protocol("WM_DELETE_WINDOW", self.func_end_call_back) + self.config(bg='#E9E9E9') self.grid_rowconfigure(4, weight=1) self.grid_columnconfigure((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), weight=1) @@ -33,34 +34,34 @@ class App(customtkinter.CTk): # ===================================================================== # create frame sidebar(left) - self.frame_func = customtkinter.CTkFrame(self, width=120, corner_radius=0) + self.frame_func = customtkinter.CTkFrame(self, width=120, corner_radius=0, fg_color='#E9E9E9') self.frame_func.grid(row=0, column=0, rowspan=7, sticky='nsew') # create AIO logo - self.label_logo = customtkinter.CTkLabel(self.frame_func, text="Rokae AIO", height=60, font=customtkinter.CTkFont(family="Segoe Script Bold", size=24, weight="bold"), text_color="DarkSlateGray") + self.label_logo = customtkinter.CTkLabel(self.frame_func, text="Rokae AIO", height=60, font=customtkinter.CTkFont(family="Segoe Script Bold", size=24, weight="bold"), text_color="#4F4F4F") self.label_logo.grid(row=0, column=0, padx=15, pady=15) # create start button - self.btn_start = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='开始运行', font=self.my_font, command=lambda: self.thread_it(self.func_start_callback)) + self.btn_start = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='开始运行', fg_color='#4F4F4F', font=self.my_font, command=lambda: self.thread_it(self.func_start_callback)) self.btn_start.grid(row=1, column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5) # create param check button - self.btn_check = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='检查参数', font=self.my_font, command=lambda: self.thread_it(self.func_check_callback)) + self.btn_check = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='检查参数', fg_color='#4F4F4F', font=self.my_font, command=lambda: self.thread_it(self.func_check_callback)) self.btn_check.grid(row=2, column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5) # create start button - self.btn_log = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='保存日志', font=self.my_font, command=lambda: self.thread_it(self.func_log_callback)) + self.btn_log = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='保存日志', fg_color='#4F4F4F', font=self.my_font, command=lambda: self.thread_it(self.func_log_callback)) self.btn_log.grid(row=3, column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5) # create start button - self.btn_end = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='结束运行', font=self.my_font, command=self.func_end_call_back) + self.btn_end = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='结束运行', fg_color='#4F4F4F', font=self.my_font, command=self.func_end_call_back) self.btn_end.grid(row=4, column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5) # create version info - self.label_version = customtkinter.CTkLabel(self.frame_func, justify='left', text="Vers: 0.1.4\nDate: 06/06/2024", font=self.my_font, text_color="DarkCyan") + self.label_version = customtkinter.CTkLabel(self.frame_func, justify='left', text="Vers: 0.1.4\nDate: 06/06/2024", font=self.my_font, text_color="#4F4F4F") self.frame_func.rowconfigure(6, weight=1) self.label_version.grid(row=6, column=0, padx=20, pady=20, sticky='s') # ===================================================================== # create frame - self.frame_param = customtkinter.CTkFrame(self, corner_radius=10) - self.frame_param.grid(row=0, column=1, rowspan=3, columnspan=13, sticky='new', ipadx=20, ipady=10, padx=10, pady=(10, 5)) + self.frame_param = customtkinter.CTkFrame(self, corner_radius=5, fg_color='#E9E9E9', border_width=2, border_color='#CDCDCD') + self.frame_param.grid(row=0, column=1, rowspan=3, columnspan=13, sticky='new', ipadx=20, ipady=10, padx=10, pady=(5, 10)) # create main menu - self.menu_main = customtkinter.CTkOptionMenu(self.frame_param, values=["INIT", "brake", "current", "iso"], font=self.my_font, command=self.func_main_callback) + self.menu_main = customtkinter.CTkOptionMenu(self.frame_param, values=["INIT", "brake", "current", "iso"], font=self.my_font, text_color='yellow', button_color='red', fg_color='green', command=self.func_main_callback) self.menu_main.grid(row=0, column=1, sticky='we', padx=(20, 10), pady=(10, 5)) self.menu_main.set("Start Here!") # create sub menu @@ -104,31 +105,31 @@ class App(customtkinter.CTk): # create axis related self.label_axis = customtkinter.CTkLabel(self.frame_param, text="AXIS", font=self.my_font) self.label_axis.grid(row=2, column=2, sticky='e', pady=(5, 5)) - self.option_axis = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font) + self.option_axis = customtkinter.CTkOptionMenu(self.frame_param, button_color='#708090', fg_color='#778899', values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font) self.option_axis.grid(row=2, column=3, padx=(5, 10), pady=(5, 5), sticky='w') self.option_axis.configure(state='disabled') # create vel related self.label_vel = customtkinter.CTkLabel(self.frame_param, text="Vel", font=self.my_font) self.label_vel.grid(row=2, column=4, sticky='e', pady=(5, 5)) - self.option_vel = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font) + self.option_vel = customtkinter.CTkOptionMenu(self.frame_param, button_color='#708090', fg_color='#778899', values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font) self.option_vel.grid(row=2, column=5, padx=(5, 10), pady=(5, 5), sticky='w') self.option_vel.configure(state='disabled') # create trq related self.label_trq = customtkinter.CTkLabel(self.frame_param, text="Trq", font=self.my_font) self.label_trq.grid(row=2, column=6, sticky='e', pady=(5, 5)) - self.option_trq = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font) + self.option_trq = customtkinter.CTkOptionMenu(self.frame_param, button_color='#708090', fg_color='#778899', values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font) self.option_trq.grid(row=2, column=7, padx=(5, 10), pady=(5, 5), sticky='w') self.option_trq.configure(state='disabled') # create trqH related self.label_trqh = customtkinter.CTkLabel(self.frame_param, text="TrqH", font=self.my_font) self.label_trqh.grid(row=2, column=8, sticky='e', pady=(5, 5)) - self.option_trqh = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font) + self.option_trqh = customtkinter.CTkOptionMenu(self.frame_param, button_color='#708090', fg_color='#778899', values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font) self.option_trqh.grid(row=2, column=9, padx=(5, 10), pady=(5, 5), sticky='w') self.option_trqh.configure(state='disabled') # create STO related self.label_sto = customtkinter.CTkLabel(self.frame_param, text="STO", font=self.my_font) self.label_sto.grid(row=2, column=10, sticky='e', pady=(5, 5)) - self.option_sto = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font) + self.option_sto = customtkinter.CTkOptionMenu(self.frame_param, button_color='#708090', fg_color='#778899', values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font) self.option_sto.grid(row=2, column=11, padx=(5, 10), pady=(5, 5), sticky='w') self.option_sto.configure(state='disabled') # create rc1 @@ -169,7 +170,7 @@ class App(customtkinter.CTk): self.entry_rc_6.configure(state='disabled') # ===================================================================== # create textbox - self.textbox = customtkinter.CTkTextbox(self, wrap='none', font=customtkinter.CTkFont(family="consolas", size=14), text_color="blue") + self.textbox = customtkinter.CTkTextbox(self, wrap='none', font=customtkinter.CTkFont(family="consolas", size=14), text_color="blue", fg_color='#E9E9E9', border_width=2, border_color='#CDCDCD', border_spacing=5) self.textbox.grid(row=4, column=1, rowspan=3, columnspan=13, ipadx=10, ipady=10, padx=10, pady=(5, 10), sticky='nsew') self.textbox.configure(state='disabled') # ===================================================================== @@ -235,16 +236,13 @@ class App(customtkinter.CTk): self.initialization() if func_name == 'brake': - self.menu_sub = customtkinter.CTkOptionMenu(self.frame_param, values=["industrial", "cobot"], font=self.my_font, command=self.func_sub_callback) - self.menu_sub.grid(row=1, column=1, sticky='we', padx=(20, 10), pady=(5, 5)) - self.menu_sub.set("--select--") - self.label_path.configure(text="Path", text_color='red') self.label_av.configure(text="AV", text_color='red') self.label_rr.configure(text="RR", text_color='red') self.label_axis.configure(text="AXIS", text_color='red') self.label_vel.configure(text="Vel", text_color='red') self.label_trq.configure(text="Trq", text_color='red') + self.label_sto.configure(text="STO", text_color='red') self.entry_path.configure(state="normal") self.entry_av.configure(state="normal") @@ -252,6 +250,7 @@ class App(customtkinter.CTk): self.option_axis.configure(state="normal") self.option_vel.configure(state="normal") self.option_trq.configure(state="normal") + self.option_sto.configure(state="normal") elif func_name == 'current': self.menu_sub = customtkinter.CTkOptionMenu(self.frame_param, values=["max", "avg", "cycle"], font=self.my_font, command=self.func_sub_callback) @@ -284,17 +283,12 @@ class App(customtkinter.CTk): else: self.initialization() self.menu_main.set("Start Here!") + self.menu_main.configure(text_color='yellow') def func_sub_callback(self, func_name): - if func_name == "industrial": - self.label_rpm.configure(text="RPM", text_color='red') - self.entry_rpm.configure(state="normal") - elif func_name == "cobot": + if func_name == "max": self.label_rpm.configure(text="RPM", text_color='black') - self.entry_rpm.configure(state="disabled") - elif func_name == "max": - self.label_rpm.configure(text="RPM", text_color='black') - self.entry_rpm.configure(state="disabled", placeholder_text='额定转速') + self.entry_rpm.configure(placeholder_text='额定转速', state="disabled") self.label_dur.configure(text="Dur", text_color='black') self.entry_dur.configure(state="disabled") self.label_vel.configure(text="Vel", text_color='black') @@ -303,7 +297,7 @@ class App(customtkinter.CTk): self.option_trq.configure(state="disabled") elif func_name == 'avg': self.label_rpm.configure(text="RPM", text_color='black') - self.entry_rpm.configure(state="disabled", placeholder_text='额定转速') + self.entry_rpm.configure(placeholder_text='额定转速', state="disabled") self.label_dur.configure(text="Dur", text_color='black') self.entry_dur.configure(state="disabled") self.label_vel.configure(text="Vel", text_color='black') @@ -312,30 +306,30 @@ class App(customtkinter.CTk): self.option_trq.configure(state="disabled") elif func_name == 'cycle': self.label_rpm.configure(text="RPM", text_color='blue') - self.entry_rpm.configure(state="normal", placeholder_text='cycle') + self.entry_rpm.configure(state="normal", placeholder_text='额定转速') self.label_dur.configure(text="Dur", text_color='blue') - self.entry_dur.configure(state="normal", placeholder_text='scenario') + self.entry_dur.configure(state="normal", placeholder_text='周期') self.label_vel.configure(text="Vel", text_color='red') self.option_vel.configure(state="normal") self.label_trq.configure(text="Trq", text_color='red') self.option_trq.configure(state="normal") - def write2textbox(self, text, wait=0, exitcode=0): + def write2textbox(self, text, wait=0, exitcode=0, color='blue'): + self.textbox.tag_add(color, 'insert', 'end') + self.textbox.tag_config(tagName=color, foreground=color) + if wait != 0: - self.textbox.configure(text_color='blue') - self.textbox.insert(index='end', text=text) + self.textbox.insert(index='end', text=text, tags=color) self.textbox.update() self.textbox.see('end') elif exitcode != 0: - self.textbox.configure(text_color='red') - self.textbox.insert(index='end', text=text + '\n') + self.textbox.insert(index='end', text=text + '\n', tags=color) self.textbox.update() self.textbox.see('end') self.textbox.configure(state='disabled') raise Exception(f"Error code: {exitcode}") else: - self.textbox.configure(text_color='blue') - self.textbox.insert(index='end', text=text + '\n') + self.textbox.insert(index='end', text=text + '\n', tags=color) self.textbox.update() self.textbox.see('end') @@ -349,7 +343,7 @@ class App(customtkinter.CTk): _ = float(item) except Exception as Err: tkinter.messagebox.showerror(title="参数错误", message="请检查对应参数是否填写正确!", ) - self.write2textbox(f"错误信息:{Err}\n参数数据缺失,或者数据类型错误,更正后重新运行...", 0, 3) + self.write2textbox(f"错误信息:{Err}\n参数数据缺失,或者数据类型错误,更正后重新运行...\n", 0, 3, 'red') return True def check_param(self): @@ -361,24 +355,18 @@ class App(customtkinter.CTk): axis = self.option_axis.get() vel = self.option_vel.get() trq = self.option_trq.get() + sto = self.option_sto.get() sub_func = self.menu_sub.get() c1 = exists(path) c2 = self.is_float('required', av, rr) - c3 = rpm = 1 + # c3 = rpm = 1 + c3 = True if len({vel, trq, sto}) == 3 else False c4 = sub_func in ['industrial', 'cobot'] c5 = True if vel != trq else False - if self.menu_sub.get() == 'industrial': - rpm = self.entry_rpm.get().strip('- ') - c3 = rpm.isdigit() - elif self.menu_sub.get() == 'cobot': - pass - else: - pass - if c1 and c2 and c3 and c4 and c5: - return 1, path, float(av), float(rr), int(rpm), int(axis), int(vel), int(trq) + return 1, path, float(av), float(rr), int(sto), int(axis), int(vel), int(trq) else: return 0, 0 # ======================================================= @@ -440,7 +428,7 @@ class App(customtkinter.CTk): func_dict = {1: brake.main, 2: current.main, 3: iso.main} if flag == 1: - func_dict[flag](path=args[0], av=args[1], rr=args[2], rpm=args[3], axis=args[4], vel=args[5], trq=args[6], w2t=self.write2textbox) + func_dict[flag](path=args[0], av=args[1], rr=args[2], sto=args[3], axis=args[4], vel=args[5], trq=args[6], w2t=self.write2textbox) elif flag == 2: # tkinter.messagebox.showinfo(title="TBD", message="功能待实现......") func_dict[flag](path=args[0], sub=args[1], rcs=args[2], vel=args[3], trq=args[4], trqh=args[5], dur=args[6], rpm=args[7], w2t=self.write2textbox) diff --git a/aio/brake.py b/aio/brake.py index 9aacb3f..f258e31 100644 --- a/aio/brake.py +++ b/aio/brake.py @@ -27,12 +27,12 @@ class GetThreadResult(Thread): return None -def data_process(result_file, raw_data_dirs, av, rr, axis, vel, trq, w2t, rpm): +def data_process(result_file, raw_data_dirs, av, rr, axis, vel, trq, w2t, sto): # 功能:完成一个结果文件的数据处理 # 参数:结果文件,数据目录,以及预读取的参数 # 返回值:- file_name = result_file.split('\\')[-1] - w2t(f"打开文件 {file_name} 需要 1min 左右", 1) + w2t(f"打开文件 {file_name} 需要 1min 左右", 1, 0, 'orange') global stop stop = 0 @@ -55,21 +55,21 @@ def data_process(result_file, raw_data_dirs, av, rr, axis, vel, trq, w2t, rpm): # count = 1 # for data_file in data_files: # now_doing_msg(data_file, 'start', w2t) - # single_file_process(data_file, wb_result, count, av, rr, axis, vel, trq, w2t, rpm) + # single_file_process(data_file, wb_result, count, av, rr, axis, vel, trq, w2t, sto) # count += 1 # now_doing_msg(data_file, 'done', w2t) # --------------------------------------------------- # 数据文件并行处理模式--------------------------------- - threads = [Thread(target=single_file_process, args=(data_files[0], wb_result, 1, av, rr, axis, vel, trq, w2t, rpm)), - Thread(target=single_file_process, args=(data_files[1], wb_result, 2, av, rr, axis, vel, trq, w2t, rpm)), - Thread(target=single_file_process, args=(data_files[2], wb_result, 3, av, rr, axis, vel, trq, w2t, rpm))] + threads = [Thread(target=single_file_process, args=(data_files[0], wb_result, 1, av, rr, axis, vel, trq, w2t, sto)), + Thread(target=single_file_process, args=(data_files[1], wb_result, 2, av, rr, axis, vel, trq, w2t, sto)), + Thread(target=single_file_process, args=(data_files[2], wb_result, 3, av, rr, axis, vel, trq, w2t, sto))] [t.start() for t in threads] [t.join() for t in threads] # --------------------------------------------------- now_doing_msg(raw_data_dir, 'done', w2t) now_doing_msg(result_file, 'done', w2t) - w2t(f"保存文件 {file_name} 需要 1min 左右", 1) + w2t(f"保存文件 {file_name} 需要 1min 左右", 1, 0, 'orange') stop = 0 t_excel = Thread(target=wb_result.save, args=(result_file, )) t_wait = Thread(target=w2t_local, args=('.', 1, w2t)) @@ -89,7 +89,7 @@ def check_files(raw_data_dirs, result_files, w2t): msg = "结果文件数目错误,结果文件有且只有三个,请确认!" for result_file in result_files: w2t(result_file) - w2t(msg, 0, 2) + w2t(msg, 0, 2, 'red') prefix = [] for result_file in result_files: @@ -99,10 +99,10 @@ def check_files(raw_data_dirs, result_files, w2t): del wd[-1] wd = '\\'.join(wd) msg = f"""请关闭所有相关数据文件,并检查工作目录 {wd} 下,有且只允许有类似如下三个文件: - 1. reach33_自研_制动性能测试.xlsx - 2. reach66_自研_制动性能测试.xlsx - 3. reach100_自研_制动性能测试.xlsx""" - w2t(msg, 0, 3) + 1. reach33_XXX制动性能测试.xlsx + 2. reach66_XXX制动性能测试.xlsx + 3. reach100_XX制动性能测试.xlsx""" + w2t(msg, 0, 3, 'red') for raw_data_dir in raw_data_dirs: components = raw_data_dir.split('\\')[-1].split('_') @@ -112,17 +112,17 @@ def check_files(raw_data_dirs, result_files, w2t): components[2] not in ['speed33', 'speed66', 'speed100']: msg = f"""报错信息:数据目录 {raw_data_dir} 命名不合规,请参考如下形式: 命名规则:reachAA_loadBB_speedCC -规则解释:AA/BB/CC 指的是负载/速度/臂展的比例,例如reach66_load100_speed33:66%臂展,100%负载以及33%速度情况下的测试结果文件夹""" - w2t(msg, 0, 4) +规则解释:AA/BB/CC 指的是臂展/负载/速度的比例,例如reach66_load100_speed33:66%臂展,100%负载以及33%速度情况下的测试结果文件夹""" + w2t(msg, 0, 4, 'red') _, raw_data_files = traversal_files(raw_data_dir, w2t) if len(raw_data_files) != 3: - msg = f"数据目录 {raw_data_dir} 下数据文件个数错误,每个数据目录下有且只能有三个以 .data/csv 为后缀的数据文件" - w2t(msg, 0, 5) + msg = f"数据目录 {raw_data_dir} 下数据文件个数错误,每个数据目录下有且只能有三个以 .data 为后缀的数据文件" + w2t(msg, 0, 5, 'red') for raw_data_file in raw_data_files: - if not (raw_data_file.split('\\')[-1].endswith('.data') or raw_data_file.split('\\')[-1].endswith('.csv')): - msg = f"数据文件 {raw_data_file} 后缀错误,每个数据目录下有且只能有三个以 .data/csv 为后缀的数据文件" - w2t(msg, 0, 6) + if not raw_data_file.split('\\')[-1].endswith('.data'): + msg = f"数据文件 {raw_data_file} 后缀错误,每个数据目录下有且只能有三个以 .data 为后缀的数据文件" + w2t(msg, 0, 6, 'red') w2t("数据目录合规性检查结束,未发现问题......") @@ -148,122 +148,90 @@ def w2t_local(msg, wait, w2t): global stop if stop == 0 and wait != 0: sleep(1) - w2t(msg, wait) + w2t(msg, wait, 0, 'orange') else: break -def single_file_process(data_file, wb_result, count, av, rr, axis, vel, trq, w2t, rpm): +def single_file_process(data_file, wb_result, count, av, rr, axis, vel, trq, w2t, sto): # 功能:完成单个数据文件的处理 # 参数:如上 # 返回值:- - if data_file.endswith('.data'): - sep = '\t' - df = read_csv(data_file, sep=sep) - elif data_file.endswith('.csv'): - sep = ',' - df = read_csv(data_file, sep=sep, encoding='gbk', header=8) + df = read_csv(data_file, sep='\t') conditions = sorted(data_file.split('\\')[-2].split('_')) # ['loadxx', 'reachxx', 'speedxx'] result_sheet_name = find_result_sheet_name(conditions, count) ws_result = wb_result[result_sheet_name] - row_max, row_start, flag = find_row_start(data_file, df, conditions, av, rr, axis, vel, w2t, rpm) - - copy_data_to_result(flag, df, ws_result, row_max, row_start, vel, trq, rpm) - ws_result["C2"] = int(2) - ws_result["G2"] = int(10+4) + row_start, row_end = find_row_start(data_file, df, conditions, av, rr, axis, vel, w2t, sto) + copy_data_to_result(df, ws_result, row_start, row_end, vel, trq, sto) -def copy_data_to_result(flag, df, ws_result, row_max, row_start, vel, trq, rpm): +def copy_data_to_result(df, ws_result, row_start, row_end, vel, trq, sto): # 功能:将数据文件中有效数据拷贝至结果文件对应的 sheet # 参数:如上 # 返回值:- # 结果文件数据清零 - for row in ws_result.iter_rows(min_row=2, min_col=1, max_row=2000, max_col=2): - for cell in row: - cell.value = None - if flag == 1: - # 将合适的数据复制到结果文件 - row_max = row_start + 399 if row_max-row_start > 400 else row_max - rc = 1 if rpm == 1 else 1000 + data = [] + for _row in range(row_start, row_end + 1): + data.append(df.iloc[_row, vel-1]) + data.append(df.iloc[_row, trq-1]) + data.append(df.iloc[_row, trq-1]) - data = [] - for i in range(row_start, row_max+1): - data.append(df.iloc[i, vel-1] * rpm) - data.append(df.iloc[i, trq-1] * rc) - - i = 0 - for row in ws_result.iter_rows(min_row=2, min_col=1, max_row=row_max - row_start + 2, max_col=2): - for cell in row: - cell.value = data[i] - i = i + 1 - else: - pass + i = 0 + row_max = 2000 if row_end-row_start < 2000 else row_end-row_start+20 + for _row in range(2, row_max): + try: + ws_result.cell(row=_row, column=0).value = data[i] + ws_result.cell(row=_row, column=0).value = data[i+1] + ws_result.cell(row=_row, column=0).value = data[i+2] + i += 3 + except: + ws_result.cell(row=_row, column=0).value = None + ws_result.cell(row=_row, column=0).value = None + ws_result.cell(row=_row, column=0).value = None def find_result_sheet_name(conditions, count): # 功能:获取结果文件准确的sheet页名称 # 参数:臂展和速度的列表 # 返回值:结果文件对应的sheet name - # 33%臂展_33%速度_正1 + # 33%负载_33%速度_1 - ['loadxx', 'reachxx', 'speedxx'] load = conditions[0].removeprefix('load') speed = conditions[2].removeprefix('speed') - result_sheet_name = f"{load}%负载_{speed}%速度_正{count}" + result_sheet_name = f"{load}%负载_{speed}%速度_{count}" return result_sheet_name -def find_row_start(data_file, df, conditions, av, rr, axis, vel, w2t, rpm): +def find_row_start(data_file, df, conditions, av, rr, axis, vel, w2t, sto): # 功能:查找数据文件中有效数据的行号,也即最后一个速度下降的点位 # 参数:如上 # 返回值:速度下降点位,最后的数据点位 ratio = float(conditions[2].removeprefix('speed'))/100 - speed_max = av * ratio * rr / 6 - row_max = row_start = df.index[-1] + speed_max = av * rr * ratio * 60 / 360 + row_max = df.index[-1] + threshold = 30 if axis == 2 and conditions[0].removeprefix('load') == '100' else 10 - threshold, step = get_threshold_step(data_file, axis) - while row_start > step+1: - speed = abs(df.iloc[row_start, vel-1] * rpm) - if int(speed) < 1: - row_start -= 50 - continue - - _ = [] - for i in range(row_start, row_start-step+1, -1): - _.append(df.iloc[i, vel-1] * rpm) - speed_avg = abs(sum(_))/len(_) - - if abs(speed_avg-speed_max) < threshold: - row_start = row_start - 10 - flag = 1 + for _row in range(row_max, -1, -1): + if df.iloc[_row, sto-1] != 0: + row_start = _row-100 if _row-100 > 0 else 0 break - else: - row_start -= step else: - msg = f"可能是{data_file}这个文件数据采集有问题,比如未采集理论速度值,也有可能是程序步长设定问题,请检查......" - w2t(msg) - flag = 0 + w2t(f"数据文件 {data_file} 采集的数据中没有 STO 为非 0 的情况,需要确认......", 0, 9, 'red') - return row_max, row_start, flag - - -def get_threshold_step(excel_file, axis): - # 功能:负载和速度100%,且是j2的时候,做特殊处理 - # 参数:新生成的excel,轴号 - # 返回值:速度差阈值,处理步长 - conditions = sorted(excel_file.split('\\')[-2].split('_')) - # 只有负载和速度是100%时,才会启用更敏感的step - flg = 1 if conditions[0][-3:] == '100' and conditions[2][-3:] == '100' else 0 - if flg == 1 and axis == 2: - threshold = 30 - step = 5 + for _row in range(row_start, row_max): + if abs(df.iloc[_row, vel-1]) < 1: + row_end = _row+100 if _row+100 <= row_max else row_max + break else: - threshold = 10 - step = 5 + w2t(f"数据文件 {data_file} 最后的速度未降为零 ", 0, 10, 'red') - return threshold, step + if abs(df.iloc[row_start+50]-speed_max) > threshold: + w2t(f"数据文件 {data_file} 未采集到指定百分比的最大速度,需要检查......") + + return row_start, row_end def traversal_files(path, w2t): @@ -272,7 +240,7 @@ def traversal_files(path, w2t): # 返回值:路径下的文件夹列表 路径下的文件列表 if not exists(path): msg = f'数据文件夹{path}不存在,请确认后重试......' - w2t(msg, 0, 1) + w2t(msg, 0, 1, 'red') else: dirs = [] files = [] @@ -285,32 +253,33 @@ def traversal_files(path, w2t): return dirs, files -def main(path, av, rr, rpm, axis, vel, trq, w2t): +def main(path, av, rr, sto, axis, vel, trq, w2t): # 功能:执行处理所有数据文件 # 参数:initialization函数的返回值 # 返回值:- time_start = time() raw_data_dirs, result_files = traversal_files(path, w2t) - prefix = [] - for raw_data_dir in raw_data_dirs: - prefix.append(raw_data_dir.split('\\')[-1].split("_")[0]) try: # threads = [] check_files(raw_data_dirs, result_files, w2t) + prefix = [] + for raw_data_dir in raw_data_dirs: + prefix.append(raw_data_dir.split('\\')[-1].split("_")[0]) + for result_file in result_files: if result_file.split('\\')[-1].split('_')[0] not in set(prefix): continue else: now_doing_msg(result_file, 'start', w2t) - data_process(result_file, raw_data_dirs, av, rr, axis, vel, trq, w2t, rpm) + data_process(result_file, raw_data_dirs, av, rr, axis, vel, trq, w2t, sto) # threads.append(Thread(target=data_process, args=(result_file, raw_data_dirs, AV, RR, RC, AXIS))) # [t.start() for t in threads] # [t.join() for t in threads] except Exception as Err: msg = f"出现错误:{Err}\n程序运行错误,请检查配置文件是否准确设定,以及数据文件组织是否正确,也有可能是结果文件损坏,尝试重新复制一份,再运行!" - w2t(msg) + w2t(msg, 0, 11, 'red') w2t("----------------------------------------------------------") w2t("全部处理完毕") @@ -322,4 +291,4 @@ def main(path, av, rr, rpm, axis, vel, trq, w2t): if __name__ == "__main__": stop = 0 - main(path=argv[1], av=argv[2], rr=argv[3], rpm=argv[4], axis=argv[5], vel=argv[6], trq=argv[7], w2t=argv[8]) + main(path=argv[1], av=argv[2], rr=argv[3], sto=argv[4], axis=argv[5], vel=argv[6], trq=argv[7], w2t=argv[8]) diff --git a/aio/current.py b/aio/current.py index 422d384..2a898a4 100644 --- a/aio/current.py +++ b/aio/current.py @@ -7,6 +7,8 @@ from re import match from threading import Thread from time import sleep from csv import reader + + class GetThreadResult(Thread): def __init__(self, func, args=()): super(GetThreadResult, self).__init__() @@ -31,7 +33,7 @@ def w2t_local(msg, wait, w2t): global stop if stop == 0 and wait != 0: sleep(1) - w2t(msg, wait) + w2t(msg, wait, 0, 'orange') else: break @@ -42,7 +44,7 @@ def traversal_files(path, w2t): # 返回值:路径下的文件夹列表 路径下的文件列表 if not exists(path): msg = f'数据文件夹{path}不存在,请确认后重试......' - w2t(msg, 0, 8) + w2t(msg, 0, 8, 'red') else: dirs = [] files = [] @@ -64,16 +66,16 @@ def initialization(path, sub, w2t): if sub != 'cycle': if not (match('j[1-7].*\\.data', filename) or match('j[1-7].*\\.csv', filename)): msg = f"所有文件必须以 jx_ 开头,以 .data/csv 结尾(x取值1-7),请检查后重新运行。" - w2t(msg, 0, 6) + w2t(msg, 0, 6, 'red') else: if filename.endswith('.xlsx'): count += 1 elif not (match('j[1-7].*\\.data', filename) or match('j[1-7].*\\.csv', filename)): msg = f"所有文件必须以 jx_ 开头,以 .data/csv 结尾(x取值1-7),请检查后重新运行。" - w2t(msg, 0, 7) + w2t(msg, 0, 7, 'red') if sub == 'cycle' and count != 1: - w2t("未找到电机电流数据处理excel表格,确认后重新运行!", 0, 5) + w2t("未找到电机电流数据处理excel表格,确认后重新运行!", 0, 5, 'red') return data_files @@ -138,8 +140,7 @@ def current_cycle(dur, data_files, rcs, vel, trq, trqh, rpm, w2t): else: single.append(data_file) - w2t(f"正在打开文件 {result},需要 10s 左右", 1) - + w2t(f"正在打开文件 {result},需要 10s 左右", 1, 0, 'orange') global stop stop = 0 t_excel = GetThreadResult(load_workbook, args=(result, )) @@ -166,7 +167,7 @@ def current_cycle(dur, data_files, rcs, vel, trq, trqh, rpm, w2t): else: p_scenario(wb, single, vel, trq, rpm, dur, w2t) - w2t(f"正在保存文件 {result},需要 10s 左右", 1) + w2t(f"正在保存文件 {result},需要 10s 左右", 1, 0, 'orange') stop = 0 t_excel = Thread(target=wb.save, args=(result, )) t_wait = Thread(target=w2t_local, args=('.', 1, w2t)) @@ -191,7 +192,7 @@ def find_point(flag, df, _row_s, _row_e, w2t, exitcode, threshold, step, end_poi else: return _row_s, _row_e else: - w2t(f"数据有误,需要检查,无法找到第{exitcode}个有效点...", 0, exitcode) + w2t(f"数据有误,需要检查,无法找到第{exitcode}个有效点...", 0, exitcode, 'red') elif flag == 'gt': while _row_e > end_point: speed_avg = df.iloc[_row_s:_row_e, 0].abs().mean() @@ -202,7 +203,7 @@ def find_point(flag, df, _row_s, _row_e, w2t, exitcode, threshold, step, end_poi else: return _row_s, _row_e else: - w2t(f"数据有误,需要检查,无法找到有效起始点或结束点...", 0, exitcode) + w2t(f"数据有误,需要检查,无法找到有效起始点或结束点...", 0, exitcode, 'red') def p_single(wb, single, vel, trq, rpm, w2t): @@ -262,7 +263,7 @@ def p_single(wb, single, vel, trq, rpm, w2t): _row_e -= _end_point _row_s -= _end_point _row_s, _row_e = find_point('lt', df, _row_s, _row_e, w2t, 4, threshold=2, step=_step, end_point=_end_point) - #目前已经有一点的速度值了,继续往前搜寻下一个速度为零的点 + # 目前已经有一点的速度值了,继续往前搜寻下一个速度为零的点 _row_e -= _end_point _row_s -= _end_point _row_s, _row_e = find_point('gt', df, _row_s, _row_e, w2t, 4, threshold=2, step=_step, end_point=_end_point) @@ -316,7 +317,7 @@ def p_scenario(wb, single, vel, trq, rpm, dur, w2t): row_start = 300 row_end = row_start + int(dur/cycle) if row_end > df.index[-1]: - w2t(f"位置超限:{data_file} 共有 {df.index[-1]} 条数据,无法取到第 {row_end} 条数据...", 0, 9) + w2t(f"位置超限:{data_file} 共有 {df.index[-1]} 条数据,无法取到第 {row_end} 条数据...", 0, 9, 'red') data = [] for row in range(row_start, row_end): diff --git a/aio/iso.py b/aio/iso.py index 7dd73fa..a6be621 100644 --- a/aio/iso.py +++ b/aio/iso.py @@ -12,7 +12,7 @@ def traversal_files(path, w2t): # 返回值:路径下的文件夹列表 路径下的文件列表 if not exists(path): msg = f'数据文件夹{path}不存在,请确认后重试......' - w2t(msg, 0, 1) + w2t(msg, 0, 1, 'red') else: dirs = files = [] for item in scandir(path): @@ -162,7 +162,7 @@ def main(path, w2t): ws.cell(row=i, column=7).value = None tmpfile = f"{path}\\data.txt" except Exception as Err: - w2t(f"发生错误:{Err}", 0, 2) + w2t(f"发生错误:{Err}", 0, 2, 'red') p_files = [] for file in files: @@ -187,7 +187,7 @@ def main(path, w2t): wb.close() if len(p_files) == 0: - w2t(f"目录 {path} 下没有需要处理的文件,需要确认......", 0, 3) + w2t(f"目录 {path} 下没有需要处理的文件,需要确认......", 0, 3, 'red') else: remove(tmpfile) w2t("------------------------------------------")