[modify] support single axis cycle data process
This commit is contained in:
parent
55514abc93
commit
97ba8ffc51
197
aio/aio.py
197
aio/aio.py
@ -24,17 +24,12 @@ class App(customtkinter.CTk):
|
||||
# configure window
|
||||
self.title("AIO - All in one automatic toolbox")
|
||||
# self.iconbitmap('./icon.ico')
|
||||
# screen_width = self.winfo_screenwidth()
|
||||
# screen_height = self.winfo_screenheight()
|
||||
# width = screen_width - 200
|
||||
# height = screen_height - 200
|
||||
# self.geometry(f"{width}x{height}+{100}+{100}")
|
||||
self.geometry("1100x500+100+100")
|
||||
self.geometry("1180x550+100+100")
|
||||
self.protocol("WM_DELETE_WINDOW", self.func_end_call_back)
|
||||
|
||||
self.grid_rowconfigure(3, weight=1)
|
||||
self.grid_columnconfigure((1, 2, 3, 4, 5, 6, 7, 8, 9), weight=1)
|
||||
self.minsize(1100, 500)
|
||||
self.grid_rowconfigure(4, weight=1)
|
||||
self.grid_columnconfigure((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), weight=1)
|
||||
self.minsize(1180, 550)
|
||||
|
||||
# =====================================================================
|
||||
# create frame sidebar(left)
|
||||
@ -62,8 +57,8 @@ class App(customtkinter.CTk):
|
||||
|
||||
# =====================================================================
|
||||
# create frame
|
||||
self.frame_param = customtkinter.CTkFrame(self, height=240, corner_radius=10)
|
||||
self.frame_param.grid(row=0, column=1, rowspan=3, columnspan=11, sticky='new', ipadx=20, ipady=10, padx=10, pady=(10, 5))
|
||||
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))
|
||||
# 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.grid(row=0, column=1, sticky='we', padx=(20, 10), pady=(10, 5))
|
||||
@ -74,7 +69,7 @@ class App(customtkinter.CTk):
|
||||
self.label_path = customtkinter.CTkLabel(self.frame_param, text="Path", font=self.my_font)
|
||||
self.label_path.grid(row=0, column=2, sticky='e', pady=(10, 5))
|
||||
self.entry_path = customtkinter.CTkEntry(self.frame_param, width=670, placeholder_text="数据文件夹路径", font=self.my_font)
|
||||
self.entry_path.grid(row=0, column=3, columnspan=9, padx=(5, 10), pady=(10, 5), sticky='we')
|
||||
self.entry_path.grid(row=0, column=3, columnspan=11, padx=(5, 10), pady=(10, 5), sticky='we')
|
||||
self.entry_path.configure(state='disabled')
|
||||
# create av related
|
||||
self.label_av = customtkinter.CTkLabel(self.frame_param, text="AV", font=self.my_font)
|
||||
@ -124,10 +119,52 @@ class App(customtkinter.CTk):
|
||||
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.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.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.grid(row=2, column=11, padx=(5, 10), pady=(5, 5), sticky='w')
|
||||
self.option_sto.configure(state='disabled')
|
||||
# create rc1
|
||||
self.label_rc_1 = customtkinter.CTkLabel(self.frame_param, text="RC1", font=self.my_font)
|
||||
self.label_rc_1.grid(row=3, column=2, sticky='e', pady=(5, 5))
|
||||
self.entry_rc_1 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
|
||||
self.entry_rc_1.grid(row=3, column=3, padx=(5, 10), pady=(5, 5), sticky='w')
|
||||
|
||||
self.label_rc_2 = customtkinter.CTkLabel(self.frame_param, text="RC2", font=self.my_font)
|
||||
self.label_rc_2.grid(row=3, column=4, sticky='e', pady=(5, 5))
|
||||
self.entry_rc_2 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
|
||||
self.entry_rc_2.grid(row=3, column=5, padx=(5, 10), pady=(5, 5), sticky='w')
|
||||
|
||||
self.label_rc_3 = customtkinter.CTkLabel(self.frame_param, text="RC3", font=self.my_font)
|
||||
self.label_rc_3.grid(row=3, column=6, sticky='e', pady=(5, 5))
|
||||
self.entry_rc_3 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
|
||||
self.entry_rc_3.grid(row=3, column=7, padx=(5, 10), pady=(5, 5), sticky='w')
|
||||
|
||||
self.label_rc_4 = customtkinter.CTkLabel(self.frame_param, text="RC4", font=self.my_font)
|
||||
self.label_rc_4.grid(row=3, column=8, sticky='e', pady=(5, 5))
|
||||
self.entry_rc_4 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
|
||||
self.entry_rc_4.grid(row=3, column=9, padx=(5, 10), pady=(5, 5), sticky='w')
|
||||
|
||||
self.label_rc_5 = customtkinter.CTkLabel(self.frame_param, text="RC5", font=self.my_font)
|
||||
self.label_rc_5.grid(row=3, column=10, sticky='e', pady=(5, 5))
|
||||
self.entry_rc_5 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
|
||||
self.entry_rc_5.grid(row=3, column=11, padx=(5, 10), pady=(5, 5), sticky='w')
|
||||
|
||||
self.label_rc_6 = customtkinter.CTkLabel(self.frame_param, text="RC6", font=self.my_font)
|
||||
self.label_rc_6.grid(row=3, column=12, sticky='e', pady=(5, 5))
|
||||
self.entry_rc_6 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
|
||||
self.entry_rc_6.grid(row=3, column=13, padx=(5, 10), pady=(5, 5), sticky='w')
|
||||
# =====================================================================
|
||||
# create textbox
|
||||
self.textbox = customtkinter.CTkTextbox(self, height=640, wrap='none', font=customtkinter.CTkFont(family="consolas", size=14), text_color="blue")
|
||||
self.textbox.grid(row=3, column=1, rowspan=5, columnspan=15, ipadx=10, ipady=10, padx=10, pady=(5, 10), sticky='nsew')
|
||||
self.textbox = customtkinter.CTkTextbox(self, wrap='none', font=customtkinter.CTkFont(family="consolas", size=14), text_color="blue")
|
||||
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')
|
||||
# =====================================================================
|
||||
# version check
|
||||
@ -157,6 +194,14 @@ class App(customtkinter.CTk):
|
||||
self.label_axis.configure(text="AXIS", text_color="black")
|
||||
self.label_vel.configure(text="Vel", text_color="black")
|
||||
self.label_trq.configure(text="Trq", text_color="black")
|
||||
self.label_trqh.configure(text="TrqH", text_color="black")
|
||||
self.label_sto.configure(text="STO", text_color="black")
|
||||
self.label_rc_1.configure(text="RC1", text_color="black")
|
||||
self.label_rc_2.configure(text="RC2", text_color="black")
|
||||
self.label_rc_3.configure(text="RC3", text_color="black")
|
||||
self.label_rc_4.configure(text="RC4", text_color="black")
|
||||
self.label_rc_5.configure(text="RC5", text_color="black")
|
||||
self.label_rc_6.configure(text="RC6", text_color="black")
|
||||
|
||||
self.entry_path.configure(placeholder_text="数据文件夹路径", state="disabled")
|
||||
self.entry_av.configure(placeholder_text="角速度", state="disabled")
|
||||
@ -167,6 +212,14 @@ class App(customtkinter.CTk):
|
||||
self.option_axis.configure(state="disabled")
|
||||
self.option_vel.configure(state="disabled")
|
||||
self.option_trq.configure(state="disabled")
|
||||
self.option_trqh.configure(state="disabled")
|
||||
self.option_sto.configure(state="disabled")
|
||||
self.entry_rc_1.configure(placeholder_text="optional", state="disabled")
|
||||
self.entry_rc_2.configure(placeholder_text="optional", state="disabled")
|
||||
self.entry_rc_3.configure(placeholder_text="optional", state="disabled")
|
||||
self.entry_rc_4.configure(placeholder_text="optional", state="disabled")
|
||||
self.entry_rc_5.configure(placeholder_text="optional", state="disabled")
|
||||
self.entry_rc_6.configure(placeholder_text="optional", state="disabled")
|
||||
|
||||
self.menu_sub.grid_forget()
|
||||
self.textbox.delete(index1='1.0', index2='end')
|
||||
@ -180,12 +233,12 @@ class App(customtkinter.CTk):
|
||||
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_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.entry_path.configure(state="normal")
|
||||
self.entry_av.configure(state="normal")
|
||||
@ -199,22 +252,36 @@ class App(customtkinter.CTk):
|
||||
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_rc.configure(text="*RC", text_color='red')
|
||||
self.label_trq.configure(text="*Trq", text_color='red')
|
||||
self.label_path.configure(text="Path", text_color='red')
|
||||
self.label_rc.configure(text="RC", text_color='blue')
|
||||
self.label_trqh.configure(text="TrqH", text_color='red')
|
||||
self.label_rc_1.configure(text="RC1", text_color='red')
|
||||
self.label_rc_2.configure(text="RC2", text_color='red')
|
||||
self.label_rc_3.configure(text="RC3", text_color='red')
|
||||
self.label_rc_4.configure(text="RC4", text_color='red')
|
||||
self.label_rc_5.configure(text="RC5", text_color='red')
|
||||
self.label_rc_6.configure(text="RC6", text_color='red')
|
||||
self.entry_path.configure(state="normal")
|
||||
self.entry_rc.configure(state="normal")
|
||||
self.option_trq.configure(state="normal")
|
||||
self.entry_rc.configure(state="normal", placeholder_text="optional")
|
||||
self.option_trqh.configure(state="normal")
|
||||
self.entry_rc_1.configure(state="normal", placeholder_text="额定电流")
|
||||
self.entry_rc_2.configure(state="normal", placeholder_text="额定电流")
|
||||
self.entry_rc_3.configure(state="normal", placeholder_text="额定电流")
|
||||
self.entry_rc_4.configure(state="normal", placeholder_text="额定电流")
|
||||
self.entry_rc_5.configure(state="normal", placeholder_text="额定电流")
|
||||
self.entry_rc_6.configure(state="normal", placeholder_text="额定电流")
|
||||
|
||||
elif func_name == 'iso':
|
||||
self.label_path.configure(text="*Path", text_color='red')
|
||||
self.label_path.configure(text="Path", text_color='red')
|
||||
self.entry_path.configure(state="normal")
|
||||
|
||||
else:
|
||||
self.initialization()
|
||||
self.menu_main.set("Start Here!")
|
||||
|
||||
def func_sub_callback(self, func_name):
|
||||
if func_name == "industrial":
|
||||
self.label_rpm.configure(text="*RPM", text_color='red')
|
||||
self.label_rpm.configure(text="RPM", text_color='red')
|
||||
self.entry_rpm.configure(state="normal")
|
||||
elif func_name == "cobot":
|
||||
self.label_rpm.configure(text="RPM", text_color='black')
|
||||
@ -224,16 +291,22 @@ class App(customtkinter.CTk):
|
||||
self.entry_dur.configure(state="disabled")
|
||||
self.label_vel.configure(text="Vel", text_color='black')
|
||||
self.option_vel.configure(state="disabled")
|
||||
self.label_trq.configure(text="Trq", text_color='black')
|
||||
self.option_trq.configure(state="disabled")
|
||||
elif func_name == 'avg':
|
||||
self.label_dur.configure(text="Dur", text_color='black')
|
||||
self.entry_dur.configure(state="disabled")
|
||||
self.label_vel.configure(text="Vel", text_color='black')
|
||||
self.option_vel.configure(state="disabled")
|
||||
self.label_trq.configure(text="Trq", text_color='black')
|
||||
self.option_trq.configure(state="disabled")
|
||||
elif func_name == 'cycle':
|
||||
self.label_dur.configure(text="*Dur", text_color='red')
|
||||
self.entry_dur.configure(state="normal")
|
||||
self.label_vel.configure(text="*Vel", text_color='red')
|
||||
self.label_dur.configure(text="Dur", text_color='blue')
|
||||
self.entry_dur.configure(state="normal", placeholder_text='scenario')
|
||||
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):
|
||||
@ -247,6 +320,7 @@ class App(customtkinter.CTk):
|
||||
self.textbox.insert(index='end', text=text + '\n')
|
||||
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')
|
||||
@ -254,6 +328,19 @@ class App(customtkinter.CTk):
|
||||
self.textbox.update()
|
||||
self.textbox.see('end')
|
||||
|
||||
def is_float(self, flag, *args):
|
||||
for item in args:
|
||||
try:
|
||||
if flag == 'optional':
|
||||
item = 0 if item == '' else item
|
||||
_ = float(item)
|
||||
elif flag == 'required':
|
||||
_ = float(item)
|
||||
except Exception as Err:
|
||||
self.write2textbox(str(Err))
|
||||
self.write2textbox("参数数据缺失,或者数据类型错误,更正后重新运行...", 0, 3)
|
||||
return True
|
||||
|
||||
def check_param(self):
|
||||
func_name = self.menu_main.get()
|
||||
if func_name == 'brake':
|
||||
@ -266,12 +353,7 @@ class App(customtkinter.CTk):
|
||||
sub_func = self.menu_sub.get()
|
||||
|
||||
c1 = exists(path)
|
||||
try:
|
||||
_a = float(av)
|
||||
_b = float(rr)
|
||||
c2 = True
|
||||
except:
|
||||
c2 = False
|
||||
c2 = self.is_float(av, rr)
|
||||
c3 = rpm = 1
|
||||
c4 = sub_func in ['industrial', 'cobot']
|
||||
c5 = True if vel != trq else False
|
||||
@ -295,35 +377,32 @@ class App(customtkinter.CTk):
|
||||
dur = self.entry_dur.get()
|
||||
vel = self.option_vel.get()
|
||||
trq = self.option_trq.get()
|
||||
trqh = self.option_trqh.get()
|
||||
sub = self.menu_sub.get()
|
||||
rc1 = self.entry_rc_1.get()
|
||||
rc2 = self.entry_rc_2.get()
|
||||
rc3 = self.entry_rc_3.get()
|
||||
rc4 = self.entry_rc_4.get()
|
||||
rc5 = self.entry_rc_5.get()
|
||||
rc6 = self.entry_rc_6.get()
|
||||
|
||||
c1 = exists(path)
|
||||
c2 = sub in ['max', 'avg', 'cycle']
|
||||
c3 = self.is_float('optional', rc)
|
||||
_ = [rc1, rc2, rc3, rc4, rc5, rc6]
|
||||
c4 = self.is_float('required', *_)
|
||||
|
||||
rcs = rc.split()
|
||||
for _ in rcs:
|
||||
try:
|
||||
_t = float(_)
|
||||
except:
|
||||
c3 = False
|
||||
break
|
||||
else:
|
||||
c3 = True
|
||||
|
||||
c4 = c5 = True
|
||||
c5 = c6 = True
|
||||
if sub == 'cycle':
|
||||
try:
|
||||
_ = float(dur)
|
||||
c4 = True
|
||||
except:
|
||||
c4 = False
|
||||
c5 = True if vel != trq else False
|
||||
c6 = self.is_float('optional', dur)
|
||||
|
||||
if c1 and c2 and c3 and c4 and c5:
|
||||
if c1 and c2 and c3 and c4 and c5 and c6:
|
||||
rcs = []
|
||||
for x in rc.split():
|
||||
for x in _:
|
||||
rcs.append(float(x))
|
||||
dur = 0 if sub != 'cycle' else dur
|
||||
return 2, path, sub, rcs, int(vel), int(trq), float(dur)
|
||||
dur = 0 if sub != 'cycle' or dur == '' else dur
|
||||
return 2, path, sub, rcs, int(vel), int(trq), int(trqh), float(dur)
|
||||
else:
|
||||
return 0, 0
|
||||
# =======================================================
|
||||
@ -348,7 +427,7 @@ class App(customtkinter.CTk):
|
||||
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)
|
||||
elif flag == 2:
|
||||
# tkinter.messagebox.showinfo(title="TBD", message="功能待实现......")
|
||||
func_dict[flag](path=args[0], sub=args[1], rc=args[2], vel=args[3], trq=args[4], dur=args[5], w2t=self.write2textbox)
|
||||
func_dict[flag](path=args[0], sub=args[1], rcs=args[2], vel=args[3], trq=args[4], trqh=args[5], dur=args[6], w2t=self.write2textbox)
|
||||
elif flag == 3:
|
||||
func_dict[flag](path=args[0], w2t=self.write2textbox)
|
||||
else:
|
||||
@ -382,12 +461,8 @@ class App(customtkinter.CTk):
|
||||
def func_end_call_back(self):
|
||||
if tkinter.messagebox.askyesno(title="关闭程序", message="相关数据可能未保存,正在运行程序时有概率会损坏数据文件,确定要终止程序运行吗?"):
|
||||
self.destroy()
|
||||
else:
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
aio = App()
|
||||
aio.mainloop()
|
||||
|
188
aio/current.py
188
aio/current.py
@ -3,6 +3,37 @@ from os import scandir
|
||||
from os.path import exists
|
||||
from sys import argv
|
||||
from pandas import read_csv
|
||||
from re import match
|
||||
from threading import Thread
|
||||
from time import sleep
|
||||
|
||||
class GetThreadResult(Thread):
|
||||
def __init__(self, func, args=()):
|
||||
super(GetThreadResult, self).__init__()
|
||||
self.func = func
|
||||
self.args = args
|
||||
self.result = 0
|
||||
|
||||
def run(self):
|
||||
sleep(1)
|
||||
self.result = self.func(*self.args)
|
||||
|
||||
def get_result(self):
|
||||
Thread.join(self) # 等待线程执行完毕
|
||||
try:
|
||||
return self.result
|
||||
except Exception as Err:
|
||||
return None
|
||||
|
||||
|
||||
def w2t_local(msg, wait, w2t):
|
||||
while True:
|
||||
global stop
|
||||
if stop == 0 and wait != 0:
|
||||
sleep(1)
|
||||
w2t(msg, wait)
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
def traversal_files(path, w2t):
|
||||
@ -27,16 +58,18 @@ def traversal_files(path, w2t):
|
||||
def initialization(path, sub, w2t):
|
||||
_, data_files = traversal_files(path, w2t)
|
||||
count = 0
|
||||
|
||||
for data_file in data_files:
|
||||
filename = data_file.split('\\')[-1]
|
||||
if sub != 'cycle':
|
||||
if not (data_file.endswith('.data') or data_file.endswith('.csv')):
|
||||
msg = f"所有文件必须以 .data 结尾,请检查后重新运行。"
|
||||
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, 2)
|
||||
else:
|
||||
if data_file.endswith('.xlsx'):
|
||||
if filename.endswith('.xlsx'):
|
||||
count += 1
|
||||
elif not (data_file.endswith('.data') or data_file.endswith('.csv')):
|
||||
msg = f"所有文件必须以 .data 结尾,请检查后重新运行。"
|
||||
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, 3)
|
||||
|
||||
if sub == 'cycle' and count != 1:
|
||||
@ -45,7 +78,7 @@ def initialization(path, sub, w2t):
|
||||
return data_files
|
||||
|
||||
|
||||
def current_max(data_files, rc, trq, w2t):
|
||||
def current_max(data_files, rcs, trqh, w2t):
|
||||
current = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0}
|
||||
for data_file in data_files:
|
||||
if data_file.endswith('.data'):
|
||||
@ -54,9 +87,9 @@ def current_max(data_files, rc, trq, w2t):
|
||||
df = read_csv(data_file, sep=',', encoding='gbk', header=8)
|
||||
|
||||
axis = int(data_file.split('\\')[-1].split('_')[0].removeprefix('j'))
|
||||
rca = rc[axis-1]
|
||||
rca = rcs[axis-1]
|
||||
|
||||
col = df.columns.values[trq-1]
|
||||
col = df.columns.values[trqh-1]
|
||||
c_max = df[col].max()
|
||||
|
||||
scale = 1 if data_file.endswith('.csv') else 1000
|
||||
@ -68,7 +101,7 @@ def current_max(data_files, rc, trq, w2t):
|
||||
return current
|
||||
|
||||
|
||||
def current_avg(data_files, rc, trq, w2t):
|
||||
def current_avg(data_files, rcs, trqh, w2t):
|
||||
current = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0}
|
||||
for data_file in data_files:
|
||||
if data_file.endswith('.data'):
|
||||
@ -77,9 +110,9 @@ def current_avg(data_files, rc, trq, w2t):
|
||||
df = read_csv(data_file, sep=',', encoding='gbk', header=8)
|
||||
|
||||
axis = int(data_file.split('\\')[-1].split('_')[0].removeprefix('j'))
|
||||
rca = rc[axis-1]
|
||||
rca = rcs[axis-1]
|
||||
|
||||
col = df.columns.values[trq - 1]
|
||||
col = df.columns.values[trqh - 1]
|
||||
c_std = df[col].std()
|
||||
c_avg = df[col].mean()
|
||||
|
||||
@ -92,46 +125,153 @@ def current_avg(data_files, rc, trq, w2t):
|
||||
return current
|
||||
|
||||
|
||||
def current_cycle(dur, data_files, rc, vel, trq, w2t):
|
||||
def current_cycle(dur, data_files, rcs, vel, trq, trqh, w2t):
|
||||
result = None
|
||||
hold = []
|
||||
single = []
|
||||
for data_file in data_files:
|
||||
filename = data_file.split('\\')[-1]
|
||||
if data_file.endswith('.xlsx'):
|
||||
result = data_file
|
||||
elif (data_file.endswith('.csv') or data_file.endswith('.data')) and data_file.startswith('hold', 3, 10):
|
||||
elif match('j[1-7]_hold_.*\\.data', filename) or match('j[1-7]_hold_.*\\.csv', filename):
|
||||
hold.append(data_file)
|
||||
else:
|
||||
single.append(data_file)
|
||||
|
||||
w2t(f"正在打开文件 {result},需要 10s 左右", 1)
|
||||
|
||||
global stop
|
||||
stop = 0
|
||||
t_excel = GetThreadResult(load_workbook, args=(result, ))
|
||||
t_wait = Thread(target=w2t_local, args=('.', 1, w2t))
|
||||
t_excel.start()
|
||||
t_wait.start()
|
||||
t_excel.join()
|
||||
wb = t_excel.get_result()
|
||||
stop = 1
|
||||
sleep(1.1)
|
||||
w2t('')
|
||||
|
||||
if hold != []:
|
||||
avg = current_avg(hold, rc, trq, w2t)
|
||||
wb = load_workbook(result)
|
||||
for k, v in avg.items():
|
||||
avg = current_avg(hold, rcs, trqh, w2t)
|
||||
for axis, cur_value in avg.items():
|
||||
try:
|
||||
shtname = f"J{k}"
|
||||
wb[shtname]["J4"].value = v
|
||||
shtname = f"J{axis}"
|
||||
wb[shtname]["J4"].value = float(cur_value)
|
||||
except:
|
||||
pass
|
||||
|
||||
if dur == 0:
|
||||
p_single(wb, single, vel, trq, w2t)
|
||||
else:
|
||||
p_scenario()
|
||||
|
||||
w2t(f"正在保存文件 {result},需要 10s 左右", 1)
|
||||
stop = 0
|
||||
t_excel = Thread(target=wb.save, args=(result, ))
|
||||
t_wait = Thread(target=w2t_local, args=('.', 1, w2t))
|
||||
t_excel.start()
|
||||
t_wait.start()
|
||||
t_excel.join()
|
||||
stop = 1
|
||||
sleep(1.1)
|
||||
w2t('\n')
|
||||
w2t("----------------------------------------------------------")
|
||||
w2t("全部处理完毕")
|
||||
|
||||
|
||||
def p_single(wb, single, vel, trq, w2t):
|
||||
# 1. 先找到第一个速度为零的点,数据从后往前找,一开始就是零的情况不予考虑
|
||||
# 2. 记录第一个点的位置,继续向前查找第二个速度为零的点,同理,一开始为零的点不予考虑
|
||||
# 3. 记录第二个点的位置,并将其中的数据拷贝至对应位置
|
||||
for data_file in single:
|
||||
axis = int(data_file.split('\\')[-1].split('_')[0].removeprefix('j'))
|
||||
rcs = rc[axis-1]
|
||||
pass
|
||||
shtname = f"J{axis}"
|
||||
ws = wb[shtname]
|
||||
|
||||
if data_file.endswith('.data'):
|
||||
df = read_csv(data_file, sep='\t')
|
||||
elif data_file.endswith('.csv'):
|
||||
df = read_csv(data_file, sep=',', encoding='gbk', header=8)
|
||||
|
||||
# 过滤尾部无效数据
|
||||
_row_e = df.index[-1]
|
||||
_row_s = _row_e - 200
|
||||
while _row_e > 200:
|
||||
speed_avg = df.iloc[_row_s:_row_e, vel-1].abs().mean()
|
||||
if speed_avg > 2:
|
||||
_row_e -= 50
|
||||
_row_s -= 50
|
||||
continue
|
||||
else:
|
||||
break
|
||||
else:
|
||||
w2t("数据有误,需要检查,无法找到第一个有效起始点...", 0, 1)
|
||||
|
||||
# 找到第一个起始点 row_end,继续找到有数据的部分
|
||||
row_end = _row_e - 100
|
||||
_row_e -= 200
|
||||
_row_s -= 200
|
||||
while _row_e > 200:
|
||||
speed_avg = df.iloc[_row_s:_row_e, vel-1].abs().mean()
|
||||
if speed_avg < 2:
|
||||
_row_e -= 50
|
||||
_row_s -= 50
|
||||
continue
|
||||
else:
|
||||
break
|
||||
else:
|
||||
w2t("数据有误,需要检查,无法找到第二个有效起始点...", 0, 2)
|
||||
|
||||
# 目前已经有一点的速度值了,继续往前搜寻下一个速度为零的点
|
||||
_row_e -= 200
|
||||
_row_s -= 200
|
||||
while _row_e > 200:
|
||||
speed_avg = df.iloc[_row_s:_row_e, vel-1].abs().mean()
|
||||
if speed_avg > 2:
|
||||
_row_e -= 50
|
||||
_row_s -= 50
|
||||
continue
|
||||
else:
|
||||
break
|
||||
else:
|
||||
w2t("数据有误,需要检查,无法找到第三个有效起始点...", 0, 3)
|
||||
|
||||
row_start = _row_s + 180
|
||||
data = []
|
||||
for row in range(row_start, row_end):
|
||||
data.append(df.iloc[row, vel-1])
|
||||
data.append(df.iloc[row, trq-1])
|
||||
|
||||
i = 0
|
||||
for row in ws.iter_rows(min_row=2, min_col=2, max_row=15000, max_col=3):
|
||||
for cell in row:
|
||||
try:
|
||||
cell.value = data[i]
|
||||
i += 1
|
||||
except:
|
||||
cell.value = None
|
||||
|
||||
|
||||
def p_scenario():
|
||||
pass
|
||||
|
||||
|
||||
# =======================================
|
||||
|
||||
|
||||
def main(path, sub, rc, vel, trq, dur, w2t):
|
||||
def main(path, sub, rcs, vel, trq, trqh, dur, w2t):
|
||||
data_files = initialization(path, sub, w2t)
|
||||
if sub == 'max':
|
||||
current_max(data_files, rc, trq, w2t)
|
||||
current_max(data_files, rcs, trqh, w2t)
|
||||
elif sub == 'avg':
|
||||
current_avg(data_files, rc, trq, w2t)
|
||||
current_avg(data_files, rcs, trqh, w2t)
|
||||
elif sub == 'cycle':
|
||||
current_cycle(dur, data_files, rc, vel, trq, w2t)
|
||||
current_cycle(dur, data_files, rcs, vel, trq, trqh, w2t)
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
stop = 0
|
||||
main(*argv[1:])
|
||||
|
BIN
aio/layout.xlsx
BIN
aio/layout.xlsx
Binary file not shown.
Reference in New Issue
Block a user