界面优化,监控逻辑优化
This commit is contained in:
@ -9,27 +9,19 @@ from codes.common import clibs
|
||||
|
||||
|
||||
class BrakeDataProcess(QThread):
|
||||
output = Signal(str, str)
|
||||
|
||||
def __init__(self, dir_path, /):
|
||||
super().__init__()
|
||||
self.dir_path = dir_path
|
||||
self.idx = 0
|
||||
self.logger = clibs.logger
|
||||
|
||||
def logger(self, level, module, content, color="black", error="", flag="both"):
|
||||
flag = "cursor" if level.upper() == "DEBUG" else "both"
|
||||
clibs.logger(level, module, content, color, flag, signal=self.output)
|
||||
if level.upper() == "ERROR":
|
||||
raise Exception(f"{error} | {content}")
|
||||
|
||||
@clibs.handle_exception
|
||||
def check_files(self, rawdata_dirs, result_files):
|
||||
msg_wrong = "需要有四个文件和若干个数据文件夹,可参考如下确认:<br>"
|
||||
msg_wrong += "- reach33/66/100_XXXXXXX.xlsx<br>- *.cfg<br>"
|
||||
msg_wrong += "- reach33_load33_speed33<br>- reach33_load33_speed66<br>...<br>- reach100_load100_speed66<br>- reach100_load100_speed100<br>"
|
||||
|
||||
if len(result_files) != 4 or len(rawdata_dirs) == 0:
|
||||
self.logger("ERROR", "brake", msg_wrong, "red", "InitFileError")
|
||||
self.logger("ERROR", "brake", msg_wrong, "red")
|
||||
|
||||
config_file, reach33_file, reach66_file, reach100_file = None, None, None, None
|
||||
for result_file in result_files:
|
||||
@ -44,7 +36,7 @@ class BrakeDataProcess(QThread):
|
||||
reach100_file = result_file
|
||||
else:
|
||||
if not (config_file and reach33_file and reach66_file and reach100_file):
|
||||
self.logger("ERROR", "brake", msg_wrong, "red", "InitFileError")
|
||||
self.logger("ERROR", "brake", msg_wrong, "red")
|
||||
|
||||
reach_s = ['reach33', 'reach66', 'reach100']
|
||||
load_s = ['load33', 'load66', 'load100']
|
||||
@ -57,17 +49,17 @@ class BrakeDataProcess(QThread):
|
||||
msg = f"报错信息:数据目录 {rawdata_dir} 命名不合规,请参考如下形式<br>"
|
||||
msg += "命名规则:reachAA_loadBB_speedCC,AA/BB/CC 指的是臂展/负载/速度的比例<br>"
|
||||
msg += "规则解释:reach66_load100_speed33,表示 66% 臂展,100% 负载以及 33% 速度情况下的测试结果文件夹<br>"
|
||||
self.logger("ERROR", "brake", msg, "red", "WrongDataFolder")
|
||||
self.logger("ERROR", "brake", msg, "red")
|
||||
|
||||
_, rawdata_files = clibs.traversal_files(rawdata_dir, self.output)
|
||||
_, rawdata_files = clibs.traversal_files(rawdata_dir)
|
||||
if len(rawdata_files) != 3:
|
||||
msg = f"数据目录 {rawdata_dir} 下数据文件个数错误,每个数据目录下有且只能有三个以 .data 为后缀的数据文件"
|
||||
self.logger("ERROR", "brake", msg, "red", "WrongDataFile")
|
||||
self.logger("ERROR", "brake", msg, "red")
|
||||
|
||||
for rawdata_file in rawdata_files:
|
||||
if not rawdata_file.endswith(".data"):
|
||||
msg = f"数据文件 {rawdata_file} 后缀错误,每个数据目录下有且只能有三个以 .data 为后缀的数据文件"
|
||||
self.logger("ERROR", "brake", msg, "red", "WrongDataFile")
|
||||
self.logger("ERROR", "brake", msg, "red")
|
||||
|
||||
result_files = []
|
||||
for _ in [reach33_file, reach66_file, reach100_file]:
|
||||
@ -77,7 +69,6 @@ class BrakeDataProcess(QThread):
|
||||
self.logger("INFO", "brake", "数据目录合规性检查结束,未发现问题......", "green")
|
||||
return config_file, result_files
|
||||
|
||||
@clibs.handle_exception
|
||||
def get_configs(self, config_file):
|
||||
try:
|
||||
with open(config_file, mode="r", encoding="utf-8") as f_config:
|
||||
@ -85,7 +76,7 @@ class BrakeDataProcess(QThread):
|
||||
|
||||
p_dir = config_file.split('/')[-2]
|
||||
if not re.match("^[jJ][123]$", p_dir):
|
||||
self.logger("ERROR", "brake", "被处理的根文件夹命名必须是 [Jj][123] 的格式", "red", "DirNameError")
|
||||
self.logger("ERROR", "brake", "被处理的根文件夹命名必须是 [Jj][123] 的格式", "red")
|
||||
|
||||
axis = int(p_dir[-1]) # 要处理的轴
|
||||
rrs = [abs(_) for _ in configs["TRANSMISSION"]["REDUCTION_RATIO_NUMERATOR"]] # 减速比,rr for reduction ratio
|
||||
@ -94,7 +85,7 @@ class BrakeDataProcess(QThread):
|
||||
av = avs[axis-1]
|
||||
return av, rr
|
||||
except Exception as Err:
|
||||
self.logger("ERROR", "brake", f"无法打开 {config_file},或者使用了错误的机型配置文件,需检查<br>{Err}", "red", "OpenFileError")
|
||||
self.logger("ERROR", "brake", f"无法打开 {config_file},或者使用了错误的机型配置文件,需检查<br>{Err}", "red")
|
||||
|
||||
def now_doing_msg(self, docs, flag):
|
||||
now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
|
||||
@ -109,7 +100,6 @@ class BrakeDataProcess(QThread):
|
||||
self.logger("INFO", "brake", f"[{now}] 文件 {docs} 数据已处理完毕")
|
||||
|
||||
@staticmethod
|
||||
@clibs.handle_exception
|
||||
def data2result(df, ws_result, row_start, row_end):
|
||||
data = []
|
||||
for row in range(row_start, row_end):
|
||||
@ -130,7 +120,6 @@ class BrakeDataProcess(QThread):
|
||||
ws_result.cell(row=row, column=2).value = None
|
||||
ws_result.cell(row=row, column=3).value = None
|
||||
|
||||
@clibs.handle_exception
|
||||
def get_row_range(self, data_file, df, conditions, av, rr):
|
||||
row_start, row_end = 0, 0
|
||||
ratio = float(conditions[2].removeprefix('speed')) / 100
|
||||
@ -142,7 +131,7 @@ class BrakeDataProcess(QThread):
|
||||
row_start = row - 20 if row - 20 > 0 else 0 # 急停前找 20 个点
|
||||
break
|
||||
else:
|
||||
self.logger("ERROR", "brake", f"数据文件 {data_file} 采集的数据中没有 ESTOP 为非 0 的情况,需要确认", "red", "StartNotFoundError")
|
||||
self.logger("ERROR", "brake", f"数据文件 {data_file} 采集的数据中没有 ESTOP 为非 0 的情况,需要确认", "red")
|
||||
|
||||
for row in range(row_start, df.index[-1] - 1, 10):
|
||||
speed_row = df.iloc[row, 0] * clibs.RADIAN * rr * 60 / 360
|
||||
@ -150,7 +139,7 @@ class BrakeDataProcess(QThread):
|
||||
row_end = row + 100 if row + 100 <= df.index[-1] - 1 else df.index[-1] - 1
|
||||
break
|
||||
else:
|
||||
self.logger("ERROR", "brake", f"数据文件 {data_file} 最后的速度未降为零", "red", "SpeedNotZeroError")
|
||||
self.logger("ERROR", "brake", f"数据文件 {data_file} 最后的速度未降为零", "red")
|
||||
|
||||
av_estop = abs(df.iloc[row_start - 20:row_start, 0].abs().mean() * clibs.RADIAN)
|
||||
if abs(av_estop / av_max) < threshold:
|
||||
@ -161,7 +150,6 @@ class BrakeDataProcess(QThread):
|
||||
return row_start, row_end
|
||||
|
||||
@staticmethod
|
||||
@clibs.handle_exception
|
||||
def get_shtname(conditions, count):
|
||||
# 33%负载_33%速度_1 - reach/load/speed
|
||||
load = conditions[1].removeprefix('load')
|
||||
@ -170,7 +158,6 @@ class BrakeDataProcess(QThread):
|
||||
|
||||
return result_sheet_name
|
||||
|
||||
@clibs.handle_exception
|
||||
def single_file_process(self, data_file, wb, count, av, rr):
|
||||
df = pandas.read_csv(data_file, sep='\t')
|
||||
conditions = data_file.split("/")[-2].split("_") # reach/load/speed
|
||||
@ -180,20 +167,19 @@ class BrakeDataProcess(QThread):
|
||||
row_start, row_end = self.get_row_range(data_file, df, conditions, av, rr)
|
||||
self.data2result(df, ws, row_start, row_end)
|
||||
|
||||
@clibs.handle_exception
|
||||
def data_process(self, result_file, rawdata_dirs, av, rr):
|
||||
filename = result_file.split("/")[-1]
|
||||
self.logger("INFO", "brake", f"正在打开文件 {filename},这可能需要一些时间......", "blue")
|
||||
try:
|
||||
wb = openpyxl.load_workbook(result_file)
|
||||
except Exception as Err:
|
||||
self.logger("ERROR", "brake", f"{filename}文件打开失败,可能是文件已损坏,确认后重新执行!<br>{Err}", "red", "CannotOpenFile")
|
||||
self.logger("ERROR", "brake", f"{filename}文件打开失败,可能是文件已损坏,确认后重新执行!<br>{Err}", "red")
|
||||
|
||||
prefix = filename.split('_')[0]
|
||||
for rawdata_dir in rawdata_dirs:
|
||||
if rawdata_dir.split("/")[-1].split('_')[0] == prefix:
|
||||
self.now_doing_msg(rawdata_dir, 'start')
|
||||
_, data_files = clibs.traversal_files(rawdata_dir, self.output)
|
||||
_, data_files = clibs.traversal_files(rawdata_dir)
|
||||
for idx in range(3):
|
||||
self.single_file_process(data_files[idx], wb, idx+1, av, rr)
|
||||
# threads = [
|
||||
@ -209,12 +195,11 @@ class BrakeDataProcess(QThread):
|
||||
wb.save(result_file)
|
||||
wb.close()
|
||||
|
||||
@clibs.handle_exception
|
||||
def processing(self):
|
||||
time_start = time.time()
|
||||
clibs.running[self.idx] = 1
|
||||
|
||||
rawdata_dirs, result_files = clibs.traversal_files(self.dir_path, self.output)
|
||||
rawdata_dirs, result_files = clibs.traversal_files(self.dir_path)
|
||||
config_file, result_files = self.check_files(rawdata_dirs, result_files)
|
||||
av, rr = self.get_configs(config_file)
|
||||
|
||||
|
@ -9,23 +9,15 @@ from codes.common import clibs
|
||||
|
||||
|
||||
class CurrentDataProcess(QThread):
|
||||
output = Signal(str, str)
|
||||
|
||||
def __init__(self, dir_path, proc, /):
|
||||
super().__init__()
|
||||
self.dir_path = dir_path
|
||||
self.proc = proc
|
||||
self.idx = 1
|
||||
self.logger = clibs.logger
|
||||
|
||||
def logger(self, level, module, content, color="black", error="", flag="both"):
|
||||
flag = "cursor" if level.upper() == "DEBUG" else "both"
|
||||
clibs.logger(level, module, content, color, flag, signal=self.output)
|
||||
if level.upper() == "ERROR":
|
||||
raise Exception(f"{error} | {content}")
|
||||
|
||||
@clibs.handle_exception
|
||||
def initialization(self):
|
||||
_, data_files = clibs.traversal_files(self.dir_path, self.output)
|
||||
_, data_files = clibs.traversal_files(self.dir_path)
|
||||
count, config_file = 0, None
|
||||
for data_file in data_files:
|
||||
filename = data_file.split("/")[-1]
|
||||
@ -38,15 +30,14 @@ class CurrentDataProcess(QThread):
|
||||
if not re.match("^j[1-7].*\\.data$", filename):
|
||||
msg = f"不合规 {data_file}<br>"
|
||||
msg += "所有数据文件必须以 j[1-7]_ 开头,以 .data 结尾,比如j1_abcdef.data,请检查整改后重新运行"
|
||||
self.logger("ERROR", "current", msg, "red", "FilenameIllegal")
|
||||
self.logger("ERROR", "current", msg, "red")
|
||||
|
||||
if count != 2:
|
||||
msg = "需要有一个机型配置文件\"*.cfg\",以及一个数据处理文件\"T_电机电流.xlsx\"表格,请检查整改后重新运行"
|
||||
self.logger("ERROR", "current", msg, "red", "FilenameIllegal")
|
||||
self.logger("ERROR", "current", msg, "red")
|
||||
|
||||
return data_files, config_file
|
||||
|
||||
@clibs.handle_exception
|
||||
def current_max(self, data_files, rts):
|
||||
self.logger("INFO", "current", f"正在处理最大转矩值逻辑......")
|
||||
current = {1: [], 2: [], 3: [], 4: [], 5: [], 6: []}
|
||||
@ -88,7 +79,6 @@ class CurrentDataProcess(QThread):
|
||||
self.logger("INFO", "current", f"最大转矩数据处理完毕......")
|
||||
return current
|
||||
|
||||
@clibs.handle_exception
|
||||
def current_avg(self, data_files, rts):
|
||||
self.logger("INFO", "current", f"正在处理平均转矩值逻辑......")
|
||||
current = {1: [], 2: [], 3: [], 4: [], 5: [], 6: []}
|
||||
@ -131,7 +121,6 @@ class CurrentDataProcess(QThread):
|
||||
self.logger("INFO", "current", f"平均转矩数据处理完毕......")
|
||||
return current
|
||||
|
||||
@clibs.handle_exception
|
||||
def current_cycle(self, data_files, rrs, rts, params):
|
||||
result, hold, single, scenario, dur_time = None, [], [], [], 0
|
||||
for data_file in data_files:
|
||||
@ -150,8 +139,8 @@ class CurrentDataProcess(QThread):
|
||||
self.logger("INFO", "current", f"正在打开文件 {filename},这可能需要一些时间......", "blue")
|
||||
try:
|
||||
wb = openpyxl.load_workbook(result)
|
||||
except Exception as Err:
|
||||
self.logger("ERROR", "current", f"{filename}文件打开失败,可能是文件已损坏,确认后重新执行!<br>{Err}", "red", "CannotOpenFile")
|
||||
except Exception as err:
|
||||
self.logger("ERROR", "current", f"{filename}文件打开失败,可能是文件已损坏,确认后重新执行!<br>{err}", "red")
|
||||
|
||||
ws = wb["统计"]
|
||||
for idx in range(len(params)-1):
|
||||
@ -175,7 +164,6 @@ class CurrentDataProcess(QThread):
|
||||
wb.save(result)
|
||||
wb.close()
|
||||
|
||||
@clibs.handle_exception
|
||||
def find_point(self, data_file, df, flag, row_s, row_e, threshold, step, end_point, skip_scale, axis, seq):
|
||||
if flag == "lt":
|
||||
while row_e > end_point:
|
||||
@ -192,7 +180,7 @@ class CurrentDataProcess(QThread):
|
||||
self.logger("WARNING", "current", f"【lt】{axis} 轴第 {seq} 次查找数据可能有异常,row_s = {row_s}, row_e = {row_e}!", "purple")
|
||||
return row_s, row_e
|
||||
else:
|
||||
self.logger("ERROR", "current", f"{data_file} 数据有误,需要检查,无法找到第 {seq} 个有效点......", "red", "AnchorNotFound")
|
||||
self.logger("ERROR", "current", f"{data_file} 数据有误,需要检查,无法找到第 {seq} 个有效点......", "red")
|
||||
elif flag == "gt":
|
||||
while row_e > end_point:
|
||||
speed_avg = df.iloc[row_s:row_e].abs().mean()
|
||||
@ -208,9 +196,8 @@ class CurrentDataProcess(QThread):
|
||||
self.logger("WARNING", "current", f"【gt】{axis} 轴第 {seq} 次查找数据可能有异常,row_s = {row_s}, row_e = {row_e}!", "purple")
|
||||
return row_s, row_e
|
||||
else:
|
||||
self.logger("ERROR", "current", f"{data_file} 数据有误,需要检查,无法找到第 {seq} 个有效点......", "red", "AnchorNotFound")
|
||||
self.logger("ERROR", "current", f"{data_file} 数据有误,需要检查,无法找到第 {seq} 个有效点......", "red")
|
||||
|
||||
@clibs.handle_exception
|
||||
def get_row_number(self, threshold, flag, df, row_s, row_e, axis):
|
||||
count_1, count_2 = 0, 0
|
||||
if flag == "start" or flag == "end":
|
||||
@ -236,7 +223,6 @@ class CurrentDataProcess(QThread):
|
||||
self.logger("DEBUG", "current", f"{axis} 轴获取{places[flag]}数据 {row_e} 可能有异常,需关注!", "purple")
|
||||
return row_e
|
||||
|
||||
@clibs.handle_exception
|
||||
def p_single(self, wb, single, rrs):
|
||||
# 1. 先找到第一个速度为零的点,数据从后往前找,一开始就是零的情况不予考虑
|
||||
# 2. 记录第一个点的位置,继续向前查找第二个速度为零的点,同理,一开始为零的点不予考虑
|
||||
@ -316,7 +302,7 @@ class CurrentDataProcess(QThread):
|
||||
self.logger("DEBUG", "current", f"{axis} 轴数据非零段点数:{row_middle-row_start+1}")
|
||||
self.logger("DEBUG", "current", f"{axis} 轴数据为零段点数:{row_end-row_middle+1}")
|
||||
if abs(row_end+row_start-2*row_middle) > 1000:
|
||||
self.logger("DEBUG", "current", f"{axis} 轴数据占空比异常!", "purple")
|
||||
self.logger("WARNING", "current", f"{axis} 轴数据占空比异常,处理数据可能有误,需检查!", "purple")
|
||||
|
||||
data, first_c, second_c, third_c, fourth_c = [], clibs.c_joint_vel-1, clibs.c_servo_trq-1, clibs.c_sensor_trq-1, clibs.c_estimate_trans_trq-1
|
||||
for row in range(row_start, row_end+1):
|
||||
@ -340,7 +326,6 @@ class CurrentDataProcess(QThread):
|
||||
cell.value = None
|
||||
i += 1
|
||||
|
||||
@clibs.handle_exception
|
||||
def p_scenario(self, wb, scenario, rrs, dur_time):
|
||||
self.logger("INFO", "current", f"本次处理的是电机电流场景数据,场景运动周期为 {dur_time}s", "blue")
|
||||
for data_file in scenario:
|
||||
@ -359,7 +344,7 @@ class CurrentDataProcess(QThread):
|
||||
row_start = 3000
|
||||
row_end = row_start + int(dur_time/cycle)
|
||||
if row_end > df.index[-1]:
|
||||
self.logger("ERROR", "current", f"位置超限:{data_file} 共有 {df.index[-1]} 条数据,无法取到第 {row_end} 条数据,需要确认场景周期时间...", "blue", "DataOverLimit")
|
||||
self.logger("ERROR", "current", f"位置超限:{data_file} 共有 {df.index[-1]} 条数据,无法取到第 {row_end} 条数据,需要确认场景周期时间...", "red")
|
||||
|
||||
data, first_c, second_c, third_c, fourth_c = [], clibs.c_joint_vel-1, clibs.c_servo_trq-1, clibs.c_sensor_trq-1, clibs.c_estimate_trans_trq-1
|
||||
for row in range(row_start, row_end+1):
|
||||
@ -383,7 +368,6 @@ class CurrentDataProcess(QThread):
|
||||
ws.cell((i//4)+2, 1).value = None
|
||||
i += 1
|
||||
|
||||
@clibs.handle_exception
|
||||
def get_configs(self, config_file):
|
||||
try:
|
||||
if re.match("^[NXEC]B.*", config_file.split("/")[-1]):
|
||||
@ -412,10 +396,9 @@ class CurrentDataProcess(QThread):
|
||||
self.logger("INFO", "current", f"get_configs: 额定转矩 {m_rts}")
|
||||
self.logger("INFO", "current", f"get_configs: 最大角速度 {m_avs}")
|
||||
return sc, r_rrs, m_avs, m_stall_ts, m_rts, m_max_ts, m_r_rpms, m_max_rpms, r_max_sst, r_max_t, r_avg_t, robot_type
|
||||
except Exception as Err:
|
||||
self.logger("ERROR", "current", f"get_config: 无法打开 {config_file},或获取配置文件参数错误 {Err}", "red", "OpenFileError")
|
||||
except Exception as err:
|
||||
self.logger("ERROR", "current", f"get_config: 无法打开 {config_file},或获取配置文件参数错误 {err}", "red")
|
||||
|
||||
@clibs.handle_exception
|
||||
def processing(self):
|
||||
time_start = time.time()
|
||||
clibs.running[self.idx] = 1
|
||||
@ -432,5 +415,5 @@ class CurrentDataProcess(QThread):
|
||||
|
||||
self.logger("INFO", "current", "-"*60 + "<br>全部处理完毕<br>", "purple")
|
||||
time_total = time.time() - time_start
|
||||
msg = f"数据处理时间:{time_total // 3600:02.0f} h {time_total % 3600 // 60:02.0f} m {time_total % 60:02.0f} s\n"
|
||||
msg = f"数据处理时间:{time_total // 3600:02.0f} h {time_total % 3600 // 60:02.0f} m {time_total % 60:02.0f} s"
|
||||
self.logger("INFO", "current", msg)
|
||||
|
@ -7,20 +7,14 @@ from codes.common import clibs
|
||||
|
||||
|
||||
class IsoDataProcess(QThread):
|
||||
output = Signal(str, str)
|
||||
|
||||
def __init__(self, dir_path, /):
|
||||
super().__init__()
|
||||
self.dir_path = dir_path
|
||||
self.idx = 2
|
||||
self.logger = clibs.logger
|
||||
|
||||
def logger(self, level, module, content, color="black", error="", flag="both"):
|
||||
flag = "cursor" if level.upper() == "DEBUG" else "both"
|
||||
clibs.logger(level, module, content, color, flag, signal=self.output)
|
||||
if level.upper() == "ERROR":
|
||||
raise Exception(f"{error} | {content}")
|
||||
|
||||
def p_iso(self, file, p_files, ws, tmpfile):
|
||||
@staticmethod
|
||||
def p_iso(file, p_files, ws, tmpfile):
|
||||
p_files.append(file)
|
||||
|
||||
pdf = pdfplumber.open(file)
|
||||
@ -79,7 +73,8 @@ class IsoDataProcess(QThread):
|
||||
pass
|
||||
pdf.close()
|
||||
|
||||
def p_iso_100(self, file, p_files, ws, tmpfile):
|
||||
@staticmethod
|
||||
def p_iso_100(file, p_files, ws, tmpfile):
|
||||
p_files.append(file)
|
||||
|
||||
pdf = pdfplumber.open(file)
|
||||
@ -112,7 +107,8 @@ class IsoDataProcess(QThread):
|
||||
pass
|
||||
pdf.close()
|
||||
|
||||
def p_iso_1000(self, file, p_files, ws, tmpfile):
|
||||
@staticmethod
|
||||
def p_iso_1000(file, p_files, ws, tmpfile):
|
||||
p_files.append(file)
|
||||
|
||||
pdf = pdfplumber.open(file)
|
||||
@ -146,9 +142,9 @@ class IsoDataProcess(QThread):
|
||||
pdf.close()
|
||||
|
||||
def initialization(self):
|
||||
dirs, files = clibs.traversal_files(self.dir_path, self.output)
|
||||
dirs, files = clibs.traversal_files(self.dir_path)
|
||||
if len(dirs) != 0:
|
||||
self.logger("ERROR", "iso", f"init: 工作目录下不可以有文件夹!", "red", "InitFileError")
|
||||
self.logger("ERROR", "iso", f"init: 工作目录下不可以有文件夹!", "red")
|
||||
|
||||
for file in files:
|
||||
file = file.lower()
|
||||
@ -161,7 +157,7 @@ class IsoDataProcess(QThread):
|
||||
elif file.endswith("iso.pdf"):
|
||||
pass
|
||||
else:
|
||||
self.logger("ERROR", "iso", f"init: 工作目录下只允许有如下四个文件,不区分大小写,pdf文件最少有一个!<br>1. iso-results.xlsx<br>2. ISO.pdf<br>3. ISO-V100.pdf<br>4. ISO-V1000.pdf", "red", "InitFileError")
|
||||
self.logger("ERROR", "iso", f"init: 工作目录下只允许有如下四个文件,不区分大小写,pdf文件最少有一个!<br>1. iso-results.xlsx<br>2. ISO.pdf<br>3. ISO-V100.pdf<br>4. ISO-V1000.pdf", "red")
|
||||
|
||||
return files
|
||||
|
||||
@ -178,8 +174,8 @@ class IsoDataProcess(QThread):
|
||||
ws = wb.active
|
||||
for i in range(3, 50):
|
||||
ws.cell(row=i, column=7).value = None
|
||||
except Exception as Err:
|
||||
self.logger("ERROR", "iso", f"main: 无法打开文件 {filename}<br>{Err}", "red", "FileOpenError")
|
||||
except Exception as err:
|
||||
self.logger("ERROR", "iso", f"main: 无法打开文件 {filename}<br>{err}", "red")
|
||||
|
||||
p_files = []
|
||||
for file in files:
|
||||
@ -204,11 +200,11 @@ class IsoDataProcess(QThread):
|
||||
wb.close()
|
||||
|
||||
if len(p_files) == 0:
|
||||
self.logger("ERROR", "iso", f"目录 {self.dir_path} 下没有需要处理的文件,需要确认......", "red", "FileNotFound")
|
||||
self.logger("ERROR", "iso", f"目录 {self.dir_path} 下没有需要处理的文件,需要确认......", "red")
|
||||
else:
|
||||
os.remove(tmpfile)
|
||||
|
||||
self.logger("INFO", "current-processing", "-" * 60 + "<br>全部处理完毕<br>", "purple")
|
||||
time_total = time.time() - time_start
|
||||
msg = f"数据处理时间:{time_total // 3600:02.0f} h {time_total % 3600 // 60:02.0f} m {time_total % 60:02.0f} s\n"
|
||||
msg = f"数据处理时间:{time_total // 3600:02.0f} h {time_total % 3600 // 60:02.0f} m {time_total % 60:02.0f} s"
|
||||
self.logger("INFO", "current-processing", msg)
|
||||
|
@ -8,18 +8,11 @@ from codes.common import clibs
|
||||
|
||||
|
||||
class WaveloggerDataProcess(QThread):
|
||||
output = Signal(str, str)
|
||||
|
||||
def __init__(self, dir_path, /):
|
||||
super().__init__()
|
||||
self.dir_path = dir_path
|
||||
self.idx = 3
|
||||
|
||||
def logger(self, level, module, content, color="black", error="", flag="both"):
|
||||
flag = "cursor" if level.upper() == "DEBUG" else "both"
|
||||
clibs.logger(level, module, content, color, flag, signal=self.output)
|
||||
if level.upper() == "ERROR":
|
||||
raise Exception(f"{error} | {content}")
|
||||
self.logger = clibs.logger
|
||||
|
||||
def find_point(self, bof, step, margin, threshold, pos, data_file, flag, df, row):
|
||||
# bof: backward or forward
|
||||
@ -38,7 +31,7 @@ class WaveloggerDataProcess(QThread):
|
||||
break
|
||||
else:
|
||||
if bof == "backward":
|
||||
self.logger("ERROR", "wavelogger", f"find_point-gt: [{pos}] 在 {data_file} 中,无法正确识别数据,需要确认...", "red", "DataError")
|
||||
self.logger("ERROR", "wavelogger", f"find_point-gt: [{pos}] 在 {data_file} 中,无法正确识别数据,需要确认...", "red")
|
||||
elif bof == "forward":
|
||||
row_target = row + margin # to end while loop in function `single_file_proc`
|
||||
elif flag == "lt":
|
||||
@ -52,7 +45,7 @@ class WaveloggerDataProcess(QThread):
|
||||
break
|
||||
else:
|
||||
if bof == "backward":
|
||||
self.logger("ERROR", "wavelogger", f"find_point-lt: [{pos}] 在 {data_file} 中,无法正确识别数据,需要确认...", "red", "DataError")
|
||||
self.logger("ERROR", "wavelogger", f"find_point-lt: [{pos}] 在 {data_file} 中,无法正确识别数据,需要确认...", "red")
|
||||
elif bof == "forward":
|
||||
row_target = row + margin # to end while loop in function `single_file_proc`
|
||||
return row_target
|
||||
@ -85,11 +78,11 @@ class WaveloggerDataProcess(QThread):
|
||||
return row_end-row_middle, row_middle-row_start, row_end-row_start, df
|
||||
|
||||
def initialization(self):
|
||||
_, data_files = clibs.traversal_files(self.dir_path, self.output)
|
||||
_, data_files = clibs.traversal_files(self.dir_path)
|
||||
|
||||
for data_file in data_files:
|
||||
if not data_file.lower().endswith(".csv"):
|
||||
self.logger("ERROR", "wavelogger", f"init: {data_file} 文件后缀错误,只允许 .csv 文件,需要确认!", "red", "FileTypeError")
|
||||
self.logger("ERROR", "wavelogger", f"init: {data_file} 文件后缀错误,只允许 .csv 文件,需要确认!", "red")
|
||||
|
||||
return data_files
|
||||
|
||||
@ -115,7 +108,7 @@ class WaveloggerDataProcess(QThread):
|
||||
value = df.iloc[start:end, 2].astype(float).mean() + 3 * df.iloc[start:end, 2].astype(float).std()
|
||||
if value > 1:
|
||||
msg = f"\n"
|
||||
self.logger("WARNING", "wavelogger", f"{data_file} 文件第 {count} 轮 第 {count_i} 个数据可能有问题,需人工手动确认,确认有问题可删除,无问题则保留", "purple")
|
||||
self.logger("WARNING", "wavelogger", f"{data_file} 文件第 {count} 轮 第 {count_i} 个数据可能有问题,需人工手动确认,确认有问题可删除,无问题则保留")
|
||||
|
||||
data[count].append(value)
|
||||
count_i += 1
|
||||
@ -157,5 +150,5 @@ class WaveloggerDataProcess(QThread):
|
||||
|
||||
self.logger("INFO", "wavelogger", "-" * 60 + "<br>全部处理完毕<br>", "purple")
|
||||
time_total = time.time() - time_start
|
||||
msg = f"数据处理时间:{time_total // 3600:02.0f} h {time_total % 3600 // 60:02.0f} m {time_total % 60:02.0f} s\n"
|
||||
msg = f"数据处理时间:{time_total // 3600:02.0f} h {time_total % 3600 // 60:02.0f} m {time_total % 60:02.0f} s"
|
||||
self.logger("INFO", "wavelogger", msg)
|
||||
|
Reference in New Issue
Block a user