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:
102
aio/code/aio.py
102
aio/code/aio.py
@ -1,49 +1,37 @@
|
||||
import tkinter
|
||||
from os.path import exists, dirname
|
||||
from os import getcwd
|
||||
from os.path import exists
|
||||
from os import getcwd, remove
|
||||
from threading import Thread
|
||||
import tkinter.messagebox
|
||||
import customtkinter
|
||||
from time import time, strftime, localtime, sleep
|
||||
from urllib.request import urlopen
|
||||
from socket import setdefaulttimeout
|
||||
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
||||
from data_process import *
|
||||
from automatic_test import *
|
||||
from durable_action import *
|
||||
import openapi
|
||||
import matplotlib.pyplot as plt
|
||||
from data_process import brake, current, iso, wavelogger
|
||||
from automatic_test import do_current, do_brake, btn_functions
|
||||
from durable_action import factory_test
|
||||
from commons import openapi, clibs
|
||||
from matplotlib.pyplot import rcParams, figure, subplots_adjust
|
||||
from matplotlib import use
|
||||
from pandas import DataFrame, read_excel
|
||||
import logging
|
||||
|
||||
with open(clibs.log_data, 'w') as _:
|
||||
for i in range(1, 11):
|
||||
try:
|
||||
remove(f'{clibs.log_data}.{i}')
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
logger = logging.getLogger(__file__)
|
||||
logger.info("日志文件初始化完成...")
|
||||
|
||||
use('Agg')
|
||||
heartbeat = f'{dirname(__file__)}/../assets/templates/heartbeat'
|
||||
durable_data_current_xlsx = f'{dirname(__file__)}/../assets/templates/durable/durable_data_current.xlsx'
|
||||
durable_data_current_max_xlsx = f'{dirname(__file__)}/../assets/templates/durable/durable_data_current_max.xlsx'
|
||||
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
|
||||
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
customtkinter.set_widget_scaling(1.1) # widget dimensions and text size
|
||||
customtkinter.set_window_scaling(1.1) # window geometry dimensions
|
||||
setdefaulttimeout(3)
|
||||
|
||||
# global vars
|
||||
durable_data_current = {
|
||||
'time': list(range(1, 19)),
|
||||
'axis1': [0 for _ in range(18)],
|
||||
'axis2': [0 for _ in range(18)],
|
||||
'axis3': [0 for _ in range(18)],
|
||||
'axis4': [0 for _ in range(18)],
|
||||
'axis5': [0 for _ in range(18)],
|
||||
'axis6': [0 for _ in range(18)],
|
||||
}
|
||||
durable_data_current_max = {
|
||||
'time': list(range(1, 19)),
|
||||
'axis1': [0 for _ in range(18)],
|
||||
'axis2': [0 for _ in range(18)],
|
||||
'axis3': [0 for _ in range(18)],
|
||||
'axis4': [0 for _ in range(18)],
|
||||
'axis5': [0 for _ in range(18)],
|
||||
'axis6': [0 for _ in range(18)],
|
||||
}
|
||||
btns_func = {
|
||||
'start': {'btn': '', 'row': 1, 'text': '开始运行'},
|
||||
'check': {'btn': '', 'row': 2, 'text': '检查参数'},
|
||||
@ -79,6 +67,7 @@ class App(customtkinter.CTk):
|
||||
self.flg = 0
|
||||
self.df_copy = None
|
||||
self.old_curve = None
|
||||
self.myThread = None
|
||||
# =====================================================================
|
||||
# configure window
|
||||
self.title("AIO - All in one automatic toolbox")
|
||||
@ -202,37 +191,36 @@ class App(customtkinter.CTk):
|
||||
if cur_vers.strip() != new_vers.strip():
|
||||
msg = f"""当前版本:{cur_vers}\n更新版本:{new_vers}\n\n请及时前往钉盘更新~~~"""
|
||||
tkinter.messagebox.showwarning(title="版本更新", message=msg)
|
||||
self.destroy()
|
||||
except:
|
||||
tkinter.messagebox.showwarning(title="版本更新", message="连接服务器失败,无法确认当前是否是最新版本......")
|
||||
# functions below ↓ ----------------------------------------------------------------------------------------
|
||||
|
||||
def create_canvas(self, figure):
|
||||
self.canvas = FigureCanvasTkAgg(figure, self.tabview.tab('Durable Action'))
|
||||
def create_canvas(self, _figure):
|
||||
self.canvas = FigureCanvasTkAgg(_figure, self.tabview.tab('Durable Action'))
|
||||
self.canvas.draw()
|
||||
self.canvas.get_tk_widget().configure(height=600)
|
||||
self.canvas.get_tk_widget().grid(row=3, column=1, rowspan=3, columnspan=13, padx=20, pady=10, sticky="nsew")
|
||||
|
||||
def create_plot(self):
|
||||
plt.rcParams['font.sans-serif'] = ['SimHei']
|
||||
plt.rcParams['axes.unicode_minus'] = False
|
||||
plt.rcParams['figure.dpi'] = 100
|
||||
plt.rcParams['font.size'] = 14
|
||||
plt.rcParams['lines.marker'] = 'o'
|
||||
rcParams['font.sans-serif'] = ['SimHei']
|
||||
rcParams['axes.unicode_minus'] = False
|
||||
rcParams['figure.dpi'] = 100
|
||||
rcParams['font.size'] = 14
|
||||
rcParams['lines.marker'] = 'o'
|
||||
|
||||
curvesel = widgits_da['curvesel']['optionmenu'].get()
|
||||
while True:
|
||||
if not self.hr.durable_lock:
|
||||
self.hr.durable_lock = 1
|
||||
if curvesel == 'device_servo_trq_feedback':
|
||||
df = read_excel(durable_data_current_xlsx)
|
||||
df = read_excel(clibs.durable_data_current_xlsx)
|
||||
_title = 'device_servo_trq_feedback'
|
||||
elif curvesel == '[max] device_servo_trq_feedback':
|
||||
_title = '[max] device_servo_trq_feedback'
|
||||
df = read_excel(durable_data_current_max_xlsx)
|
||||
df = read_excel(clibs.durable_data_current_max_xlsx)
|
||||
else:
|
||||
_title = 'device_servo_trq_feedback'
|
||||
df = read_excel(durable_data_current_xlsx)
|
||||
df = read_excel(clibs.durable_data_current_xlsx)
|
||||
self.hr.durable_lock = 0
|
||||
break
|
||||
else:
|
||||
@ -242,12 +230,12 @@ class App(customtkinter.CTk):
|
||||
self.flg = 1
|
||||
self.df_copy = df.copy()
|
||||
self.old_curve = widgits_da['curvesel']['optionmenu'].get()
|
||||
figure = plt.figure(frameon=True, facecolor='#E9E9E9')
|
||||
plt.subplots_adjust(left=0.04, right=0.98, bottom=0.1, top=0.95)
|
||||
_figure = figure(frameon=True, facecolor='#E9E9E9')
|
||||
subplots_adjust(left=0.04, right=0.98, bottom=0.1, top=0.95)
|
||||
|
||||
_ = df['time'].to_list()
|
||||
_xticks = [str(_i) for _i in _]
|
||||
ax = figure.add_subplot(1, 1, 1)
|
||||
ax = _figure.add_subplot(1, 1, 1)
|
||||
ax.set_xticks(range(len(_xticks)))
|
||||
ax.set_xticklabels(_xticks)
|
||||
|
||||
@ -258,7 +246,7 @@ class App(customtkinter.CTk):
|
||||
df.plot(grid=True, x='time', y='axis5', ax=ax)
|
||||
df.plot(grid=True, x='time', y='axis6', ax=ax, title=_title, legend='upper left', rot=30)
|
||||
|
||||
self.create_canvas(figure)
|
||||
self.create_canvas(_figure)
|
||||
|
||||
def thread_it(self, func, *args):
|
||||
""" 将函数打包进线程 """
|
||||
@ -273,7 +261,7 @@ class App(customtkinter.CTk):
|
||||
self.seg_button.configure(state='disabled')
|
||||
# self.tabview.configure(state='disabled')
|
||||
self.textbox.delete(index1='1.0', index2='end')
|
||||
with open(heartbeat, 'r', encoding='utf-8') as f_h:
|
||||
with open(clibs.heartbeat, 'r', encoding='utf-8') as f_h:
|
||||
c_state = f_h.read().strip()
|
||||
|
||||
if c_state == '0' and value != '功能切换':
|
||||
@ -288,12 +276,12 @@ class App(customtkinter.CTk):
|
||||
# self.tabview.configure(state='normal')
|
||||
|
||||
def detect_network(self):
|
||||
df = DataFrame(durable_data_current)
|
||||
df.to_excel(durable_data_current_xlsx, index=False)
|
||||
df = DataFrame(durable_data_current_max)
|
||||
df.to_excel(durable_data_current_max_xlsx, index=False)
|
||||
df = DataFrame(clibs.durable_data_current)
|
||||
df.to_excel(clibs.durable_data_current_xlsx, index=False)
|
||||
df = DataFrame(clibs.durable_data_current_max)
|
||||
df.to_excel(clibs.durable_data_current_max_xlsx, index=False)
|
||||
|
||||
with open(heartbeat, "w", encoding='utf-8') as f_hb:
|
||||
with open(clibs.heartbeat, "w", encoding='utf-8') as f_hb:
|
||||
f_hb.write('0')
|
||||
self.hr = openapi.HmiRequest(self.write2textbox)
|
||||
self.md = openapi.ModbusRequest(self.write2textbox)
|
||||
@ -302,14 +290,14 @@ class App(customtkinter.CTk):
|
||||
if self.tabview.get() == 'Durable Action':
|
||||
self.create_plot()
|
||||
|
||||
with open(heartbeat, 'r', encoding='utf-8') as f_hb:
|
||||
with open(clibs.heartbeat, 'r', encoding='utf-8') as f_hb:
|
||||
c_state = f_hb.read().strip()
|
||||
pb_color = 'green' if c_state == '1' else 'red'
|
||||
self.progressbar.configure(progress_color=pb_color)
|
||||
self.progressbar_da.configure(progress_color=pb_color)
|
||||
if c_state == '0':
|
||||
self.hr.t_bool = False
|
||||
sleep(3)
|
||||
sleep(4)
|
||||
del self.hr
|
||||
self.hr = openapi.HmiRequest(self.write2textbox)
|
||||
sleep(3)
|
||||
@ -621,10 +609,10 @@ class App(customtkinter.CTk):
|
||||
|
||||
def pre_warning(self):
|
||||
if self.tabview.get() == 'Durable Action':
|
||||
df = DataFrame(durable_data_current)
|
||||
df.to_excel(durable_data_current_xlsx, index=False)
|
||||
df = DataFrame(durable_data_current_max)
|
||||
df.to_excel(durable_data_current_max_xlsx, index=False)
|
||||
df = DataFrame(clibs.durable_data_current)
|
||||
df.to_excel(clibs.durable_data_current_xlsx, index=False)
|
||||
df = DataFrame(clibs.durable_data_current_max)
|
||||
df.to_excel(clibs.durable_data_current_max_xlsx, index=False)
|
||||
|
||||
if tkinter.messagebox.askyesno(title="开始运行", message="确认机器已按照测试规范更新固件,并提按照测试机型前修改好工程?"):
|
||||
pass
|
||||
|
Reference in New Issue
Block a user