[modify] finish current related functions
This commit is contained in:
parent
1f00d22bce
commit
afb862201a
13
aio/aio.py
13
aio/aio.py
@ -271,8 +271,11 @@ class App(customtkinter.CTk):
|
|||||||
trq = self.option_trq.get()
|
trq = self.option_trq.get()
|
||||||
sub_func = self.menu_sub.get()
|
sub_func = self.menu_sub.get()
|
||||||
c1 = exists(path)
|
c1 = exists(path)
|
||||||
c2 = sub_func in ['max', 'avg']
|
c2 = sub_func in ['max', 'avg', 'cycle']
|
||||||
c3 = True if vel != trq else False
|
if sub_func == 'cycle':
|
||||||
|
c3 = True if vel != trq else False
|
||||||
|
else:
|
||||||
|
c3 = 1
|
||||||
try:
|
try:
|
||||||
_ = float(rc)
|
_ = float(rc)
|
||||||
c4 = True
|
c4 = True
|
||||||
@ -280,7 +283,7 @@ class App(customtkinter.CTk):
|
|||||||
c4 = False
|
c4 = False
|
||||||
|
|
||||||
if c1 and c2 and c3 and c4:
|
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:
|
else:
|
||||||
return 0, 0
|
return 0, 0
|
||||||
elif func_name == 'iso':
|
elif func_name == 'iso':
|
||||||
@ -304,8 +307,8 @@ class App(customtkinter.CTk):
|
|||||||
if flag == 1:
|
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], rpm=args[3], axis=args[4], vel=args[5], trq=args[6], w2t=self.write2textbox)
|
||||||
elif flag == 2:
|
elif flag == 2:
|
||||||
tkinter.messagebox.showinfo(title="TBD", message="功能待实现......")
|
# tkinter.messagebox.showinfo(title="TBD", message="功能待实现......")
|
||||||
# func_dict[flag](path=args[0], rc=args[1], sub_func=args[2])
|
func_dict[flag](path=args[0], sub=args[1], rc=args[2], vel=args[3], trq=args[4], w2t=self.write2textbox)
|
||||||
elif flag == 3:
|
elif flag == 3:
|
||||||
func_dict[flag](path=args[0], w2t=self.write2textbox)
|
func_dict[flag](path=args[0], w2t=self.write2textbox)
|
||||||
else:
|
else:
|
||||||
|
@ -1,30 +1,21 @@
|
|||||||
import openpyxl
|
import openpyxl
|
||||||
import os
|
from os import scandir
|
||||||
import sys
|
from os.path import exists
|
||||||
|
from sys import argv
|
||||||
import pandas
|
import pandas
|
||||||
|
|
||||||
|
|
||||||
def warn_pause_exit(msg, pause_num, exit_num):
|
def traversal_files(path, w2t):
|
||||||
# 功能:打印告警信息,并推出程序
|
|
||||||
# 参数:告警信息,暂停的次数,退出的值
|
|
||||||
# 返回值:-
|
|
||||||
print(msg + '\n')
|
|
||||||
for i in range(pause_num):
|
|
||||||
_ = input("Press ENTER to continue......\n")
|
|
||||||
sys.exit(exit_num)
|
|
||||||
|
|
||||||
|
|
||||||
def traversal_files(path):
|
|
||||||
# 功能:以列表的形式分别返回指定路径下的文件和文件夹,不包含子目录
|
# 功能:以列表的形式分别返回指定路径下的文件和文件夹,不包含子目录
|
||||||
# 参数:路径
|
# 参数:路径
|
||||||
# 返回值:路径下的文件夹列表 路径下的文件列表
|
# 返回值:路径下的文件夹列表 路径下的文件列表
|
||||||
if not os.path.exists(path):
|
if not exists(path):
|
||||||
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
||||||
warn_pause_exit(msg, 1, 11)
|
w2t(msg, 0, 1)
|
||||||
else:
|
else:
|
||||||
dirs = []
|
dirs = []
|
||||||
files = []
|
files = []
|
||||||
for item in os.scandir(path):
|
for item in scandir(path):
|
||||||
if item.is_dir():
|
if item.is_dir():
|
||||||
dirs.append(item.path)
|
dirs.append(item.path)
|
||||||
elif item.is_file():
|
elif item.is_file():
|
||||||
@ -33,71 +24,47 @@ def traversal_files(path):
|
|||||||
return dirs, files
|
return dirs, files
|
||||||
|
|
||||||
|
|
||||||
def initialization():
|
def initialization(path, w2t):
|
||||||
try:
|
_, data_files = traversal_files(path, w2t)
|
||||||
# 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)
|
|
||||||
for data_file in data_files:
|
for data_file in data_files:
|
||||||
if not data_file.endswith('.data'):
|
if not data_file.endswith('.data'):
|
||||||
msg = f"所有文件必须以 .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):
|
def current_max(data_files, rc, trq, w2t):
|
||||||
data_files, FUNC, RC, COLUMN, AXIS = args
|
|
||||||
for data_file in data_files:
|
for data_file in data_files:
|
||||||
df = pandas.read_csv(data_file, sep='\t')
|
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()
|
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"数据处理完毕......"
|
w2t("【MAX】数据处理完毕......")
|
||||||
warn_pause_exit(msg, 1, 0)
|
|
||||||
|
|
||||||
|
|
||||||
def current_avg(*args):
|
def current_avg(data_files, rc, trq, w2t):
|
||||||
data_files, FUNC, RC, COLUMN, AXIS = args
|
|
||||||
for data_file in data_files:
|
for data_file in data_files:
|
||||||
df = pandas.read_csv(data_file, sep='\t')
|
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_std = df[col].std()
|
||||||
c_avg = df[col].mean()
|
c_avg = df[col].mean()
|
||||||
|
|
||||||
axis = int(data_file.split('\\')[-1].split('_')[0].replace('j', ''))
|
w2t(f"{data_file}: {(abs(c_avg)+c_std)/1000*rc:.4f}")
|
||||||
print(f"{data_file}: {(abs(c_avg)+c_std)/1000*float(RC[axis-1]):.3f}")
|
|
||||||
|
|
||||||
msg = f"数据处理完毕......"
|
w2t("【AVG】数据处理完毕......")
|
||||||
warn_pause_exit(msg, 1, 0)
|
|
||||||
|
|
||||||
|
|
||||||
def full_cycle(*args):
|
def main(path, sub, rc, vel, trq, w2t):
|
||||||
pass
|
data_files = initialization(path, w2t)
|
||||||
|
if sub == 'max':
|
||||||
|
current_max(data_files, rc, trq, w2t)
|
||||||
def main():
|
elif sub == 'avg':
|
||||||
args = initialization()
|
current_avg(data_files, rc, trq, w2t)
|
||||||
if args[1] == 'max':
|
else:
|
||||||
current_max(*args)
|
pass
|
||||||
elif args[1] == 'avg':
|
|
||||||
current_avg(*args)
|
|
||||||
elif args[1] == 'cycle':
|
|
||||||
full_cycle(*args)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main(path=argv[1], sub=argv[2], rc=argv[3], vel=argv[4], trq=argv[5], w2t=argv[6])
|
||||||
|
Reference in New Issue
Block a user