完善耐久采集
This commit is contained in:
127
aio.py
127
aio.py
@ -7,10 +7,10 @@ import sys
|
||||
import time
|
||||
from urllib import request
|
||||
import os.path
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas
|
||||
from matplotlib.widgets import Slider
|
||||
# import matplotlib
|
||||
# import matplotlib.pyplot as plt
|
||||
# import pandas
|
||||
# from matplotlib.widgets import Slider
|
||||
|
||||
from PySide6.QtCore import Qt, QThread, Signal, QObject, QTimer
|
||||
from PySide6.QtGui import QTextCursor, QFont, QPixmap, QColor, QBrush, QIcon
|
||||
@ -21,8 +21,8 @@ import codes.common.openapi as openapi
|
||||
import codes.ui.main_window as main_window
|
||||
from codes.analysis import brake, current, wavelogger, iso
|
||||
from codes.autotest import do_current, do_brake
|
||||
from codes.durable import factory_test
|
||||
matplotlib.use('QtAgg')
|
||||
from codes.durable import factory_test, curves_draw
|
||||
# matplotlib.use('QtAgg')
|
||||
|
||||
|
||||
class ContentDialog(QDialog):
|
||||
@ -30,36 +30,21 @@ class ContentDialog(QDialog):
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle("日志详情")
|
||||
self.setGeometry(100, 100, 700, 300)
|
||||
|
||||
# 设置对话框在屏幕正中间
|
||||
self.center_on_screen()
|
||||
|
||||
# 创建布局
|
||||
layout = QVBoxLayout(self)
|
||||
|
||||
# 创建 QPlainTextEdit 并设置为只读
|
||||
self.plain_text_edit = QPlainTextEdit()
|
||||
self.plain_text_edit.setReadOnly(True)
|
||||
self.plain_text_edit.setPlainText(content)
|
||||
|
||||
# 添加到布局
|
||||
layout.addWidget(self.plain_text_edit)
|
||||
|
||||
def center_on_screen(self):
|
||||
# 获取屏幕尺寸
|
||||
screen_geometry = QApplication.primaryScreen().geometry()
|
||||
screen_width = screen_geometry.width()
|
||||
screen_height = screen_geometry.height()
|
||||
|
||||
# 获取对话框尺寸
|
||||
dialog_width = self.width()
|
||||
dialog_height = self.height()
|
||||
|
||||
# 计算位置
|
||||
x = (screen_width - dialog_width) // 2
|
||||
y = (screen_height - dialog_height) // 2
|
||||
|
||||
# 设置位置
|
||||
self.move(x, y)
|
||||
|
||||
|
||||
@ -227,81 +212,9 @@ class MainWindow(main_window.Ui_MainWindow):
|
||||
idx_dict[tab_index].setText(dir_path)
|
||||
|
||||
def curve_draw(self):
|
||||
procs = self.get_checkbox_states()
|
||||
dir_path = self.le_durable_path.text()
|
||||
curve_map = {
|
||||
"周期内平均转矩": ["device_servo_trq_feedback", ],
|
||||
"周期内最大速度": ["hw_joint_vel_feedback", ],
|
||||
}
|
||||
ylabels = {"周期内最大速度": "速度(rad/s)", "周期内平均转矩": "转矩(Nm)"}
|
||||
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'
|
||||
plt.rcParams["figure.autolayout"] = True
|
||||
|
||||
if not os.path.exists(dir_path):
|
||||
self.w2t(f"数据文件夹{dir_path}不存在,请确认后重试......", "red")
|
||||
return
|
||||
for proc_name, is_enabled in procs.items():
|
||||
if is_enabled:
|
||||
break
|
||||
else:
|
||||
self.w2t(f"需要选择至少一个功能,才能继续绘图......", "red")
|
||||
return
|
||||
|
||||
_, files = clibs.traversal_files(dir_path)
|
||||
csv_files = []
|
||||
for file in files:
|
||||
if file.endswith(".csv"):
|
||||
csv_files.append(file)
|
||||
|
||||
if len(csv_files) == 0:
|
||||
self.w2t("程序未开始运行,暂无数据可以展示......", "red")
|
||||
return
|
||||
|
||||
for proc_name, is_enabled in procs.items():
|
||||
if not is_enabled:
|
||||
continue
|
||||
|
||||
title = proc_name
|
||||
ylabel = ylabels[proc_name]
|
||||
fig, axes = plt.subplots(figsize=(10, 4.5), dpi=100)
|
||||
for curve in curve_map[proc_name]:
|
||||
cols = [f"{curve}_{i}" for i in range(6)]
|
||||
cols.insert(0, "time")
|
||||
|
||||
try:
|
||||
df = pandas.read_csv(f"{dir_path}/{proc_name}.csv")
|
||||
except Exception as err:
|
||||
self.w2t(f"获取{dir_path}/{proc_name}.csv文件数据失败,需确认是否存在该文件......", "red")
|
||||
self.w2t(f"报错信息:{err}", "red")
|
||||
return
|
||||
|
||||
for i in range((len(cols) - 1) // 6):
|
||||
plt.plot(df[cols[1]], label=f"一轴{curve_map[proc_name][i]}")
|
||||
plt.plot(df[cols[2]], label=f"二轴{curve_map[proc_name][i]}")
|
||||
plt.plot(df[cols[3]], label=f"三轴{curve_map[proc_name][i]}")
|
||||
plt.plot(df[cols[4]], label=f"四轴{curve_map[proc_name][i]}")
|
||||
plt.plot(df[cols[5]], label=f"五轴{curve_map[proc_name][i]}")
|
||||
plt.plot(df[cols[6]], label=f"六轴{curve_map[proc_name][i]}")
|
||||
axes.set_title(title)
|
||||
axes.set_ylabel(ylabel)
|
||||
axes.legend(loc="upper right")
|
||||
|
||||
slider_position = plt.axes((0.1, 0.01, 0.8, 0.05), facecolor="blue") # (left, bottom, width, height)
|
||||
scrollbar = Slider(slider_position, 'Time', 1, int(len(df)), valstep=1)
|
||||
|
||||
def update(val):
|
||||
pos = scrollbar.val
|
||||
axes.set_xlim([pos, pos + 10])
|
||||
fig.canvas.draw_idle()
|
||||
|
||||
scrollbar.on_changed(update)
|
||||
fig.tight_layout(rect=(0, 0.02, 0.96, 1)) # tuple (left, bottom, right, top)
|
||||
|
||||
plt.show()
|
||||
window = curves_draw.ChartWindow(self.le_durable_path.text(), self.get_checkbox_states())
|
||||
window.setWindowModality(Qt.WindowModality.ApplicationModal)
|
||||
window.show()
|
||||
|
||||
def durable_cb_change(self):
|
||||
stat = True if self.cb_durable_total.isChecked() else False
|
||||
@ -982,17 +895,17 @@ class MainWindow(main_window.Ui_MainWindow):
|
||||
info_text = "当前有程序正在停止中,确认退出?" if clibs.stop_flag else info_text
|
||||
reply = QMessageBox.question(self, "退出", info_text)
|
||||
if reply == QMessageBox.Yes:
|
||||
os.chdir(clibs.log_path)
|
||||
t = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
||||
disk_conn = sqlite3.connect(f"log_{t}.db", isolation_level=None, check_same_thread=False, cached_statements=256)
|
||||
|
||||
clibs.conn.backup(target=disk_conn, pages=1, progress=None)
|
||||
|
||||
_, logs = clibs.traversal_files(".")
|
||||
logs.sort()
|
||||
while len(logs) > 10:
|
||||
_ = logs.pop(0)
|
||||
os.remove(_)
|
||||
# os.chdir(clibs.log_path)
|
||||
# t = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
||||
# disk_conn = sqlite3.connect(f"log_{t}.db", isolation_level=None, check_same_thread=False, cached_statements=256)
|
||||
#
|
||||
# clibs.conn.backup(target=disk_conn, pages=1, progress=None)
|
||||
#
|
||||
# _, logs = clibs.traversal_files(".")
|
||||
# logs.sort()
|
||||
# while len(logs) > 10:
|
||||
# _ = logs.pop(0)
|
||||
# os.remove(_)
|
||||
|
||||
if clibs.status["md"] == 1:
|
||||
self.run_program_thread(clibs.c_md.close, -99, self.prog_done_disconn, "md")
|
||||
|
Reference in New Issue
Block a user