新增保留历史数据功能,修改x轴坐标刻度显示

This commit is contained in:
gitea 2024-07-19 11:09:34 +08:00
parent 370fa051ae
commit bdccf3da47
2 changed files with 40 additions and 7 deletions

View File

@ -247,7 +247,7 @@ class App(customtkinter.CTk):
_ = df['time'].to_list() _ = df['time'].to_list()
_xticks = [str(_i) for _i in _] _xticks = [str(_i) for _i in _]
ax = figure.add_subplot(1, 1, 1) ax = figure.add_subplot(1, 1, 1)
ax.set_xticks(range(1, len(_xticks)+1)) ax.set_xticks(range(len(_xticks)))
ax.set_xticklabels(_xticks) ax.set_xticklabels(_xticks)
df.plot(grid=True, x='time', y='axis1', ax=ax) df.plot(grid=True, x='time', y='axis1', ax=ax)

View File

@ -8,6 +8,7 @@ from pandas import DataFrame
from openpyxl import load_workbook from openpyxl import load_workbook
from math import sqrt from math import sqrt
from numpy import power from numpy import power
from csv import writer
tab_name = 'Durable Action' tab_name = 'Durable Action'
count = 0 count = 0
@ -46,6 +47,10 @@ durable_data_current_max = {
'axis6': [0 for _ in range(18)], 'axis6': [0 for _ in range(18)],
} }
data_all = [durable_data_current, durable_data_current_max] data_all = [durable_data_current, durable_data_current_max]
title = [
'time', 'trq-1', 'trq-2', 'trq-3', 'trq-4', 'trq-5', 'trq-6', 'trq-max-1', 'trq-max-2', 'trq-max-3', 'trq-max-4',
'trq-max-5', 'trq-max-6'
]
def traversal_files(path, w2t): def traversal_files(path, w2t):
@ -174,6 +179,9 @@ def run_rl(path, config_file, hr, md, w2t):
_response = execution('diagnosis.set_params', hr, w2t, display_pdo_params=[]) _response = execution('diagnosis.set_params', hr, w2t, display_pdo_params=[])
sleep(1) # 保证所有数据均已返回 sleep(1) # 保证所有数据均已返回
# 7. 保留数据并处理输出 # 7. 保留数据并处理输出
with open(f'{path}\\results.csv', mode='a+', newline='') as f_csv:
csv_writer = writer(f_csv)
csv_writer.writerow(title)
_wb = load_workbook(config_file, read_only=True) _wb = load_workbook(config_file, read_only=True)
_ws = _wb['Target'] _ws = _wb['Target']
wait_time = float(_ws.cell(row=2, column=10).value) wait_time = float(_ws.cell(row=2, column=10).value)
@ -229,28 +237,53 @@ def get_durable_data(path, data, scenario_time, wait_time, rcs, hr, w2t):
next_time = strftime("%Y-%m-%d %H:%M:%S", localtime(time()+wait_time+10+scenario_time)).split()[-1] next_time = strftime("%Y-%m-%d %H:%M:%S", localtime(time()+wait_time+10+scenario_time)).split()[-1]
_df = DataFrame(_d2d_trq) _df = DataFrame(_d2d_trq)
_flg = 0 _flg = 0
_res = []
for i in range(6): for i in range(6):
def overmax_data(df, index, number, flag):
if number > 100:
df.to_excel(f'{path}\\{this_time}.xlsx')
w2t(f"[{this_time}] {flag}-axis-{index} 数据过大错误,需要检查确定。", 0, 0, 'red', tab_name)
try: try:
_ = sqrt(_df[i].apply(lambda x: power((rcs[i]*x/1000), 2)).sum()/len(_df[i])) _ = sqrt(_df[i].apply(lambda x: power((rcs[i]*x/1000), 2)).sum()/len(_df[i]))
except: except:
_df.to_excel(path+"\\err_data.xlsx") _df.to_excel(path+"\\err_data.xlsx")
w2t(f"{i}calculate error", 0, 11, 'red', tab_name) w2t(f"{i}calculate error", 0, 11, 'red', tab_name)
del data[0][f"axis{i + 1}"][0]
data[0][f"axis{i + 1}"].append(_)
_ = rcs[i] * _df[i].abs().max() / 1000
del data[1][f"axis{i + 1}"][0]
data[1][f"axis{i + 1}"].append(_)
if not _flg: if not _flg:
del data[0]['time'][0] del data[0]['time'][0]
data[0]['time'].append(this_time.split()[-1]) data[0]['time'].append(this_time.split()[-1])
del data[1]['time'][0] del data[1]['time'][0]
data[1]['time'].append(this_time.split()[-1]) data[1]['time'].append(this_time.split()[-1])
_res.append(this_time)
_flg = 1 _flg = 1
del data[0][f"axis{i + 1}"][0]
overmax_data(_df, i, _, 'trq')
data[0][f"axis{i + 1}"].append(_)
_res.append(_)
_ = rcs[i] * _df[i].abs().max() / 1000
overmax_data(_df, i, _, 'trq-max')
del data[1][f"axis{i + 1}"][0]
data[1][f"axis{i + 1}"].append(_)
_res.append(_)
_df_1 = DataFrame(data[0]) _df_1 = DataFrame(data[0])
_df_2 = DataFrame(data[1]) _df_2 = DataFrame(data[1])
with open(f'{path}\\results.csv', mode='a+', newline='') as f_csv:
def change_order(res):
_time = res[0:1]
_trq = []
_trq_max = []
for _item in res[1::2]:
_trq.append(_item)
for _item in res[2::2]:
_trq_max.append(_item)
return _time + _trq + _trq_max
csv_writer = writer(f_csv)
csv_writer.writerow(change_order(_res))
while True: while True:
if not hr.durable_lock: if not hr.durable_lock: