v0.2.0.5(2024/07/31)
此版本改动较大,公共部分做了规整,放置到新建文件夹 commons 当中,并所有自定义模块引入 logging 模块,记录重要信息 1. [t_change_ui: clibs.py] - 调整代码组织结构,新增模块,将公共函数以及类合并入此 - 将一些常量放入该模块 - 引入logging/concurrent_log_handler模块,并作初始化操作,供其他模块使用,按50M切割,最多保留10份 - prj_to_xcore函数设置工程名部分重写,修复了多个prj工程可能不能执行的问题 2. [t_change_ui: openapi.py] - 完全重写了 get_from_id 函数,使更精准 - 在 msg_storage 函数中,增加 logger,保留所有响应消息 - 删除 heartbeat 函数中的日志保存功能部分 - 心跳再次修改为 2s... 3. [t_change_ui: aio.py] - 增加了日志初始化部分 - detect_network 函数中修改重新实例化HR间隔为 4s,对应心跳 4. [t_change_ui: do_brake.py] - 使用一直打开曲线的方法规避解决了 OOM 的问题,同时修改数据处理方式,只取最后 12s 5. [t_change_ui: do_current.py] - 保持电流,只取最后 15s 6. [t_change_ui: all the part]: 引入 commons 包,并定制了 logging 输出,后续持续优化
This commit is contained in:
@ -1 +0,0 @@
|
||||
__all__ = ['brake', 'current', 'iso', 'wavelogger']
|
@ -1,49 +1,14 @@
|
||||
# coding: utf-8
|
||||
from os import scandir
|
||||
from os.path import isfile, exists
|
||||
from os.path import isfile
|
||||
from sys import argv
|
||||
from openpyxl import load_workbook
|
||||
from time import time, sleep, strftime, localtime
|
||||
from threading import Thread
|
||||
from pandas import read_csv
|
||||
from logging import getLogger
|
||||
from commons import clibs
|
||||
|
||||
|
||||
class GetThreadResult(Thread):
|
||||
def __init__(self, func, args=()):
|
||||
super(GetThreadResult, self).__init__()
|
||||
self.func = func
|
||||
self.args = args
|
||||
self.result = 0
|
||||
|
||||
def run(self):
|
||||
sleep(1)
|
||||
self.result = self.func(*self.args)
|
||||
|
||||
def get_result(self):
|
||||
Thread.join(self) # 等待线程执行完毕
|
||||
try:
|
||||
return self.result
|
||||
except Exception as Err:
|
||||
return None
|
||||
|
||||
|
||||
def traversal_files(path, w2t):
|
||||
# 功能:以列表的形式分别返回指定路径下的文件和文件夹,不包含子目录
|
||||
# 参数:路径
|
||||
# 返回值:路径下的文件夹列表 路径下的文件列表
|
||||
if not exists(path):
|
||||
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
||||
w2t(msg, 0, 1, 'red')
|
||||
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
|
||||
logger = getLogger(__file__)
|
||||
|
||||
|
||||
def check_files(path, raw_data_dirs, result_files, w2t):
|
||||
@ -83,7 +48,7 @@ def check_files(path, raw_data_dirs, result_files, w2t):
|
||||
规则解释:AA/BB/CC 指的是臂展/负载/速度的比例,例如reach66_load100_speed33:66%臂展,100%负载以及33%速度情况下的测试结果文件夹"""
|
||||
w2t(msg, 0, 4, 'red')
|
||||
|
||||
_, raw_data_files = traversal_files(raw_data_dir, w2t)
|
||||
_, raw_data_files = clibs.traversal_files(raw_data_dir, w2t)
|
||||
if len(raw_data_files) != 3:
|
||||
msg = f"数据目录 {raw_data_dir} 下数据文件个数错误,每个数据目录下有且只能有三个以 .data 为后缀的数据文件"
|
||||
w2t(msg, 0, 5, 'red')
|
||||
@ -109,6 +74,7 @@ def get_configs(configfile, w2t):
|
||||
|
||||
return av, rr
|
||||
|
||||
|
||||
def now_doing_msg(docs, flag, w2t):
|
||||
# 功能:输出正在处理的文件或目录
|
||||
# 参数:文件或目录,start 或 done 标识
|
||||
@ -228,7 +194,7 @@ def data_process(result_file, raw_data_dirs, av, rr, vel, trq, estop, w2t):
|
||||
|
||||
global stop
|
||||
stop = 0
|
||||
t_excel = GetThreadResult(load_workbook, args=(result_file, ))
|
||||
t_excel = clibs.GetThreadResult(load_workbook, args=(result_file, ))
|
||||
t_wait = Thread(target=w2t_local, args=('.', 1, w2t))
|
||||
t_excel.start()
|
||||
t_wait.start()
|
||||
@ -242,7 +208,7 @@ def data_process(result_file, raw_data_dirs, av, rr, vel, trq, estop, w2t):
|
||||
for raw_data_dir in raw_data_dirs:
|
||||
if raw_data_dir.split('\\')[-1].split('_')[0] == prefix:
|
||||
now_doing_msg(raw_data_dir, 'start', w2t)
|
||||
_, data_files = traversal_files(raw_data_dir, w2t)
|
||||
_, data_files = clibs.traversal_files(raw_data_dir, w2t)
|
||||
# 数据文件串行处理模式---------------------------------
|
||||
# count = 1
|
||||
# for data_file in data_files:
|
||||
@ -280,7 +246,7 @@ def main(path, vel, trq, estop, w2t):
|
||||
# 参数:initialization函数的返回值
|
||||
# 返回值:-
|
||||
time_start = time()
|
||||
raw_data_dirs, result_files = traversal_files(path, w2t)
|
||||
raw_data_dirs, result_files = clibs.traversal_files(path, w2t)
|
||||
|
||||
try:
|
||||
# threads = []
|
||||
|
@ -1,31 +1,14 @@
|
||||
from openpyxl import load_workbook
|
||||
from os import scandir
|
||||
from os.path import exists
|
||||
from sys import argv
|
||||
from pandas import read_csv, concat, set_option
|
||||
from re import match
|
||||
from threading import Thread
|
||||
from time import sleep
|
||||
from csv import reader, writer
|
||||
from logging import getLogger
|
||||
from commons import clibs
|
||||
|
||||
|
||||
class GetThreadResult(Thread):
|
||||
def __init__(self, func, args=()):
|
||||
super(GetThreadResult, self).__init__()
|
||||
self.func = func
|
||||
self.args = args
|
||||
self.result = 0
|
||||
|
||||
def run(self):
|
||||
sleep(1)
|
||||
self.result = self.func(*self.args)
|
||||
|
||||
def get_result(self):
|
||||
Thread.join(self) # 等待线程执行完毕
|
||||
try:
|
||||
return self.result
|
||||
except Exception as Err:
|
||||
return None
|
||||
logger = getLogger(__file__)
|
||||
|
||||
|
||||
def w2t_local(msg, wait, w2t):
|
||||
@ -38,27 +21,8 @@ def w2t_local(msg, wait, w2t):
|
||||
break
|
||||
|
||||
|
||||
def traversal_files(path, w2t):
|
||||
# 功能:以列表的形式分别返回指定路径下的文件和文件夹,不包含子目录
|
||||
# 参数:路径
|
||||
# 返回值:路径下的文件夹列表 路径下的文件列表
|
||||
if not exists(path):
|
||||
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
||||
w2t(msg, 0, 8, 'red')
|
||||
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, sub, w2t):
|
||||
_, data_files = traversal_files(path, w2t)
|
||||
_, data_files = clibs.traversal_files(path, w2t)
|
||||
count = 0
|
||||
|
||||
for data_file in data_files:
|
||||
@ -69,8 +33,8 @@ def initialization(path, sub, w2t):
|
||||
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),请检查后重新运行。"
|
||||
msg = f"不合规 {data_file}\n"
|
||||
msg += f"所有文件必须以 jx_ 开头,以 .data/csv 结尾(x取值1-7),请检查后重新运行。"
|
||||
w2t(msg, 0, 6, 'red')
|
||||
|
||||
if not ((sub == 'cycle' and count == 2) or (sub != 'cycle' and count == 1)):
|
||||
@ -174,7 +138,7 @@ def current_cycle(dur, data_files, rcs, rrs, vel, trq, trqh, rpms, w2t):
|
||||
w2t(f"正在打开文件 {result},需要 10s 左右", 1, 0, 'orange')
|
||||
global stop
|
||||
stop = 0
|
||||
t_excel = GetThreadResult(load_workbook, args=(result, ))
|
||||
t_excel = clibs.GetThreadResult(load_workbook, args=(result, ))
|
||||
t_wait = Thread(target=w2t_local, args=('.', 1, w2t))
|
||||
t_excel.start()
|
||||
t_wait.start()
|
||||
@ -268,7 +232,7 @@ def p_single(wb, single, vel, trq, rpms, rrs, w2t):
|
||||
col_names = list(df.columns)
|
||||
df_1 = df[col_names[vel-1]].multiply(rpm*addition)
|
||||
df_2 = df[col_names[trq-1]].multiply(scale)
|
||||
print(df_1.abs().max())
|
||||
# print(df_1.abs().max())
|
||||
df = concat([df_1, df_2], axis=1)
|
||||
|
||||
_step = 5 if data_file.endswith('.csv') else 50
|
||||
|
@ -1,27 +1,12 @@
|
||||
# _*_ encoding:utf-8 _*_
|
||||
import pdfplumber
|
||||
from openpyxl import load_workbook
|
||||
from os import scandir, remove
|
||||
from os.path import exists
|
||||
from os import remove
|
||||
from sys import argv
|
||||
from logging import getLogger
|
||||
from commons import clibs
|
||||
|
||||
|
||||
def traversal_files(path, w2t):
|
||||
# 功能:以列表的形式分别返回指定路径下的文件和文件夹,不包含子目录
|
||||
# 参数:路径
|
||||
# 返回值:路径下的文件夹列表 路径下的文件列表
|
||||
if not exists(path):
|
||||
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
||||
w2t(msg, 0, 1, 'red')
|
||||
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
|
||||
logger = getLogger(__file__)
|
||||
|
||||
|
||||
def p_iso(file, p_files, ws, tmpfile):
|
||||
@ -153,7 +138,7 @@ def p_iso_1000(file, p_files, ws, tmpfile):
|
||||
|
||||
|
||||
def main(path, w2t):
|
||||
dirs, files = traversal_files(path, 1)
|
||||
dirs, files = clibs.traversal_files(path, 1)
|
||||
|
||||
try:
|
||||
wb = load_workbook(path + "/iso-results.xlsx")
|
||||
|
@ -1,31 +1,11 @@
|
||||
import os
|
||||
import random
|
||||
|
||||
from pandas import read_csv
|
||||
from csv import reader
|
||||
from sys import argv
|
||||
from os.path import exists
|
||||
from os import scandir, remove
|
||||
from openpyxl import Workbook
|
||||
from random import randint
|
||||
from logging import getLogger
|
||||
from commons import clibs
|
||||
|
||||
def traversal_files(path, w2t):
|
||||
# 功能:以列表的形式分别返回指定路径下的文件和文件夹,不包含子目录
|
||||
# 参数:路径
|
||||
# 返回值:路径下的文件夹列表 路径下的文件列表
|
||||
if not exists(path):
|
||||
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
||||
w2t(msg, 0, 1, 'red')
|
||||
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
|
||||
logger = getLogger(__file__)
|
||||
|
||||
|
||||
def find_point(bof, step, pos, data_file, flag, df, row, w2t):
|
||||
@ -95,7 +75,7 @@ def get_cycle_info(data_file, df, row, step, w2t):
|
||||
|
||||
|
||||
def initialization(path, w2t):
|
||||
_, data_files = traversal_files(path, w2t)
|
||||
_, data_files = clibs.traversal_files(path, w2t)
|
||||
|
||||
for data_file in data_files:
|
||||
if not data_file.lower().endswith('.csv'):
|
||||
@ -126,7 +106,7 @@ def single_file_proc(ws, data_file, df, low, high, cycle, w2t):
|
||||
_step = 5
|
||||
_data = {}
|
||||
row_max = df.index[-1]-100
|
||||
print(data_file)
|
||||
# print(data_file)
|
||||
while _row < row_max:
|
||||
if count not in _data.keys():
|
||||
_data[count] = []
|
||||
@ -149,7 +129,7 @@ def single_file_proc(ws, data_file, df, low, high, cycle, w2t):
|
||||
ws.cell(row=1, column=i).value = f"第{i-1}次测试"
|
||||
ws.cell(row=i, column=1).value = f"第{i-1}次精度变化"
|
||||
|
||||
print(_data)
|
||||
# print(_data)
|
||||
for i in sorted(_data.keys()):
|
||||
_row = 2
|
||||
_column = i + 1
|
||||
@ -162,9 +142,9 @@ def execution(data_files, w2t):
|
||||
wb = Workbook()
|
||||
for data_file in data_files:
|
||||
ws, df, low, high, cycle = preparation(data_file, wb, w2t)
|
||||
print(f"low = {low}")
|
||||
print(f"high = {high}")
|
||||
print(f"cycle = {cycle}")
|
||||
# print(f"low = {low}")
|
||||
# print(f"high = {high}")
|
||||
# print(f"cycle = {cycle}")
|
||||
single_file_proc(ws, data_file, df, low, high, cycle, w2t)
|
||||
|
||||
wd = data_files[0].split('\\')
|
||||
|
Reference in New Issue
Block a user