71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
import openpyxl
|
|
from os import scandir
|
|
from os.path import exists
|
|
from sys import argv
|
|
import pandas
|
|
|
|
|
|
def traversal_files(path, w2t):
|
|
# 功能:以列表的形式分别返回指定路径下的文件和文件夹,不包含子目录
|
|
# 参数:路径
|
|
# 返回值:路径下的文件夹列表 路径下的文件列表
|
|
if not exists(path):
|
|
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
|
w2t(msg, 0, 1)
|
|
else:
|
|
dirs = []
|
|
files = []
|
|
for item in scandir(path):
|
|
if item.is_dir():
|
|
dirs.append(item.path)
|
|
elif item.is_file():
|
|
files.append(item.path)
|
|
|
|
return dirs, files
|
|
|
|
|
|
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 结尾,请检查后重新运行。"
|
|
w2t(msg, 0, 2)
|
|
|
|
return data_files
|
|
|
|
|
|
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[trq-1]
|
|
c_max = df[col].max()
|
|
w2t(f"{data_file}: {c_max/1000*rc:.4f}")
|
|
|
|
w2t("【MAX】数据处理完毕......")
|
|
|
|
|
|
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[trq-1]
|
|
c_std = df[col].std()
|
|
c_avg = df[col].mean()
|
|
|
|
w2t(f"{data_file}: {(abs(c_avg)+c_std)/1000*rc:.4f}")
|
|
|
|
w2t("【AVG】数据处理完毕......")
|
|
|
|
|
|
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(path=argv[1], sub=argv[2], rc=argv[3], vel=argv[4], trq=argv[5], w2t=argv[6])
|