diff --git a/aio/aio.py b/aio/aio.py index 7efe456..533b3a1 100644 --- a/aio/aio.py +++ b/aio/aio.py @@ -271,8 +271,11 @@ class App(customtkinter.CTk): trq = self.option_trq.get() sub_func = self.menu_sub.get() c1 = exists(path) - c2 = sub_func in ['max', 'avg'] - c3 = True if vel != trq else False + c2 = sub_func in ['max', 'avg', 'cycle'] + if sub_func == 'cycle': + c3 = True if vel != trq else False + else: + c3 = 1 try: _ = float(rc) c4 = True @@ -280,7 +283,7 @@ class App(customtkinter.CTk): c4 = False if c1 and c2 and c3 and c4: - return 2, path, float(rc), int(vel), int(trq), sub_func + return 2, path, sub_func, float(rc), int(vel), int(trq) else: return 0, 0 elif func_name == 'iso': @@ -304,8 +307,8 @@ class App(customtkinter.CTk): 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) elif flag == 2: - tkinter.messagebox.showinfo(title="TBD", message="功能待实现......") - # func_dict[flag](path=args[0], rc=args[1], sub_func=args[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], w2t=self.write2textbox) elif flag == 3: func_dict[flag](path=args[0], w2t=self.write2textbox) else: diff --git a/aio/current.py b/aio/current.py index 511f354..ac5580a 100644 --- a/aio/current.py +++ b/aio/current.py @@ -1,30 +1,21 @@ import openpyxl -import os -import sys +from os import scandir +from os.path import exists +from sys import argv import pandas -def warn_pause_exit(msg, pause_num, exit_num): - # 功能:打印告警信息,并推出程序 - # 参数:告警信息,暂停的次数,退出的值 - # 返回值:- - print(msg + '\n') - for i in range(pause_num): - _ = input("Press ENTER to continue......\n") - sys.exit(exit_num) - - -def traversal_files(path): +def traversal_files(path, w2t): # 功能:以列表的形式分别返回指定路径下的文件和文件夹,不包含子目录 # 参数:路径 # 返回值:路径下的文件夹列表 路径下的文件列表 - if not os.path.exists(path): + if not exists(path): msg = f'数据文件夹{path}不存在,请确认后重试......' - warn_pause_exit(msg, 1, 11) + w2t(msg, 0, 1) else: dirs = [] files = [] - for item in os.scandir(path): + for item in scandir(path): if item.is_dir(): dirs.append(item.path) elif item.is_file(): @@ -33,71 +24,47 @@ def traversal_files(path): return dirs, files -def initialization(): - try: - # read init configurations from config file - wb_conf = openpyxl.load_workbook('./configs.xlsx', read_only=True) - ws_conf = wb_conf['current'] - except Exception as Err: - msg = "无法在当前路径下找到或打开【configs.xlsx】文件,请确认!" - warn_pause_exit(msg, 1, 2) - - FUNC = ws_conf.cell(row=2, column=2).value - DATA_DIR = ws_conf.cell(row=3, column=2).value - AXIS = int(ws_conf.cell(row=4, column=2).value) - RC = ws_conf.cell(row=5, column=2).value.split(',') - COLUMN = int(ws_conf.cell(row=6, column=2).value) - wb_conf.close() - - _, data_files = traversal_files(DATA_DIR) +def initialization(path, w2t): + _, data_files = traversal_files(path, w2t) for data_file in data_files: if not data_file.endswith('.data'): msg = f"所有文件必须以 .data 结尾,请检查后重新运行。" - warn_pause_exit(msg, 1, 1) + w2t(msg, 0, 2) - return data_files, FUNC, RC, COLUMN, AXIS + return data_files -def current_max(*args): - data_files, FUNC, RC, COLUMN, AXIS = args +def current_max(data_files, rc, trq, w2t): for data_file in data_files: df = pandas.read_csv(data_file, sep='\t') - col = df.columns.values[COLUMN-1] + col = df.columns.values[trq-1] c_max = df[col].max() - print(f"{data_file}: {c_max/1000*RC[AXIS-1]:.3f}") + w2t(f"{data_file}: {c_max/1000*rc:.4f}") - msg = f"数据处理完毕......" - warn_pause_exit(msg, 1, 0) + w2t("【MAX】数据处理完毕......") -def current_avg(*args): - data_files, FUNC, RC, COLUMN, AXIS = args +def current_avg(data_files, rc, trq, w2t): for data_file in data_files: df = pandas.read_csv(data_file, sep='\t') - col = df.columns.values[COLUMN-1] + col = df.columns.values[trq-1] c_std = df[col].std() c_avg = df[col].mean() - axis = int(data_file.split('\\')[-1].split('_')[0].replace('j', '')) - print(f"{data_file}: {(abs(c_avg)+c_std)/1000*float(RC[axis-1]):.3f}") + w2t(f"{data_file}: {(abs(c_avg)+c_std)/1000*rc:.4f}") - msg = f"数据处理完毕......" - warn_pause_exit(msg, 1, 0) + w2t("【AVG】数据处理完毕......") -def full_cycle(*args): - pass - - -def main(): - args = initialization() - if args[1] == 'max': - current_max(*args) - elif args[1] == 'avg': - current_avg(*args) - elif args[1] == 'cycle': - full_cycle(*args) +def main(path, sub, rc, vel, trq, w2t): + data_files = initialization(path, w2t) + if sub == 'max': + current_max(data_files, rc, trq, w2t) + elif sub == 'avg': + current_avg(data_files, rc, trq, w2t) + else: + pass if __name__ == '__main__': - main() + main(path=argv[1], sub=argv[2], rc=argv[3], vel=argv[4], trq=argv[5], w2t=argv[6])