v0.0.7(2024/05/27)
1. 该版本制动数据处理变动较大,重写了find_row_start & copy_data_to_result,删除了delete_excel_files 2. 主要是修改了数据处理的方式,直接使用pandas进行数据处理,跳过了openpyxl来回变换,节省了大量的IO以及时间
This commit is contained in:
parent
203138947b
commit
1cee89cd0a
@ -43,24 +43,24 @@ def get_threshold_step(excel_file, AXIS):
|
|||||||
return threshold, step
|
return threshold, step
|
||||||
|
|
||||||
|
|
||||||
def find_row_start(excel_file, wb_data, ws_data, conditions, AV, RR, AXIS):
|
def find_row_start(data_file, df, conditions, AV, RR, AXIS):
|
||||||
# 功能:查找数据文件中有效数据的行号,也即最后一个速度下降的点位
|
# 功能:查找数据文件中有效数据的行号,也即最后一个速度下降的点位
|
||||||
# 参数:如上
|
# 参数:如上
|
||||||
# 返回值:速度下降点位,最后的数据点位
|
# 返回值:速度下降点位,最后的数据点位
|
||||||
ratio = float(conditions[1].removeprefix('speed'))/100
|
ratio = float(conditions[1].removeprefix('speed'))/100
|
||||||
speed_max = AV * ratio * RR / 6
|
speed_max = AV * ratio * RR / 6
|
||||||
row_max = row_start = ws_data.max_row
|
row_max = row_start = df.index[-1]
|
||||||
|
|
||||||
threshold, step = get_threshold_step(excel_file, AXIS)
|
threshold, step = get_threshold_step(data_file, AXIS)
|
||||||
while row_start > step+1:
|
while row_start > step+1:
|
||||||
speed = ws_data[f"A{row_start}"].value
|
speed = df.iloc[row_start, 0]
|
||||||
if speed is None or int(speed) < 1:
|
if int(speed) < 1:
|
||||||
row_start -= 50
|
row_start -= 50
|
||||||
continue
|
continue
|
||||||
|
|
||||||
_ = []
|
_ = []
|
||||||
for i in range(row_start, row_start-step+1, -1):
|
for i in range(row_start, row_start-step+1, -1):
|
||||||
_.append(ws_data[f"A{i}"].value)
|
_.append(df.iloc[i, 0])
|
||||||
speed_avg = abs(sum(_))/len(_)
|
speed_avg = abs(sum(_))/len(_)
|
||||||
|
|
||||||
if abs(speed_avg-speed_max) < threshold:
|
if abs(speed_avg-speed_max) < threshold:
|
||||||
@ -69,9 +69,7 @@ def find_row_start(excel_file, wb_data, ws_data, conditions, AV, RR, AXIS):
|
|||||||
else:
|
else:
|
||||||
row_start -= step
|
row_start -= step
|
||||||
else:
|
else:
|
||||||
wb_data.close()
|
msg = f"可能是{data_file},这个文件数据采集有问题,比如采集的时机不对,也有可能是程序步长设定问题,请检查......"
|
||||||
os.remove(excel_file)
|
|
||||||
msg = f"可能是{excel_file.replace('xlsx', 'data')},这个文件数据采集有问题,比如采集的时机不对,也有可能是程序步长设定问题,请检查......"
|
|
||||||
warn_pause_exit(msg, 1, 9)
|
warn_pause_exit(msg, 1, 9)
|
||||||
|
|
||||||
return row_max, row_start
|
return row_max, row_start
|
||||||
@ -89,7 +87,7 @@ def find_result_sheet_name(conditions, count):
|
|||||||
return result_sheet_name
|
return result_sheet_name
|
||||||
|
|
||||||
|
|
||||||
def copy_data_to_result(ws_data, ws_result, row_max, row_start):
|
def copy_data_to_result(df, ws_result, row_max, row_start):
|
||||||
# 功能:将数据文件中有效数据拷贝至结果文件对应的 sheet
|
# 功能:将数据文件中有效数据拷贝至结果文件对应的 sheet
|
||||||
# 参数:如上
|
# 参数:如上
|
||||||
# 返回值:-
|
# 返回值:-
|
||||||
@ -102,9 +100,10 @@ def copy_data_to_result(ws_data, ws_result, row_max, row_start):
|
|||||||
row_max = row_start + 399 if row_max-row_start > 400 else row_max
|
row_max = row_start + 399 if row_max-row_start > 400 else row_max
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for row in ws_data.iter_rows(min_row=row_start, min_col=1, max_row=row_max, max_col=2):
|
for i in range(row_start, row_max+1):
|
||||||
for cell in row:
|
data.append(df.iloc[i, 0])
|
||||||
data.append(cell.value)
|
data.append(df.iloc[i, 1])
|
||||||
|
|
||||||
i = 0
|
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 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:
|
for cell in row:
|
||||||
@ -116,26 +115,17 @@ def single_file_process(data_file, wb_result, count, AV, RR, RC, AXIS):
|
|||||||
# 功能:完成单个数据文件的处理
|
# 功能:完成单个数据文件的处理
|
||||||
# 参数:如上
|
# 参数:如上
|
||||||
# 返回值:-
|
# 返回值:-
|
||||||
excel_file = data_file.replace('.data', '.xlsx')
|
|
||||||
sheet_name = data_file.split('\\')[-1].removesuffix('.data')
|
|
||||||
df = pandas.read_csv(data_file, sep='\t')
|
df = pandas.read_csv(data_file, sep='\t')
|
||||||
df.to_excel(excel_file, sheet_name=sheet_name, index=False)
|
|
||||||
|
|
||||||
conditions = sorted(data_file.split('\\')[-2].split('_')[1:])
|
conditions = sorted(data_file.split('\\')[-2].split('_')[1:])
|
||||||
result_sheet_name = find_result_sheet_name(conditions, count)
|
result_sheet_name = find_result_sheet_name(conditions, count)
|
||||||
ws_result = wb_result[result_sheet_name]
|
ws_result = wb_result[result_sheet_name]
|
||||||
|
|
||||||
wb_data = openpyxl.load_workbook(excel_file)
|
row_max, row_start = find_row_start(data_file, df, conditions, AV, RR, AXIS)
|
||||||
ws_data = wb_data[sheet_name]
|
|
||||||
row_max, row_start = find_row_start(excel_file, wb_data, ws_data, conditions, AV, RR, AXIS)
|
|
||||||
|
|
||||||
copy_data_to_result(ws_data, ws_result, row_max, row_start)
|
copy_data_to_result(df, ws_result, row_max, row_start)
|
||||||
ws_result["C2"] = int(2)
|
ws_result["C2"] = int(2)
|
||||||
ws_result["G2"] = int(10+4)
|
ws_result["G2"] = int(10+4)
|
||||||
|
|
||||||
wb_data.save(excel_file)
|
|
||||||
wb_data.close()
|
|
||||||
|
|
||||||
|
|
||||||
def now_doing_msg(docs, flag):
|
def now_doing_msg(docs, flag):
|
||||||
# 功能:输出正在处理的文件或目录
|
# 功能:输出正在处理的文件或目录
|
||||||
@ -249,17 +239,6 @@ def check_files(raw_data_dirs, result_files):
|
|||||||
print("数据目录合规性检查结束,未发现问题......")
|
print("数据目录合规性检查结束,未发现问题......")
|
||||||
|
|
||||||
|
|
||||||
def delete_excel_files(raw_data_dirs):
|
|
||||||
# 功能:删除数据文件夹里的 .xlsx 文件
|
|
||||||
# 参数:数据文件夹
|
|
||||||
# 返回值:-
|
|
||||||
for raw_data_dir in raw_data_dirs:
|
|
||||||
_, raw_data_files = traversal_files(raw_data_dir)
|
|
||||||
for raw_data_file in raw_data_files:
|
|
||||||
if raw_data_file.endswith('.xlsx'):
|
|
||||||
os.remove(raw_data_file)
|
|
||||||
|
|
||||||
|
|
||||||
def initialization():
|
def initialization():
|
||||||
# 功能:初始化,记录开始时间,读取预定义参数
|
# 功能:初始化,记录开始时间,读取预定义参数
|
||||||
# 参数:-
|
# 参数:-
|
||||||
@ -281,7 +260,6 @@ def initialization():
|
|||||||
wb_conf.close()
|
wb_conf.close()
|
||||||
|
|
||||||
raw_data_dirs, result_files = traversal_files(DATA_DIR)
|
raw_data_dirs, result_files = traversal_files(DATA_DIR)
|
||||||
delete_excel_files(raw_data_dirs)
|
|
||||||
check_files(raw_data_dirs, result_files)
|
check_files(raw_data_dirs, result_files)
|
||||||
|
|
||||||
return raw_data_dirs, result_files, time_start, AV, RR, RC, AXIS
|
return raw_data_dirs, result_files, time_start, AV, RR, RC, AXIS
|
||||||
@ -309,10 +287,8 @@ def execution(args):
|
|||||||
# [t.join() for t in threads]
|
# [t.join() for t in threads]
|
||||||
print("----------------------------------------------------------")
|
print("----------------------------------------------------------")
|
||||||
print("全部处理完毕")
|
print("全部处理完毕")
|
||||||
delete_excel_files(raw_data_dirs)
|
|
||||||
except Exception as Err:
|
except Exception as Err:
|
||||||
print("程序运行错误,请检查配置文件是否准确设定,以及数据文件组织是否正确,也有可能是结果文件损坏,尝试重新复制一份,再运行!")
|
print("程序运行错误,请检查配置文件是否准确设定,以及数据文件组织是否正确,也有可能是结果文件损坏,尝试重新复制一份,再运行!")
|
||||||
delete_excel_files(raw_data_dirs)
|
|
||||||
|
|
||||||
time_end = time.time()
|
time_end = time.time()
|
||||||
time_total = time_end - time_start
|
time_total = time_end - time_start
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
注意事项:
|
注意事项:
|
||||||
1. 数据文件存储存储规则
|
1. 数据文件存储存储规则
|
||||||
所谓数据文件,就是我们拍急停的时候,采集到的 .data 文件,正方向拍三次急停,会采集到三个 .data 文件,存储在同一个文件夹内,即每组(三个 .data 文件)文件必须存储在同一个文件夹内,数据文件的命名无要求,
|
所谓数据文件,就是我们拍急停的时候,采集到的 .data 文件,正方向拍三次急停,会采集到三个 .data 文件,存储在同一个文件夹内,即每组(三个 .data 文件)文件必须存储在同一个文件夹内,数据文件的命名无要求,
|
||||||
|
|
||||||
2. 文件夹命名规则
|
2. 文件夹命名规则
|
||||||
虽然对采集到的 .data 文件没有命名要求,但是对于文件夹的命名是有要求的,必须是如下格式:
|
虽然对采集到的 .data 文件没有命名要求,但是对于文件夹的命名是有要求的,必须是如下格式:
|
||||||
loadXX_speedXX_reachXX 或者 loadXX_reachXX_speedXX
|
loadXX_speedXX_reachXX 或者 loadXX_reachXX_speedXX
|
||||||
@ -26,9 +26,9 @@
|
|||||||
load33_自研_制动性能测试.xlsx
|
load33_自研_制动性能测试.xlsx
|
||||||
load66_自研_制动性能测试.xlsx
|
load66_自研_制动性能测试.xlsx
|
||||||
load100_自研_制动性能测试.xlsx
|
load100_自研_制动性能测试.xlsx
|
||||||
|
|
||||||
!!结果文件可以是没有数据的,也可以是之前有数据的,只要保证第 6 点中的那几个数据准确即可
|
!!结果文件可以是没有数据的,也可以是之前有数据的,只要保证第 6 点中的那几个数据准确即可
|
||||||
|
|
||||||
4. 数据存储的组织结
|
4. 数据存储的组织结
|
||||||
..../j1/load100_speed33_reach100
|
..../j1/load100_speed33_reach100
|
||||||
..../j1/load100_speed66_reach100
|
..../j1/load100_speed66_reach100
|
||||||
@ -37,28 +37,28 @@
|
|||||||
..../j1/load100_speed33_reach100/2024_05_16_09_18_52.data
|
..../j1/load100_speed33_reach100/2024_05_16_09_18_52.data
|
||||||
..../j1/load100_speed33_reach100/2024_05_16_09_19_52.data
|
..../j1/load100_speed33_reach100/2024_05_16_09_19_52.data
|
||||||
..../j1/load100_speed33_reach100/2024_05_16_09_20_52.data
|
..../j1/load100_speed33_reach100/2024_05_16_09_20_52.data
|
||||||
|
|
||||||
..../j1/load33_自研_制动性能测试.xlsx
|
..../j1/load33_自研_制动性能测试.xlsx
|
||||||
..../j1/load66_自研_制动性能测试.xlsx
|
..../j1/load66_自研_制动性能测试.xlsx
|
||||||
..../j1/load100_自研_制动性能测试.xlsx
|
..../j1/load100_自研_制动性能测试.xlsx
|
||||||
|
|
||||||
5. 文件的打开与关闭
|
5. 文件的打开与关闭
|
||||||
a. 在执行程序之前,需要关闭所有相关 excle 文件
|
a. 在执行程序之前,需要关闭所有相关 excle 文件
|
||||||
b. 在执行程序之中,不允许打开相关 excle 文件
|
b. 在执行程序之中,不允许打开相关 excle 文件
|
||||||
c. 在执行程序之后,需要逐个打开结果文件,并保存一次
|
c. 在执行程序之后,需要逐个打开结果文件,并保存一次
|
||||||
|
|
||||||
6. 参数一致性检查
|
6. 参数一致性检查
|
||||||
执行程序前,需要确定 configs.xlsx 中设定的减速比/最大角速度/额定电流的值是正确的
|
执行程序前,需要确定 configs.xlsx 中设定的减速比/最大角速度/额定电流的值是正确的
|
||||||
|
|
||||||
7. 数据准确性检查
|
7. 数据准确性检查
|
||||||
执行完程序之后,需要对结果文件的数据准确性做核对,通过我自己的数据观察,误差基本在10ms以内,也即10个数据点,误差较大的情况可自行调整
|
执行完程序之后,需要对结果文件的数据准确性做核对,通过我自己的数据观察,误差基本在10ms以内,也即10个数据点,误差较大的情况可自行调整
|
||||||
|
|
||||||
8. .data 数据顺序
|
8. .data 数据顺序
|
||||||
.data 文件的第一列和第二列必须分别是速度和电流
|
.data 文件的第一列和第二列必须分别是速度和电流
|
||||||
|
|
||||||
9. 其他
|
9. 其他
|
||||||
程序运行主要的耗时集中在打开,保存和关闭结果文件,第一次打开的时候会比较慢,是因为 excel 在做首次公式的计算,保存关闭之后,再打开会比较快一些,另外,如果在运行出错并重复运行程序的时候无响应,或者出现异常,请打开任务管理器,关闭一切和excel相关的进程,重新运行即可
|
程序运行主要的耗时集中在打开,保存和关闭结果文件,第一次打开的时候会比较慢,是因为 excel 在做首次公式的计算,保存关闭之后,再打开会比较快一些,另外,如果在运行出错并重复运行程序的时候无响应,或者出现异常,请打开任务管理器,关闭一切和excel相关的进程,重新运行即可
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RELEASE CHANGES
|
RELEASE CHANGES
|
||||||
@ -105,4 +105,9 @@ v0.0.5(2024/05/23)
|
|||||||
|
|
||||||
v0.0.6(2024/05/23)
|
v0.0.6(2024/05/23)
|
||||||
1. 为了调整多功能框架,aio.py文件将会作为入口程序存在,不实现具体功能,功能的实现将由具体的功能脚本实现,aio.py只负责条件调用
|
1. 为了调整多功能框架,aio.py文件将会作为入口程序存在,不实现具体功能,功能的实现将由具体的功能脚本实现,aio.py只负责条件调用
|
||||||
2. 新增了自动化处理电流数据(电机/过载)的功能
|
2. 新增了自动化处理电流数据(电机/过载)的功能
|
||||||
|
|
||||||
|
v0.0.7(2024/05/27)
|
||||||
|
1. 该版本制动数据处理变动较大,重写了find_row_start & copy_data_to_result,删除了delete_excel_files
|
||||||
|
2. 主要是修改了数据处理的方式,直接使用pandas进行数据处理,跳过了openpyxl来回变换,节省了大量的IO以及时间
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user