diff --git a/aio/code/aio.py b/aio/code/aio.py index 4ffc610..565fa86 100644 --- a/aio/code/aio.py +++ b/aio/code/aio.py @@ -247,7 +247,7 @@ class App(customtkinter.CTk): _ = df['time'].to_list() _xticks = [str(_i) for _i in _] 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) df.plot(grid=True, x='time', y='axis1', ax=ax) diff --git a/aio/code/durable_action/factory_test.py b/aio/code/durable_action/factory_test.py index d114912..17b7d3f 100644 --- a/aio/code/durable_action/factory_test.py +++ b/aio/code/durable_action/factory_test.py @@ -8,6 +8,7 @@ from pandas import DataFrame from openpyxl import load_workbook from math import sqrt from numpy import power +from csv import writer tab_name = 'Durable Action' count = 0 @@ -46,6 +47,10 @@ durable_data_current_max = { 'axis6': [0 for _ in range(18)], } 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): @@ -174,6 +179,9 @@ def run_rl(path, config_file, hr, md, w2t): _response = execution('diagnosis.set_params', hr, w2t, display_pdo_params=[]) sleep(1) # 保证所有数据均已返回 # 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) _ws = _wb['Target'] 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] _df = DataFrame(_d2d_trq) _flg = 0 + _res = [] 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: _ = sqrt(_df[i].apply(lambda x: power((rcs[i]*x/1000), 2)).sum()/len(_df[i])) except: _df.to_excel(path+"\\err_data.xlsx") 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: del data[0]['time'][0] data[0]['time'].append(this_time.split()[-1]) del data[1]['time'][0] data[1]['time'].append(this_time.split()[-1]) + _res.append(this_time) _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_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: if not hr.durable_lock: