[t_change_ui: aio.py/brake.py/current.py] 整体修改了操作界面,删除了大部分的配置输入框,改用 configs.xlsx 配置文件替代,并优化了max/avg功能中写入结果数据的方式
This commit is contained in:
@ -63,19 +63,18 @@ def initialization(path, sub, w2t):
|
||||
|
||||
for data_file in data_files:
|
||||
filename = data_file.split('\\')[-1]
|
||||
if sub != 'cycle':
|
||||
if data_file.endswith('configs.xlsx'):
|
||||
count += 1
|
||||
elif sub == 'cycle' and data_file.endswith('.xlsx'):
|
||||
count += 1
|
||||
else:
|
||||
if not (match('j[1-7].*\\.data', filename) or match('j[1-7].*\\.csv', filename)):
|
||||
print(f"不合规 {data_file}")
|
||||
msg = f"所有文件必须以 jx_ 开头,以 .data/csv 结尾(x取值1-7),请检查后重新运行。"
|
||||
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, 'red')
|
||||
|
||||
if sub == 'cycle' and count != 1:
|
||||
w2t("未找到电机电流数据处理excel表格,确认后重新运行!", 0, 5, 'red')
|
||||
if not ((sub == 'cycle' and count == 2) or (sub != 'cycle' and count == 1)):
|
||||
w2t("使用max/avg功能时,需要有配置文件表格;使用cycle功能时,需要有电机电流数据处理和配置文件两个表格,确认后重新运行!", 0, 5, 'red')
|
||||
|
||||
return data_files
|
||||
|
||||
@ -87,7 +86,10 @@ def current_max(data_files, rcs, trqh, w2t):
|
||||
df = read_csv(data_file, sep='\t')
|
||||
elif data_file.endswith('.csv'):
|
||||
df = read_csv(data_file, sep=',', encoding='gbk', header=8)
|
||||
else:
|
||||
continue
|
||||
|
||||
cols = len(df.columns)
|
||||
axis = int(data_file.split('\\')[-1].split('_')[0].removeprefix('j'))
|
||||
rca = rcs[axis-1]
|
||||
|
||||
@ -100,9 +102,9 @@ def current_max(data_files, rcs, trqh, w2t):
|
||||
w2t(f"{data_file}: {_:.4f}")
|
||||
|
||||
with open(data_file, 'a+') as f_data:
|
||||
csv_writer = writer(f_data)
|
||||
csv_writer.writerow([''] * 4)
|
||||
csv_writer.writerow([_])
|
||||
sep = '\t' if data_file.endswith('.data') else ','
|
||||
csv_writer = writer(f_data, delimiter=sep)
|
||||
csv_writer.writerow([''] * (cols-1) + [_])
|
||||
|
||||
for axis, cur in current.items():
|
||||
if not cur:
|
||||
@ -123,7 +125,10 @@ def current_avg(data_files, rcs, trqh, w2t):
|
||||
df = read_csv(data_file, sep='\t')
|
||||
elif data_file.endswith('.csv'):
|
||||
df = read_csv(data_file, sep=',', encoding='gbk', header=8)
|
||||
else:
|
||||
continue
|
||||
|
||||
cols = len(df.columns)
|
||||
axis = int(data_file.split('\\')[-1].split('_')[0].removeprefix('j'))
|
||||
rca = rcs[axis-1]
|
||||
|
||||
@ -137,9 +142,9 @@ def current_avg(data_files, rcs, trqh, w2t):
|
||||
w2t(f"{data_file}: {_:.4f}")
|
||||
|
||||
with open(data_file, 'a+') as f_data:
|
||||
csv_writer = writer(f_data)
|
||||
csv_writer.writerow([''] * 4)
|
||||
csv_writer.writerow([_])
|
||||
sep = '\t' if data_file.endswith('.data') else ','
|
||||
csv_writer = writer(f_data, delimiter=sep)
|
||||
csv_writer.writerow([''] * (cols-1) + [_])
|
||||
|
||||
for axis, cur in current.items():
|
||||
if not cur:
|
||||
@ -153,17 +158,17 @@ def current_avg(data_files, rcs, trqh, w2t):
|
||||
return current
|
||||
|
||||
|
||||
def current_cycle(dur, data_files, rcs, vel, trq, trqh, rpm, w2t):
|
||||
def current_cycle(dur, data_files, rcs, vel, trq, trqh, rpms, w2t):
|
||||
result = None
|
||||
hold = []
|
||||
single = []
|
||||
for data_file in data_files:
|
||||
filename = data_file.split('\\')[-1]
|
||||
if data_file.endswith('.xlsx'):
|
||||
if data_file.endswith('.xlsx') and not data_file.endswith('configs.xlsx'):
|
||||
result = data_file
|
||||
elif match('j[1-7]_hold_.*\\.data', filename) or match('j[1-7]_hold_.*\\.csv', filename):
|
||||
hold.append(data_file)
|
||||
else:
|
||||
elif match('j[1-7]_.*\\.data', filename) or match('j[1-7]_.*\\.csv', filename):
|
||||
single.append(data_file)
|
||||
|
||||
w2t(f"正在打开文件 {result},需要 10s 左右", 1, 0, 'orange')
|
||||
@ -189,9 +194,9 @@ def current_cycle(dur, data_files, rcs, vel, trq, trqh, rpm, w2t):
|
||||
pass
|
||||
|
||||
if dur == 0:
|
||||
p_single(wb, single, vel, trq, rpm, w2t)
|
||||
p_single(wb, single, vel, trq, rpms, w2t)
|
||||
else:
|
||||
p_scenario(wb, single, vel, trq, rpm, dur, w2t)
|
||||
p_scenario(wb, single, vel, trq, rpms, dur, w2t)
|
||||
|
||||
w2t(f"正在保存文件 {result},需要 10s 左右", 1, 0, 'orange')
|
||||
stop = 0
|
||||
@ -232,15 +237,15 @@ def find_point(data_file, pos, flag, df, _row_s, _row_e, w2t, exitcode, threshol
|
||||
w2t(f"[{pos}] {data_file}数据有误,需要检查,无法找到有效起始点或结束点...", 0, exitcode, 'red')
|
||||
|
||||
|
||||
def p_single(wb, single, vel, trq, rpm, w2t):
|
||||
def p_single(wb, single, vel, trq, rpms, w2t):
|
||||
# 1. 先找到第一个速度为零的点,数据从后往前找,一开始就是零的情况不予考虑
|
||||
# 2. 记录第一个点的位置,继续向前查找第二个速度为零的点,同理,一开始为零的点不予考虑
|
||||
# 3. 记录第二个点的位置,并将其中的数据拷贝至对应位置
|
||||
for data_file in single:
|
||||
rpm = 1 if rpm == 0 else rpm
|
||||
scale = 1000 if data_file.endswith('.csv') else 1
|
||||
axis = int(data_file.split('\\')[-1].split('_')[0].removeprefix('j'))
|
||||
shtname = f"J{axis}"
|
||||
rpm = rpms[axis-1] if data_file.endswith('.csv') else 1
|
||||
scale = 1000 if data_file.endswith('.csv') else 1
|
||||
ws = wb[shtname]
|
||||
addition = 1
|
||||
set_option("display.precision", 2)
|
||||
@ -313,13 +318,13 @@ def p_single(wb, single, vel, trq, rpm, w2t):
|
||||
cell.value = None
|
||||
|
||||
|
||||
def p_scenario(wb, single, vel, trq, rpm, dur, w2t):
|
||||
def p_scenario(wb, single, vel, trq, rpms, dur, w2t):
|
||||
for data_file in single:
|
||||
cycle = 0.001
|
||||
rpm = 1 if rpm == 0 else rpm
|
||||
scale = 1000 if data_file.endswith('.csv') else 1
|
||||
axis = int(data_file.split('\\')[-1].split('_')[0].removeprefix('j'))
|
||||
shtname = f"J{axis}"
|
||||
rpm = rpms[axis-1] if data_file.endswith('.csv') else 1
|
||||
scale = 1000 if data_file.endswith('.csv') else 1
|
||||
ws = wb[shtname]
|
||||
addition = 1
|
||||
set_option("display.precision", 2)
|
||||
@ -365,17 +370,34 @@ def p_scenario(wb, single, vel, trq, rpm, dur, w2t):
|
||||
cell.value = None
|
||||
|
||||
|
||||
# =======================================
|
||||
def get_configs(configfile, w2t):
|
||||
_wb = load_workbook(configfile, read_only=True)
|
||||
_ws = _wb['Target']
|
||||
rcs = []
|
||||
rpms = []
|
||||
for i in range(2, 9):
|
||||
try:
|
||||
rpms.append(float(_ws.cell(row=4, column=i).value))
|
||||
except:
|
||||
rpms.append(0.0)
|
||||
|
||||
try:
|
||||
rcs.append(float(_ws.cell(row=6, column=i).value))
|
||||
except:
|
||||
rcs.append(0.0)
|
||||
|
||||
return rpms, rcs
|
||||
|
||||
|
||||
def main(path, sub, rcs, vel, trq, trqh, dur, rpm, w2t):
|
||||
def main(path, sub, dur, vel, trq, trqh, w2t):
|
||||
data_files = initialization(path, sub, w2t)
|
||||
rpms, rcs = get_configs(path + '\\configs.xlsx', w2t)
|
||||
if sub == 'max':
|
||||
current_max(data_files, rcs, trqh, w2t)
|
||||
elif sub == 'avg':
|
||||
current_avg(data_files, rcs, trqh, w2t)
|
||||
elif sub == 'cycle':
|
||||
current_cycle(dur, data_files, rcs, vel, trq, trqh, rpm, w2t)
|
||||
current_cycle(dur, data_files, rcs, vel, trq, trqh, rpms, w2t)
|
||||
else:
|
||||
pass
|
||||
|
||||
|
Reference in New Issue
Block a user