完成了电流->转矩的转变,基本完成

This commit is contained in:
2025-01-22 16:14:19 +08:00
parent 7f815ac63e
commit 92bdf133f2
48 changed files with 662 additions and 870240 deletions

View File

@ -1,6 +1,7 @@
import pandas
import csv
import openpyxl
import chardet
from common import clibs
@ -9,7 +10,7 @@ def find_point(bof, step, margin, threshold, pos, data_file, flag, df, row, w2t)
# pos: used for debug
# flag: greater than or lower than
row_target = None
row_origin = df.index[-1] - margin + 1
row_origin = len(df) - margin + 1
if flag == "gt":
while 0 < row < row_origin:
value = float(df.iloc[row, 2])
@ -22,7 +23,7 @@ def find_point(bof, step, margin, threshold, pos, data_file, flag, df, row, w2t)
else:
if bof == "backward":
clibs.insert_logdb("ERROR", "wavelogger", f"find_point-gt: [{pos}] 在 {data_file} 中,无法正确识别数据,需要确认...")
w2t(f"[{pos}] 在 {data_file} 中,无法正确识别数据,需要确认...", "red", "DataError")
w2t(f"[{pos}] 在 {data_file} 中,无法正确识别数据,需要确认...\n", "red", "DataError")
elif bof == "forward":
row_target = row + margin # to end while loop in function `single_file_proc`
elif flag == "lt":
@ -37,7 +38,7 @@ def find_point(bof, step, margin, threshold, pos, data_file, flag, df, row, w2t)
else:
if bof == "backward":
clibs.insert_logdb("ERROR", "wavelogger", f"find_point-lt: [{pos}] 在 {data_file} 中,无法正确识别数据,需要确认...")
w2t(f"[{pos}] 在 {data_file} 中,无法正确识别数据,需要确认...", "red", "DataError")
w2t(f"[{pos}] 在 {data_file} 中,无法正确识别数据,需要确认...\n", "red", "DataError")
elif bof == "forward":
row_target = row + margin # to end while loop in function `single_file_proc`
return row_target
@ -49,10 +50,14 @@ def get_cycle_info(data_file, step, margin, threshold, w2t):
# 1. 从最后读取数据无论是大于1还是小于1都舍弃找到相反的值的起始点
# 2. 从起始点,继续往前寻找,找到与之数值相反的中间点
# 3. 从中间点,继续往前寻找,找到与之数值相反的结束点,至此,得到了高低数值的时间区间以及一轮的周期时间
csv_reader = csv.reader(open(data_file))
with open(data_file, "rb") as f:
raw_data = f.read(1000)
result = chardet.detect(raw_data)
encoding = result['encoding']
csv_reader = csv.reader(open(data_file, encoding=encoding))
begin = int(next(csv_reader)[1])
df = pandas.read_csv(data_file, sep=",", encoding="gbk", skip_blank_lines=False, header=begin - 1, on_bad_lines="skip")
row = df.index[-1] - margin
df = pandas.read_csv(data_file, sep=",", encoding=encoding, skip_blank_lines=False, header=begin - 1, on_bad_lines="skip")
row = len(df) - margin
if float(df.iloc[row, 2]) < threshold:
row = find_point("backward", step, margin, threshold, "a1", data_file, "lt", df, row, w2t)
@ -73,7 +78,7 @@ def initialization(path, w2t):
for data_file in data_files:
if not data_file.lower().endswith(".csv"):
clibs.insert_logdb("ERROR", "wavelogger", f"init: {data_file} 文件后缀错误,只允许 .csv 文件,需要确认!")
w2t(f"{data_file} 文件后缀错误,只允许 .csv 文件,需要确认!", "red", "FileTypeError")
w2t(f"{data_file} 文件后缀错误,只允许 .csv 文件,需要确认!\n", "red", "FileTypeError")
return data_files
@ -88,7 +93,7 @@ def preparation(data_file, step, margin, threshold, wb, w2t):
def single_file_proc(ws, data_file, step, threshold, margin, data_length, df, cycle, w2t):
row, row_lt, row_gt, count, count_i, data = 1, 1, 1, 1, 1, {}
row_max = df.index[-1] - margin
row_max = len(df) - margin
while row < row_max:
if count not in data.keys():
data[count] = []
@ -98,9 +103,9 @@ def single_file_proc(ws, data_file, step, threshold, margin, data_length, df, cy
row_lt = find_point("forward", step, margin, threshold, "c"+str(row), data_file, "lt", df, row, w2t)
start = int(row_gt + (row_lt - row_gt - data_length) / 2)
end = start + data_length
value = df.iloc[start:end, 2].mean() + 3 * df.iloc[start:end, 2].std()
value = df.iloc[start:end, 2].astype(float).mean() + 3 * df.iloc[start:end, 2].astype(float).std()
if value > 1:
msg = f"{data_file} 文件第 {count} 轮 第 {count_i} 个数据可能有问题,需人工手动确认,确认有问题可删除,无问题则保留"
msg = f"{data_file} 文件第 {count} 轮 第 {count_i} 个数据可能有问题,需人工手动确认,确认有问题可删除,无问题则保留\n"
clibs.insert_logdb("WARNING", "wavelogger", msg)
w2t(msg, "orange")
data[count].append(value)