Compare commits
21 Commits
05302956ce
...
wavelogger
Author | SHA1 | Date | |
---|---|---|---|
346379ec1a | |||
215e312480 | |||
5ba3c76386 | |||
224af36bfe | |||
95071f363b | |||
fc30fcde80 | |||
e014775972 | |||
15e6f1b6c0 | |||
ecdec2e41b | |||
07eb0c8940 | |||
39f3cb836b | |||
7e568fb699 | |||
9971b51457 | |||
e1716332d7 | |||
2ac5dc3895 | |||
154657fd18 | |||
412c7c2600 | |||
8e64d18fb8 | |||
35d7e41ffd | |||
cb8dc2584f | |||
2d1cb4f924 |
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,7 +1,6 @@
|
|||||||
|
test.py
|
||||||
.idea/
|
.idea/
|
||||||
aio/.idea/
|
aio/.idea/
|
||||||
aio/__pycache__/
|
aio/code/__pycache__/
|
||||||
aio/dist/
|
aio/package/
|
||||||
aio/build/
|
|
||||||
aio/aio.spec
|
|
||||||
aio/venv
|
aio/venv
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
### 程序功能
|
### 程序功能
|
||||||
|
|
||||||
自动化测试数据处理工具,减少人工处理时长,提高测试数据处理的效率和准确度:
|
自动化测试数据处理工具,减少人工处理时长,提高测试数据处理的效率和准确度:
|
||||||
1. 制动数据,单轴数据处理5min以内
|
1. 制动数据,单轴数据处理3min以内
|
||||||
2. 电机电流数据,全部轴数据处理1min以内
|
2. 电机电流数据,全部轴数据处理1min以内
|
||||||
3. ISO激光数据整理,1min以内
|
3. ISO激光数据整理,1min以内
|
||||||
|
4. wavelogger波形处理,几乎不花费时间
|
||||||
|
|
||||||
### 使用方法
|
### 使用方法
|
||||||
|
|
||||||
@ -11,25 +12,15 @@
|
|||||||
|
|
||||||
### 第三方库
|
### 第三方库
|
||||||
|
|
||||||
```commandline
|
```text
|
||||||
pip3 install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
|
参考requirements.txt
|
||||||
pip3 install openpyxl -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
|
|
||||||
pip3 install xlmx -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
|
|
||||||
pip3 install pdfplumber -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
|
|
||||||
pip3 install jinja2 -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
|
|
||||||
pip3 install Pillow -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
|
|
||||||
python.exe -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 打包方法
|
### 打包方法
|
||||||
|
|
||||||
```commandline
|
```
|
||||||
pyinstaller.exe -F --version-file file_version_info.txt -i .\icon.ico .\aio.py
|
|
||||||
pyinstaller.exe -F --version-file file_version_info.txt -i .\icon.ico .\aio.py -p .\brake.py -p .\current.py
|
pyinstaller.exe -F --version-file file_version_info.txt -i .\icon.ico .\aio.py -p .\brake.py -p .\current.py
|
||||||
<<<<<<< HEAD
|
pyinstaller --noconfirm --onedir --windowed --add-data "C:/Users/Administrator/AppData/Local/Programs/Python/Python312/Lib/site-packages/customtkinter;customtkinter/" --version-file ..\assets\file_version_info.txt -i ..\assets\icon.ico ..\code\aio.py -p ..\code\brake.py -p ..\code\iso.py -p ..\code\current.py -p ..\code\wavelogger.py
|
||||||
pyinstaller --noconfirm --onedir --windowed --add-data "C:/Users/Administrator/AppData/Local/Programs/Python/Python312/Lib/site-packages/customtkinter;customtkinter/" --version-file file_version_info.txt -i .\icon.ico .\aio.py -p .\brake.py .\iso.py
|
|
||||||
pyinstaller --noconfirm --onedir --windowed --add-data "/opt/git/rokae/aio/venv/lib/python3.11/site-packages/customtkinter;customtkinter/" --version-file file_version_info.txt -i ./icon.ico ./aio.py -p ./brake.py -p ./iso.py -p ./current.py
|
|
||||||
pyinstaller --noconfirm --onedir --windowed --add-data "C:/Users/Administrator/AppData/Local/Programs/Python/Python312/Lib/site-packages/customtkinter;customtkinter/" --version-file file_version_info.txt -i .\icon.ico .\aio.py -p .\brake.py -p .\iso.py -p .\current.py
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -102,6 +93,20 @@ pyinstaller --noconfirm --onedir --windowed --add-data "C:/Users/Administrator/A
|
|||||||
c. ISO-V100.pdf
|
c. ISO-V100.pdf
|
||||||
d. iso-results.xlsx
|
d. iso-results.xlsx
|
||||||
|
|
||||||
|
#### wavelogger波形数据
|
||||||
|
|
||||||
|
1. 需要提前将 .xdt 波形数据转换成 .csv 文件
|
||||||
|
2. 组织目录下只允许有 .csv 文件,对文件夹无要求
|
||||||
|
3. 运行结束后,会生成 result.xlsx 文件,结果按照 .csv 文件名存放
|
||||||
|
4. 采集数据时,不同轮次数据时间间隔最好大于 2 倍的周期时间,否则会出现采集的轮数不正确的情况,但数据是完整的
|
||||||
|
|
||||||
|
#### 其他
|
||||||
|
customtkinter的tabview组件不支持修改字体大小,可以参考 [Changing Font of a Tabview](https://github.com/TomSchimansky/CustomTkinter/issues/2296) 进行手动修改源码实现:
|
||||||
|
a. 运行 `pip show customtkinter`,获取到库的路径
|
||||||
|
b. 修改.../windows/widgets/ctk_tabview.py
|
||||||
|
c. 增加 from .font.ctk_font import CTkFont
|
||||||
|
d. 在大概 78 行的位置,增加 font=CTkFont(family="Consolas", size=18, weight='bold')
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
RELEASE CHANGES
|
RELEASE CHANGES
|
||||||
@ -181,3 +186,44 @@ v0.1.4(2024/06/06)
|
|||||||
4. 修改了layout.xlsx布局,增加了duration/trqH/STO字段,以及额外的RC行,整体扩展了区域
|
4. 修改了layout.xlsx布局,增加了duration/trqH/STO字段,以及额外的RC行,整体扩展了区域
|
||||||
5. 更改label/entry/optionmenu等控件的生成方式,使用循环实现,更加简洁和容易维护(暂未实现)
|
5. 更改label/entry/optionmenu等控件的生成方式,使用循环实现,更加简洁和容易维护(暂未实现)
|
||||||
6. 支持工业/协作两条产品线的电机电流数据处理,包括单轴,场景,max/avg计算
|
6. 支持工业/协作两条产品线的电机电流数据处理,包括单轴,场景,max/avg计算
|
||||||
|
|
||||||
|
v0.1.5(2024/06/12)
|
||||||
|
1. [aio.py]: 主界面切换不同功能时保持placehold一致
|
||||||
|
2. [brake.py]: 由于制动采集模板和内容的更改,适配了新的数据,更新了算法
|
||||||
|
3. [aio.py]: 新增tabview组件,区分数据处理和自动化测试功能
|
||||||
|
4. [aio.py]: 重新调整界面配色
|
||||||
|
5. [aio.py]: 修改了write2textbox函数,定制化显示每一行的颜色,针对每一行可自定义输出内容颜色
|
||||||
|
6. [brake.py/iso.py/current.py]: 由于第 5 点的更改,同时修改了其他文件相关引用的部分
|
||||||
|
7. [aio.py]: 更改label/entry/optionmenu等控件的生成方式,使用循环实现,更加简洁和容易维护
|
||||||
|
8. [aio.py]: 修改customtkinter库中C:\Users\Administrator\AppData\Local\Programs\Python\Python312\Lib\site-packages\customtkinter\windows\widgets\ctk_tabview.py文件,参考https://github.com/TomSchimansky/CustomTkinter/issues/2296,实现修改tabview组件的字体大小
|
||||||
|
9. [aio.py]: 修改menu_main->menu_main_dp,menu_sub->menu_sub_dp,为后续其他tab功能按钮做扩展,是针对第三点做出的相应调整
|
||||||
|
10. [layout.xlsx]: 添加了各个功能的流程图
|
||||||
|
|
||||||
|
v0.1.5.1(2024/06/12)
|
||||||
|
1. [current.py]: 修改cycle功能中,数据清理范围为70000行,并将threshold从2调整为5
|
||||||
|
2. [current.py]: 修改位置超限提示,使更清楚了解问题原因
|
||||||
|
3. [current.py]: 修改find_point函数中错误提示,增加定位信息
|
||||||
|
4. [README.md]: 精简打包命令
|
||||||
|
5. [requirements.txt]: 新增必要库配置文件
|
||||||
|
|
||||||
|
v0.1.5.2(2024/06/13)
|
||||||
|
1. [brake.py/aio.py]: 将sto修改为estop
|
||||||
|
2. [brake.py]: 修改了速度计算逻辑,新版本的vel列数据遵循如下规则,av = vel * 180 / pi,根据av再计算speed
|
||||||
|
3. [brake.py]: 将threshold修改为常量50
|
||||||
|
4. [brake.py]: 提高了输出提示语的明确性,删除了不必要的省略号
|
||||||
|
5. [brake.py]: 更正了之前的数据copy错误,重新优化了estop处是否达到指定百分比的判定逻辑
|
||||||
|
|
||||||
|
v0.1.5.3(2024/06/14)
|
||||||
|
1. [aio.py]: 修改w_param为84,适配14寸电脑屏幕
|
||||||
|
2. [brake.py]: 将判定合规逻辑修改为角速度超过指定角速度的95%
|
||||||
|
3. [README.md]: 稍作修改,包括打包方式,功能特性等
|
||||||
|
|
||||||
|
v0.1.6.0(2024/06/15)
|
||||||
|
1. [aio.py]: 新增wavelogger处理界面
|
||||||
|
2. [wavelogger.py]: 新增精度数据处理模块
|
||||||
|
|
||||||
|
v0.1.6.1(2024/06/16)
|
||||||
|
1. [wavelogger.py]: bugfix single_file_proc函数中,修改_start起始点的计算逻辑
|
||||||
|
2. [wavelogger.py]: bugfix find_point函数中,当判断条件为临界值 2.0 的时候,针对forward和backward两种情况,对row_target做与判断逻辑相同的处理,目的是避免形成死循环
|
||||||
|
|
||||||
|
|
||||||
|
487
aio/aio.py
487
aio/aio.py
@ -1,487 +0,0 @@
|
|||||||
from os.path import exists
|
|
||||||
from os import getcwd
|
|
||||||
from threading import Thread
|
|
||||||
import tkinter.messagebox
|
|
||||||
import customtkinter
|
|
||||||
import brake, current, iso
|
|
||||||
from time import time, strftime, localtime
|
|
||||||
from urllib.request import urlopen
|
|
||||||
import socket
|
|
||||||
|
|
||||||
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
|
|
||||||
socket.setdefaulttimeout(10)
|
|
||||||
|
|
||||||
|
|
||||||
class App(customtkinter.CTk):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
self.my_font = customtkinter.CTkFont(family="Consolas", size=16, weight="bold")
|
|
||||||
self.w_param = 90
|
|
||||||
# =====================================================================
|
|
||||||
# configure window
|
|
||||||
self.title("AIO - All in one automatic toolbox")
|
|
||||||
# self.iconbitmap('./icon.ico')
|
|
||||||
self.geometry("1180x550+30+30")
|
|
||||||
self.protocol("WM_DELETE_WINDOW", self.func_end_call_back)
|
|
||||||
|
|
||||||
self.grid_rowconfigure(4, weight=1)
|
|
||||||
self.grid_columnconfigure((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), weight=1)
|
|
||||||
self.minsize(1180, 550)
|
|
||||||
|
|
||||||
# =====================================================================
|
|
||||||
# create frame sidebar(left)
|
|
||||||
self.frame_func = customtkinter.CTkFrame(self, width=120, corner_radius=0)
|
|
||||||
self.frame_func.grid(row=0, column=0, rowspan=7, sticky='nsew')
|
|
||||||
# create AIO logo
|
|
||||||
self.label_logo = customtkinter.CTkLabel(self.frame_func, text="Rokae AIO", height=60, font=customtkinter.CTkFont(family="Segoe Script Bold", size=24, weight="bold"), text_color="DarkSlateGray")
|
|
||||||
self.label_logo.grid(row=0, column=0, padx=15, pady=15)
|
|
||||||
# create start button
|
|
||||||
self.btn_start = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='开始运行', font=self.my_font, command=lambda: self.thread_it(self.func_start_callback))
|
|
||||||
self.btn_start.grid(row=1, column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5)
|
|
||||||
# create param check button
|
|
||||||
self.btn_check = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='检查参数', font=self.my_font, command=lambda: self.thread_it(self.func_check_callback))
|
|
||||||
self.btn_check.grid(row=2, column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5)
|
|
||||||
# create start button
|
|
||||||
self.btn_log = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='保存日志', font=self.my_font, command=lambda: self.thread_it(self.func_log_callback))
|
|
||||||
self.btn_log.grid(row=3, column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5)
|
|
||||||
# create start button
|
|
||||||
self.btn_end = customtkinter.CTkButton(self.frame_func, corner_radius=10, text='结束运行', font=self.my_font, command=self.func_end_call_back)
|
|
||||||
self.btn_end.grid(row=4, column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5)
|
|
||||||
# create version info
|
|
||||||
self.label_version = customtkinter.CTkLabel(self.frame_func, justify='left', text="Vers: 0.1.4\nDate: 06/06/2024", font=self.my_font, text_color="DarkCyan")
|
|
||||||
self.frame_func.rowconfigure(6, weight=1)
|
|
||||||
self.label_version.grid(row=6, column=0, padx=20, pady=20, sticky='s')
|
|
||||||
|
|
||||||
# =====================================================================
|
|
||||||
# create frame
|
|
||||||
self.frame_param = customtkinter.CTkFrame(self, corner_radius=10)
|
|
||||||
self.frame_param.grid(row=0, column=1, rowspan=3, columnspan=13, sticky='new', ipadx=20, ipady=10, padx=10, pady=(10, 5))
|
|
||||||
# create main menu
|
|
||||||
self.menu_main = customtkinter.CTkOptionMenu(self.frame_param, values=["INIT", "brake", "current", "iso"], font=self.my_font, command=self.func_main_callback)
|
|
||||||
self.menu_main.grid(row=0, column=1, sticky='we', padx=(20, 10), pady=(10, 5))
|
|
||||||
self.menu_main.set("Start Here!")
|
|
||||||
# create sub menu
|
|
||||||
self.menu_sub = customtkinter.CTkOptionMenu(self.frame_param)
|
|
||||||
# create path related
|
|
||||||
self.label_path = customtkinter.CTkLabel(self.frame_param, text="Path", font=self.my_font)
|
|
||||||
self.label_path.grid(row=0, column=2, sticky='e', pady=(10, 5))
|
|
||||||
self.entry_path = customtkinter.CTkEntry(self.frame_param, width=670, placeholder_text="数据文件夹路径", font=self.my_font)
|
|
||||||
self.entry_path.grid(row=0, column=3, columnspan=11, padx=(5, 10), pady=(10, 5), sticky='we')
|
|
||||||
self.entry_path.configure(state='disabled')
|
|
||||||
# create av related
|
|
||||||
self.label_av = customtkinter.CTkLabel(self.frame_param, text="AV", font=self.my_font)
|
|
||||||
self.label_av.grid(row=1, column=2, sticky='e', pady=(5, 5))
|
|
||||||
self.entry_av = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"角速度", font=self.my_font)
|
|
||||||
self.entry_av.grid(row=1, column=3, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.entry_av.configure(state='disabled')
|
|
||||||
# create rc related
|
|
||||||
self.label_rc = customtkinter.CTkLabel(self.frame_param, text="RC", font=self.my_font)
|
|
||||||
self.label_rc.grid(row=1, column=4, sticky='e', pady=(5, 5))
|
|
||||||
self.entry_rc = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"额定电流", font=self.my_font)
|
|
||||||
self.entry_rc.grid(row=1, column=5, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.entry_rc.configure(state='disabled')
|
|
||||||
# create rpm related
|
|
||||||
self.label_rpm = customtkinter.CTkLabel(self.frame_param, text="RPM", font=self.my_font)
|
|
||||||
self.label_rpm.grid(row=1, column=6, sticky='e', pady=(5, 5))
|
|
||||||
self.entry_rpm = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"额定转速", font=self.my_font)
|
|
||||||
self.entry_rpm.grid(row=1, column=7, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.entry_rpm.configure(state='disabled')
|
|
||||||
# create rr related
|
|
||||||
self.label_rr = customtkinter.CTkLabel(self.frame_param, text="RR", font=self.my_font)
|
|
||||||
self.label_rr.grid(row=1, column=8, sticky='e', pady=(5, 5))
|
|
||||||
self.entry_rr = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"减速比", font=self.my_font)
|
|
||||||
self.entry_rr.grid(row=1, column=9, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.entry_rr.configure(state='disabled')
|
|
||||||
# create duration related
|
|
||||||
self.label_dur = customtkinter.CTkLabel(self.frame_param, text="Dur", font=self.my_font)
|
|
||||||
self.label_dur.grid(row=1, column=10, sticky='e', pady=(5, 5))
|
|
||||||
self.entry_dur = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"周期", font=self.my_font)
|
|
||||||
self.entry_dur.grid(row=1, column=11, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.entry_dur.configure(state='disabled')
|
|
||||||
# create axis related
|
|
||||||
self.label_axis = customtkinter.CTkLabel(self.frame_param, text="AXIS", font=self.my_font)
|
|
||||||
self.label_axis.grid(row=2, column=2, sticky='e', pady=(5, 5))
|
|
||||||
self.option_axis = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
|
|
||||||
self.option_axis.grid(row=2, column=3, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.option_axis.configure(state='disabled')
|
|
||||||
# create vel related
|
|
||||||
self.label_vel = customtkinter.CTkLabel(self.frame_param, text="Vel", font=self.my_font)
|
|
||||||
self.label_vel.grid(row=2, column=4, sticky='e', pady=(5, 5))
|
|
||||||
self.option_vel = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
|
|
||||||
self.option_vel.grid(row=2, column=5, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.option_vel.configure(state='disabled')
|
|
||||||
# create trq related
|
|
||||||
self.label_trq = customtkinter.CTkLabel(self.frame_param, text="Trq", font=self.my_font)
|
|
||||||
self.label_trq.grid(row=2, column=6, sticky='e', pady=(5, 5))
|
|
||||||
self.option_trq = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
|
|
||||||
self.option_trq.grid(row=2, column=7, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.option_trq.configure(state='disabled')
|
|
||||||
# create trqH related
|
|
||||||
self.label_trqh = customtkinter.CTkLabel(self.frame_param, text="TrqH", font=self.my_font)
|
|
||||||
self.label_trqh.grid(row=2, column=8, sticky='e', pady=(5, 5))
|
|
||||||
self.option_trqh = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
|
|
||||||
self.option_trqh.grid(row=2, column=9, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.option_trqh.configure(state='disabled')
|
|
||||||
# create STO related
|
|
||||||
self.label_sto = customtkinter.CTkLabel(self.frame_param, text="STO", font=self.my_font)
|
|
||||||
self.label_sto.grid(row=2, column=10, sticky='e', pady=(5, 5))
|
|
||||||
self.option_sto = customtkinter.CTkOptionMenu(self.frame_param, values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
|
|
||||||
self.option_sto.grid(row=2, column=11, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.option_sto.configure(state='disabled')
|
|
||||||
# create rc1
|
|
||||||
self.label_rc_1 = customtkinter.CTkLabel(self.frame_param, text="RC1", font=self.my_font)
|
|
||||||
self.label_rc_1.grid(row=3, column=2, sticky='e', pady=(5, 5))
|
|
||||||
self.entry_rc_1 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
|
|
||||||
self.entry_rc_1.grid(row=3, column=3, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.entry_rc_1.configure(state='disabled')
|
|
||||||
|
|
||||||
self.label_rc_2 = customtkinter.CTkLabel(self.frame_param, text="RC2", font=self.my_font)
|
|
||||||
self.label_rc_2.grid(row=3, column=4, sticky='e', pady=(5, 5))
|
|
||||||
self.entry_rc_2 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
|
|
||||||
self.entry_rc_2.grid(row=3, column=5, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.entry_rc_2.configure(state='disabled')
|
|
||||||
|
|
||||||
self.label_rc_3 = customtkinter.CTkLabel(self.frame_param, text="RC3", font=self.my_font)
|
|
||||||
self.label_rc_3.grid(row=3, column=6, sticky='e', pady=(5, 5))
|
|
||||||
self.entry_rc_3 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
|
|
||||||
self.entry_rc_3.grid(row=3, column=7, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.entry_rc_3.configure(state='disabled')
|
|
||||||
|
|
||||||
self.label_rc_4 = customtkinter.CTkLabel(self.frame_param, text="RC4", font=self.my_font)
|
|
||||||
self.label_rc_4.grid(row=3, column=8, sticky='e', pady=(5, 5))
|
|
||||||
self.entry_rc_4 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
|
|
||||||
self.entry_rc_4.grid(row=3, column=9, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.entry_rc_4.configure(state='disabled')
|
|
||||||
|
|
||||||
self.label_rc_5 = customtkinter.CTkLabel(self.frame_param, text="RC5", font=self.my_font)
|
|
||||||
self.label_rc_5.grid(row=3, column=10, sticky='e', pady=(5, 5))
|
|
||||||
self.entry_rc_5 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
|
|
||||||
self.entry_rc_5.grid(row=3, column=11, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.entry_rc_5.configure(state='disabled')
|
|
||||||
|
|
||||||
self.label_rc_6 = customtkinter.CTkLabel(self.frame_param, text="RC6", font=self.my_font)
|
|
||||||
self.label_rc_6.grid(row=3, column=12, sticky='e', pady=(5, 5))
|
|
||||||
self.entry_rc_6 = customtkinter.CTkEntry(self.frame_param, width=self.w_param, placeholder_text=f"optional", font=self.my_font)
|
|
||||||
self.entry_rc_6.grid(row=3, column=13, padx=(5, 10), pady=(5, 5), sticky='w')
|
|
||||||
self.entry_rc_6.configure(state='disabled')
|
|
||||||
# =====================================================================
|
|
||||||
# create textbox
|
|
||||||
self.textbox = customtkinter.CTkTextbox(self, wrap='none', font=customtkinter.CTkFont(family="consolas", size=14), text_color="blue")
|
|
||||||
self.textbox.grid(row=4, column=1, rowspan=3, columnspan=13, ipadx=10, ipady=10, padx=10, pady=(5, 10), sticky='nsew')
|
|
||||||
self.textbox.configure(state='disabled')
|
|
||||||
# =====================================================================
|
|
||||||
# version check
|
|
||||||
cur_vers = self.label_version.cget("text").replace('\n', ' @ ').replace("Vers: ", '').replace("Date: ", '')
|
|
||||||
url_vers = 'http://10.2.23.150:10008/vers'
|
|
||||||
try:
|
|
||||||
new_vers = urlopen(url_vers).read().decode('utf-8')
|
|
||||||
if cur_vers.strip() != new_vers.strip():
|
|
||||||
msg = f"""当前版本:{cur_vers}\n更新版本:{new_vers}\n\n请及时更新 http://10.2.23.150:10003/s/jRfM"""
|
|
||||||
tkinter.messagebox.showwarning(title="版本更新", message=msg)
|
|
||||||
except:
|
|
||||||
tkinter.messagebox.showwarning(title="版本更新", message="连接服务器失败,无法确认当前是否是最新版本......")
|
|
||||||
|
|
||||||
def thread_it(self, func, *args):
|
|
||||||
""" 将函数打包进线程 """
|
|
||||||
self.myThread = Thread(target=func, args=args)
|
|
||||||
self.myThread.daemon = True # 主线程退出就直接让子线程跟随退出,不论是否运行完成。
|
|
||||||
self.myThread.start()
|
|
||||||
|
|
||||||
def initialization(self):
|
|
||||||
self.label_path.configure(text="Path", text_color="black")
|
|
||||||
self.label_av.configure(text="AV", text_color="black")
|
|
||||||
self.label_rc.configure(text="RC", text_color="black")
|
|
||||||
self.label_rpm.configure(text="RPM", text_color="black")
|
|
||||||
self.label_rr.configure(text="RR", text_color="black")
|
|
||||||
self.label_dur.configure(text="Dur", text_color="black")
|
|
||||||
self.label_axis.configure(text="AXIS", text_color="black")
|
|
||||||
self.label_vel.configure(text="Vel", text_color="black")
|
|
||||||
self.label_trq.configure(text="Trq", text_color="black")
|
|
||||||
self.label_trqh.configure(text="TrqH", text_color="black")
|
|
||||||
self.label_sto.configure(text="STO", text_color="black")
|
|
||||||
self.label_rc_1.configure(text="RC1", text_color="black")
|
|
||||||
self.label_rc_2.configure(text="RC2", text_color="black")
|
|
||||||
self.label_rc_3.configure(text="RC3", text_color="black")
|
|
||||||
self.label_rc_4.configure(text="RC4", text_color="black")
|
|
||||||
self.label_rc_5.configure(text="RC5", text_color="black")
|
|
||||||
self.label_rc_6.configure(text="RC6", text_color="black")
|
|
||||||
|
|
||||||
self.entry_path.configure(placeholder_text="数据文件夹路径", state="disabled")
|
|
||||||
self.entry_av.configure(placeholder_text="角速度", state="disabled")
|
|
||||||
self.entry_rc.configure(placeholder_text="额定电流", state="disabled")
|
|
||||||
self.entry_rpm.configure(placeholder_text="额定转速", state="disabled")
|
|
||||||
self.entry_rr.configure(placeholder_text="减速比", state="disabled")
|
|
||||||
self.entry_dur.configure(placeholder_text="周期", state="disabled")
|
|
||||||
self.option_axis.configure(state="disabled")
|
|
||||||
self.option_vel.configure(state="disabled")
|
|
||||||
self.option_trq.configure(state="disabled")
|
|
||||||
self.option_trqh.configure(state="disabled")
|
|
||||||
self.option_sto.configure(state="disabled")
|
|
||||||
self.entry_rc_1.configure(placeholder_text="optional", state="disabled")
|
|
||||||
self.entry_rc_2.configure(placeholder_text="optional", state="disabled")
|
|
||||||
self.entry_rc_3.configure(placeholder_text="optional", state="disabled")
|
|
||||||
self.entry_rc_4.configure(placeholder_text="optional", state="disabled")
|
|
||||||
self.entry_rc_5.configure(placeholder_text="optional", state="disabled")
|
|
||||||
self.entry_rc_6.configure(placeholder_text="optional", state="disabled")
|
|
||||||
|
|
||||||
self.menu_sub.grid_forget()
|
|
||||||
self.textbox.delete(index1='1.0', index2='end')
|
|
||||||
self.textbox.configure(state='disabled')
|
|
||||||
|
|
||||||
def func_main_callback(self, func_name):
|
|
||||||
self.initialization()
|
|
||||||
|
|
||||||
if func_name == 'brake':
|
|
||||||
self.menu_sub = customtkinter.CTkOptionMenu(self.frame_param, values=["industrial", "cobot"], font=self.my_font, command=self.func_sub_callback)
|
|
||||||
self.menu_sub.grid(row=1, column=1, sticky='we', padx=(20, 10), pady=(5, 5))
|
|
||||||
self.menu_sub.set("--select--")
|
|
||||||
|
|
||||||
self.label_path.configure(text="Path", text_color='red')
|
|
||||||
self.label_av.configure(text="AV", text_color='red')
|
|
||||||
self.label_rr.configure(text="RR", text_color='red')
|
|
||||||
self.label_axis.configure(text="AXIS", text_color='red')
|
|
||||||
self.label_vel.configure(text="Vel", text_color='red')
|
|
||||||
self.label_trq.configure(text="Trq", text_color='red')
|
|
||||||
|
|
||||||
self.entry_path.configure(state="normal")
|
|
||||||
self.entry_av.configure(state="normal")
|
|
||||||
self.entry_rr.configure(state="normal")
|
|
||||||
self.option_axis.configure(state="normal")
|
|
||||||
self.option_vel.configure(state="normal")
|
|
||||||
self.option_trq.configure(state="normal")
|
|
||||||
|
|
||||||
elif func_name == 'current':
|
|
||||||
self.menu_sub = customtkinter.CTkOptionMenu(self.frame_param, values=["max", "avg", "cycle"], font=self.my_font, command=self.func_sub_callback)
|
|
||||||
self.menu_sub.grid(row=1, column=1, sticky='we', padx=(20, 10), pady=(5, 5))
|
|
||||||
self.menu_sub.set("--select--")
|
|
||||||
|
|
||||||
self.label_path.configure(text="Path", text_color='red')
|
|
||||||
self.label_rc.configure(text="RC", text_color='blue')
|
|
||||||
self.label_trqh.configure(text="TrqH", text_color='red')
|
|
||||||
self.label_rc_1.configure(text="RC1", text_color='red')
|
|
||||||
self.label_rc_2.configure(text="RC2", text_color='red')
|
|
||||||
self.label_rc_3.configure(text="RC3", text_color='red')
|
|
||||||
self.label_rc_4.configure(text="RC4", text_color='red')
|
|
||||||
self.label_rc_5.configure(text="RC5", text_color='red')
|
|
||||||
self.label_rc_6.configure(text="RC6", text_color='red')
|
|
||||||
self.entry_path.configure(state="normal")
|
|
||||||
self.entry_rc.configure(state="normal", placeholder_text="optional")
|
|
||||||
self.option_trqh.configure(state="normal")
|
|
||||||
self.entry_rc_1.configure(state="normal", placeholder_text="额定电流")
|
|
||||||
self.entry_rc_2.configure(state="normal", placeholder_text="额定电流")
|
|
||||||
self.entry_rc_3.configure(state="normal", placeholder_text="额定电流")
|
|
||||||
self.entry_rc_4.configure(state="normal", placeholder_text="额定电流")
|
|
||||||
self.entry_rc_5.configure(state="normal", placeholder_text="额定电流")
|
|
||||||
self.entry_rc_6.configure(state="normal", placeholder_text="额定电流")
|
|
||||||
|
|
||||||
elif func_name == 'iso':
|
|
||||||
self.label_path.configure(text="Path", text_color='red')
|
|
||||||
self.entry_path.configure(state="normal")
|
|
||||||
|
|
||||||
else:
|
|
||||||
self.initialization()
|
|
||||||
self.menu_main.set("Start Here!")
|
|
||||||
|
|
||||||
def func_sub_callback(self, func_name):
|
|
||||||
if func_name == "industrial":
|
|
||||||
self.label_rpm.configure(text="RPM", text_color='red')
|
|
||||||
self.entry_rpm.configure(state="normal")
|
|
||||||
elif func_name == "cobot":
|
|
||||||
self.label_rpm.configure(text="RPM", text_color='black')
|
|
||||||
self.entry_rpm.configure(state="disabled")
|
|
||||||
elif func_name == "max":
|
|
||||||
self.label_rpm.configure(text="RPM", text_color='black')
|
|
||||||
self.entry_rpm.configure(state="disabled", placeholder_text='额定转速')
|
|
||||||
self.label_dur.configure(text="Dur", text_color='black')
|
|
||||||
self.entry_dur.configure(state="disabled")
|
|
||||||
self.label_vel.configure(text="Vel", text_color='black')
|
|
||||||
self.option_vel.configure(state="disabled")
|
|
||||||
self.label_trq.configure(text="Trq", text_color='black')
|
|
||||||
self.option_trq.configure(state="disabled")
|
|
||||||
elif func_name == 'avg':
|
|
||||||
self.label_rpm.configure(text="RPM", text_color='black')
|
|
||||||
self.entry_rpm.configure(state="disabled", placeholder_text='额定转速')
|
|
||||||
self.label_dur.configure(text="Dur", text_color='black')
|
|
||||||
self.entry_dur.configure(state="disabled")
|
|
||||||
self.label_vel.configure(text="Vel", text_color='black')
|
|
||||||
self.option_vel.configure(state="disabled")
|
|
||||||
self.label_trq.configure(text="Trq", text_color='black')
|
|
||||||
self.option_trq.configure(state="disabled")
|
|
||||||
elif func_name == 'cycle':
|
|
||||||
self.label_rpm.configure(text="RPM", text_color='blue')
|
|
||||||
self.entry_rpm.configure(state="normal", placeholder_text='cycle')
|
|
||||||
self.label_dur.configure(text="Dur", text_color='blue')
|
|
||||||
self.entry_dur.configure(state="normal", placeholder_text='scenario')
|
|
||||||
self.label_vel.configure(text="Vel", text_color='red')
|
|
||||||
self.option_vel.configure(state="normal")
|
|
||||||
self.label_trq.configure(text="Trq", text_color='red')
|
|
||||||
self.option_trq.configure(state="normal")
|
|
||||||
|
|
||||||
def write2textbox(self, text, wait=0, exitcode=0):
|
|
||||||
if wait != 0:
|
|
||||||
self.textbox.configure(text_color='blue')
|
|
||||||
self.textbox.insert(index='end', text=text)
|
|
||||||
self.textbox.update()
|
|
||||||
self.textbox.see('end')
|
|
||||||
elif exitcode != 0:
|
|
||||||
self.textbox.configure(text_color='red')
|
|
||||||
self.textbox.insert(index='end', text=text + '\n')
|
|
||||||
self.textbox.update()
|
|
||||||
self.textbox.see('end')
|
|
||||||
self.textbox.configure(state='disabled')
|
|
||||||
raise Exception(f"Error code: {exitcode}")
|
|
||||||
else:
|
|
||||||
self.textbox.configure(text_color='blue')
|
|
||||||
self.textbox.insert(index='end', text=text + '\n')
|
|
||||||
self.textbox.update()
|
|
||||||
self.textbox.see('end')
|
|
||||||
|
|
||||||
def is_float(self, flag, *args):
|
|
||||||
for item in args:
|
|
||||||
try:
|
|
||||||
if flag == 'optional':
|
|
||||||
item = 0 if item == '' else item
|
|
||||||
_ = float(item)
|
|
||||||
elif flag == 'required':
|
|
||||||
_ = float(item)
|
|
||||||
except Exception as Err:
|
|
||||||
tkinter.messagebox.showerror(title="参数错误", message="请检查对应参数是否填写正确!", )
|
|
||||||
self.write2textbox(f"错误信息:{Err}\n参数数据缺失,或者数据类型错误,更正后重新运行...", 0, 3)
|
|
||||||
return True
|
|
||||||
|
|
||||||
def check_param(self):
|
|
||||||
func_name = self.menu_main.get()
|
|
||||||
if func_name == 'brake':
|
|
||||||
path = self.entry_path.get().strip(' ')
|
|
||||||
av = self.entry_av.get().strip('- ')
|
|
||||||
rr = self.entry_rr.get().strip('- ')
|
|
||||||
axis = self.option_axis.get()
|
|
||||||
vel = self.option_vel.get()
|
|
||||||
trq = self.option_trq.get()
|
|
||||||
sub_func = self.menu_sub.get()
|
|
||||||
|
|
||||||
c1 = exists(path)
|
|
||||||
c2 = self.is_float('required', av, rr)
|
|
||||||
c3 = rpm = 1
|
|
||||||
c4 = sub_func in ['industrial', 'cobot']
|
|
||||||
c5 = True if vel != trq else False
|
|
||||||
|
|
||||||
if self.menu_sub.get() == 'industrial':
|
|
||||||
rpm = self.entry_rpm.get().strip('- ')
|
|
||||||
c3 = rpm.isdigit()
|
|
||||||
elif self.menu_sub.get() == 'cobot':
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if c1 and c2 and c3 and c4 and c5:
|
|
||||||
return 1, path, float(av), float(rr), int(rpm), int(axis), int(vel), int(trq)
|
|
||||||
else:
|
|
||||||
return 0, 0
|
|
||||||
# =======================================================
|
|
||||||
elif func_name == 'current':
|
|
||||||
path = self.entry_path.get()
|
|
||||||
rc = self.entry_rc.get()
|
|
||||||
rpm = self.entry_rpm.get()
|
|
||||||
dur = self.entry_dur.get()
|
|
||||||
vel = self.option_vel.get()
|
|
||||||
trq = self.option_trq.get()
|
|
||||||
trqh = self.option_trqh.get()
|
|
||||||
sub = self.menu_sub.get()
|
|
||||||
rc1 = self.entry_rc_1.get()
|
|
||||||
rc2 = self.entry_rc_2.get()
|
|
||||||
rc3 = self.entry_rc_3.get()
|
|
||||||
rc4 = self.entry_rc_4.get()
|
|
||||||
rc5 = self.entry_rc_5.get()
|
|
||||||
rc6 = self.entry_rc_6.get()
|
|
||||||
|
|
||||||
c0 = exists(path)
|
|
||||||
c1 = sub in ['max', 'avg', 'cycle']
|
|
||||||
c2 = self.is_float('optional', rc)
|
|
||||||
c3 = self.is_float('optional', rpm)
|
|
||||||
_ = [rc1, rc2, rc3, rc4, rc5, rc6]
|
|
||||||
c4 = self.is_float('required', *_)
|
|
||||||
|
|
||||||
c5 = c6 = True
|
|
||||||
if sub == 'cycle':
|
|
||||||
c5 = True if vel != trq else False
|
|
||||||
c6 = self.is_float('optional', dur)
|
|
||||||
|
|
||||||
if c0 and c1 and c2 and c3 and c4 and c5 and c6:
|
|
||||||
rcs = []
|
|
||||||
for x in _:
|
|
||||||
rcs.append(float(x))
|
|
||||||
rc = 0 if rc == '' else rc
|
|
||||||
dur = 0 if sub != 'cycle' or dur == '' else dur
|
|
||||||
rpm = 0 if sub != 'cycle' or rpm == '' else rpm
|
|
||||||
rcs.append(float(rc))
|
|
||||||
return 2, path, sub, rcs, int(vel), int(trq), int(trqh), float(dur), float(rpm)
|
|
||||||
else:
|
|
||||||
return 0, 0
|
|
||||||
# =======================================================
|
|
||||||
elif func_name == 'iso':
|
|
||||||
path = self.entry_path.get()
|
|
||||||
c1 = exists(path)
|
|
||||||
if c1:
|
|
||||||
return 3, path
|
|
||||||
else:
|
|
||||||
return 0, 0
|
|
||||||
else:
|
|
||||||
return 0, 0
|
|
||||||
|
|
||||||
def func_start_callback(self):
|
|
||||||
self.textbox.configure(state='normal')
|
|
||||||
self.textbox.delete(index1='1.0', index2='end')
|
|
||||||
|
|
||||||
flag, *args = self.check_param()
|
|
||||||
func_dict = {1: brake.main, 2: current.main, 3: iso.main}
|
|
||||||
|
|
||||||
if flag == 1:
|
|
||||||
func_dict[flag](path=args[0], av=args[1], rr=args[2], rpm=args[3], axis=args[4], vel=args[5], trq=args[6], w2t=self.write2textbox)
|
|
||||||
elif flag == 2:
|
|
||||||
# tkinter.messagebox.showinfo(title="TBD", message="功能待实现......")
|
|
||||||
func_dict[flag](path=args[0], sub=args[1], rcs=args[2], vel=args[3], trq=args[4], trqh=args[5], dur=args[6], rpm=args[7], w2t=self.write2textbox)
|
|
||||||
elif flag == 3:
|
|
||||||
func_dict[flag](path=args[0], w2t=self.write2textbox)
|
|
||||||
else:
|
|
||||||
tkinter.messagebox.showerror(title="参数错误", message="请检查对应参数是否填写正确!", )
|
|
||||||
|
|
||||||
self.textbox.configure(state='disabled')
|
|
||||||
|
|
||||||
def func_check_callback(self):
|
|
||||||
self.textbox.configure(state='normal')
|
|
||||||
self.textbox.delete(index1='1.0', index2='end')
|
|
||||||
flag, *args = self.check_param()
|
|
||||||
if flag:
|
|
||||||
tkinter.messagebox.showinfo(title="参数正确", message="所有参数形式上填写无误,可以开始运行!")
|
|
||||||
else:
|
|
||||||
tkinter.messagebox.showerror(title="参数错误", message="需要检查对应参数是否填写正确!", )
|
|
||||||
self.textbox.configure(state='disabled')
|
|
||||||
|
|
||||||
def func_log_callback(self):
|
|
||||||
content = self.textbox.get(index1='1.0', index2='end')
|
|
||||||
if len(content) > 1:
|
|
||||||
try:
|
|
||||||
now = strftime('%Y%m%d%H%M%S', localtime(time()))
|
|
||||||
log_name = f"{now}_aio.log"
|
|
||||||
with open(f'{log_name}', 'w', encoding='utf-8') as objlog:
|
|
||||||
objlog.write(content)
|
|
||||||
tkinter.messagebox.showinfo(title="保存成功", message=f'{log_name}已被保存存至↓↓↓\n{getcwd()}')
|
|
||||||
|
|
||||||
except Exception as Err:
|
|
||||||
self.write2textbox(Err)
|
|
||||||
tkinter.messagebox.showerror(title="保存失败", message="未能保存本次日志,或未能完整保存,请准备好相关数据,联系fanmingfu@rokae.com查看详细信息!", )
|
|
||||||
else:
|
|
||||||
tkinter.messagebox.showwarning(title="未能保存", message="日志数据为空,不可保存!")
|
|
||||||
|
|
||||||
def func_end_call_back(self):
|
|
||||||
if tkinter.messagebox.askyesno(title="关闭程序", message="相关数据可能未保存,正在运行程序时有概率会损坏数据文件,确定要终止程序运行吗?"):
|
|
||||||
self.destroy()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
aio = App()
|
|
||||||
aio.mainloop()
|
|
@ -6,8 +6,8 @@ VSVersionInfo(
|
|||||||
ffi=FixedFileInfo(
|
ffi=FixedFileInfo(
|
||||||
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
|
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
|
||||||
# Set not needed items to zero 0.
|
# Set not needed items to zero 0.
|
||||||
filevers=(0, 1, 4, 0),
|
filevers=(0, 1, 6, 1),
|
||||||
prodvers=(0, 1, 4, 0),
|
prodvers=(0, 1, 6, 1),
|
||||||
# Contains a bitmask that specifies the valid bits 'flags'r
|
# Contains a bitmask that specifies the valid bits 'flags'r
|
||||||
mask=0x3f,
|
mask=0x3f,
|
||||||
# Contains a bitmask that specifies the Boolean attributes of the file.
|
# Contains a bitmask that specifies the Boolean attributes of the file.
|
||||||
@ -31,12 +31,12 @@ VSVersionInfo(
|
|||||||
'040904b0',
|
'040904b0',
|
||||||
[StringStruct('CompanyName', 'Rokae - https://www.rokae.com/'),
|
[StringStruct('CompanyName', 'Rokae - https://www.rokae.com/'),
|
||||||
StringStruct('FileDescription', 'All in one automatic toolbox'),
|
StringStruct('FileDescription', 'All in one automatic toolbox'),
|
||||||
StringStruct('FileVersion', '0.1.4 (2024-06-06)'),
|
StringStruct('FileVersion', '0.1.6.1 (2024-06-16)'),
|
||||||
StringStruct('InternalName', 'AIO.exe'),
|
StringStruct('InternalName', 'AIO.exe'),
|
||||||
StringStruct('LegalCopyright', '© 2024-2024 Manford Fan'),
|
StringStruct('LegalCopyright', '© 2024-2024 Manford Fan'),
|
||||||
StringStruct('OriginalFilename', 'AIO.exe'),
|
StringStruct('OriginalFilename', 'AIO.exe'),
|
||||||
StringStruct('ProductName', 'AIO'),
|
StringStruct('ProductName', 'AIO'),
|
||||||
StringStruct('ProductVersion', '0.1.4 (2024-06-06)')])
|
StringStruct('ProductVersion', '0.1.6.1 (2024-06-16)')])
|
||||||
]),
|
]),
|
||||||
VarFileInfo([VarStruct('Translation', [1033, 1200])])
|
VarFileInfo([VarStruct('Translation', [1033, 1200])])
|
||||||
]
|
]
|
Before Width: | Height: | Size: 162 KiB After Width: | Height: | Size: 162 KiB |
BIN
aio/assets/layout.xlsx
Normal file
BIN
aio/assets/layout.xlsx
Normal file
Binary file not shown.
9
aio/assets/requirements.txt
Normal file
9
aio/assets/requirements.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
openpyxl==3.1.2
|
||||||
|
pdfplumber==0.11.0
|
||||||
|
customtkinter==5.2.2
|
||||||
|
Jinja2==3.1.4
|
||||||
|
lxml==5.2.2
|
||||||
|
numpy==1.26.4
|
||||||
|
pandas==2.2.2
|
||||||
|
pillow==10.3.0
|
||||||
|
pyinstaller==6.7.0
|
1
aio/assets/vers
Normal file
1
aio/assets/vers
Normal file
@ -0,0 +1 @@
|
|||||||
|
0.1.6.1 @ 06/16/2024
|
1856
aio/assets/workflow/brake.excalidraw
Normal file
1856
aio/assets/workflow/brake.excalidraw
Normal file
File diff suppressed because it is too large
Load Diff
3289
aio/assets/workflow/current.excalidraw
Normal file
3289
aio/assets/workflow/current.excalidraw
Normal file
File diff suppressed because it is too large
Load Diff
370
aio/code/aio.py
Normal file
370
aio/code/aio.py
Normal file
@ -0,0 +1,370 @@
|
|||||||
|
from os.path import exists
|
||||||
|
from os import getcwd
|
||||||
|
from threading import Thread
|
||||||
|
import tkinter.messagebox
|
||||||
|
import customtkinter
|
||||||
|
import brake, current, iso, wavelogger
|
||||||
|
from time import time, strftime, localtime
|
||||||
|
from urllib.request import urlopen
|
||||||
|
from socket import setdefaulttimeout
|
||||||
|
|
||||||
|
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(10)
|
||||||
|
# global vars
|
||||||
|
btns = {
|
||||||
|
'start': {'btn': '', 'row': 1, 'text': '开始运行'},
|
||||||
|
'check': {'btn': '', 'row': 2, 'text': '检查参数'},
|
||||||
|
'log': {'btn': '', 'row': 3, 'text': '保存日志'},
|
||||||
|
'end': {'btn': '', 'row': 4, 'text': '结束运行'},
|
||||||
|
}
|
||||||
|
widgits = {
|
||||||
|
'path': {'label': '', 'entry': '', 'row': 1, 'col': 2, 'text': '数据文件夹路径'},
|
||||||
|
'av': {'label': '', 'entry': '', 'row': 2, 'col': 2, 'text': '角速度'},
|
||||||
|
'rc': {'label': '', 'entry': '', 'row': 2, 'col': 4, 'text': '额定电流'},
|
||||||
|
'rpm': {'label': '', 'entry': '', 'row': 2, 'col': 6, 'text': '额定转速'},
|
||||||
|
'rr': {'label': '', 'entry': '', 'row': 2, 'col': 8, 'text': '减速比'},
|
||||||
|
'dur': {'label': '', 'entry': '', 'row': 2, 'col': 10, 'text': '周期时间'},
|
||||||
|
'axis': {'label': '', 'optionmenu': '', 'row': 3, 'col': 2, 'text': ''},
|
||||||
|
'vel': {'label': '', 'optionmenu': '', 'row': 3, 'col': 4, 'text': ''},
|
||||||
|
'trq': {'label': '', 'optionmenu': '', 'row': 3, 'col': 6, 'text': ''},
|
||||||
|
'trqh': {'label': '', 'optionmenu': '', 'row': 3, 'col': 8, 'text': ''},
|
||||||
|
'estop': {'label': '', 'optionmenu': '', 'row': 3, 'col': 10, 'text': ''},
|
||||||
|
'rc1': {'label': '', 'entry': '', 'row': 4, 'col': 2, 'text': '额定电流'},
|
||||||
|
'rc2': {'label': '', 'entry': '', 'row': 4, 'col': 4, 'text': '额定电流'},
|
||||||
|
'rc3': {'label': '', 'entry': '', 'row': 4, 'col': 6, 'text': '额定电流'},
|
||||||
|
'rc4': {'label': '', 'entry': '', 'row': 4, 'col': 8, 'text': '额定电流'},
|
||||||
|
'rc5': {'label': '', 'entry': '', 'row': 4, 'col': 10, 'text': '额定电流'},
|
||||||
|
'rc6': {'label': '', 'entry': '', 'row': 4, 'col': 12, 'text': '额定电流'},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class App(customtkinter.CTk):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.my_font = customtkinter.CTkFont(family="Consolas", size=16, weight="bold")
|
||||||
|
self.w_param = 84
|
||||||
|
# =====================================================================
|
||||||
|
# configure window
|
||||||
|
self.title("AIO - All in one automatic toolbox")
|
||||||
|
# self.iconbitmap('./icon.ico')
|
||||||
|
self.geometry("1200x550+30+30")
|
||||||
|
self.protocol("WM_DELETE_WINDOW", self.func_end_callback)
|
||||||
|
self.config(bg='#E9E9E9')
|
||||||
|
self.grid_rowconfigure(5, weight=1)
|
||||||
|
self.grid_columnconfigure((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), weight=1)
|
||||||
|
self.minsize(1200, 550)
|
||||||
|
# =====================================================================
|
||||||
|
# create frame sidebar(left)
|
||||||
|
self.frame_func = customtkinter.CTkFrame(self, width=120, corner_radius=0, fg_color='#E9E9E9')
|
||||||
|
self.frame_func.grid(row=0, column=0, rowspan=7, sticky='nsew')
|
||||||
|
# create AIO logo
|
||||||
|
self.label_logo = customtkinter.CTkLabel(self.frame_func, text="Rokae AIO", height=60, font=customtkinter.CTkFont(family="Segoe Script Bold", size=24, weight="bold"), text_color="#4F4F4F")
|
||||||
|
self.label_logo.grid(row=0, column=0, padx=15, pady=15)
|
||||||
|
# create buttons
|
||||||
|
for func in btns:
|
||||||
|
btns[func]['btn'] = customtkinter.CTkButton(self.frame_func, corner_radius=10, text=btns[func]['text'], fg_color='#4F4F4F', font=self.my_font)
|
||||||
|
btns[func]['btn'].grid(row=btns[func]['row'], column=0, sticky='new', padx=10, pady=10, ipadx=5, ipady=5)
|
||||||
|
btns['start']['btn'].configure(command=lambda: self.thread_it(self.func_start_callback))
|
||||||
|
btns['check']['btn'].configure(command=lambda: self.thread_it(self.func_check_callback))
|
||||||
|
btns['log']['btn'].configure(command=lambda: self.thread_it(self.func_log_callback))
|
||||||
|
btns['end']['btn'].configure(command=lambda: self.thread_it(self.func_end_callback))
|
||||||
|
# create version info
|
||||||
|
self.label_version = customtkinter.CTkLabel(self.frame_func, justify='left', text="Vers: 0.1.6.1\nDate: 06/16/2024", font=self.my_font, text_color="#4F4F4F")
|
||||||
|
self.frame_func.rowconfigure(6, weight=1)
|
||||||
|
self.label_version.grid(row=6, column=0, padx=20, pady=20, sticky='s')
|
||||||
|
# =====================================================================
|
||||||
|
# create tabviews
|
||||||
|
self.tabview = customtkinter.CTkTabview(self, width=10000, height=100, anchor='w', fg_color='#E9E9E9', border_width=2, border_color='#CDCDCD')
|
||||||
|
self.tabview.grid(row=0, column=1, padx=10, pady=5, sticky="nsew")
|
||||||
|
self.tabview.add("Data Process")
|
||||||
|
self.tabview.add("Automatic Test")
|
||||||
|
# create main menu
|
||||||
|
self.menu_main_dp = customtkinter.CTkOptionMenu(self.tabview.tab('Data Process'), values=["init", "brake", "current", "iso", "wavelogger"], font=self.my_font, text_color='yellow', button_color='red', fg_color='green', command=self.func_main_callback)
|
||||||
|
self.menu_main_dp.grid(row=1, column=1, sticky='we', padx=5, pady=5)
|
||||||
|
self.menu_main_dp.set("Start Here!")
|
||||||
|
# create sub menu
|
||||||
|
self.menu_sub_dp = customtkinter.CTkOptionMenu(self.tabview.tab('Data Process'))
|
||||||
|
# =====================================================================
|
||||||
|
# create widgits
|
||||||
|
for widgit in widgits:
|
||||||
|
if widgit == 'path':
|
||||||
|
widgits[widgit]['label'] = customtkinter.CTkLabel(self.tabview.tab('Data Process'), text=f'{widgit.upper()}', font=self.my_font)
|
||||||
|
widgits[widgit]['label'].grid(row=widgits[widgit]['row'], column=widgits[widgit]['col'], sticky='e', pady=5)
|
||||||
|
widgits[widgit]['entry'] = customtkinter.CTkEntry(self.tabview.tab('Data Process'), width=670, placeholder_text=widgits[widgit]['text'], font=self.my_font)
|
||||||
|
widgits[widgit]['entry'].grid(row=widgits[widgit]['row'], column=widgits[widgit]['col']+1, columnspan=11, padx=(5, 10), pady=5, sticky='we')
|
||||||
|
widgits[widgit]['entry'].configure(state='disabled')
|
||||||
|
elif widgit in ['av', 'rc', 'rpm', 'rr', 'dur', 'rc1', 'rc2', 'rc3', 'rc4', 'rc5', 'rc6']:
|
||||||
|
widgits[widgit]['label'] = customtkinter.CTkLabel(self.tabview.tab('Data Process'), text=f"{widgit.upper()}", font=self.my_font)
|
||||||
|
widgits[widgit]['label'].grid(row=widgits[widgit]['row'], column=widgits[widgit]['col'], sticky='e', pady=5)
|
||||||
|
widgits[widgit]['entry'] = customtkinter.CTkEntry(self.tabview.tab('Data Process'), width=self.w_param, placeholder_text=f"{widgits[widgit]['text']}", font=self.my_font)
|
||||||
|
widgits[widgit]['entry'].grid(row=widgits[widgit]['row'], column=widgits[widgit]['col']+1, padx=(5, 10), pady=5, sticky='w')
|
||||||
|
widgits[widgit]['entry'].configure(state='disabled')
|
||||||
|
elif widgit in ['axis', 'vel', 'trq', 'trqh', 'estop']:
|
||||||
|
widgits[widgit]['label'] = customtkinter.CTkLabel(self.tabview.tab('Data Process'), text=f"{widgit.upper()}", font=self.my_font)
|
||||||
|
widgits[widgit]['label'].grid(row=widgits[widgit]['row'], column=widgits[widgit]['col'], sticky='e', pady=5)
|
||||||
|
widgits[widgit]['optionmenu'] = customtkinter.CTkOptionMenu(self.tabview.tab('Data Process'), button_color='#708090', fg_color='#778899', values=["1", "2", "3", "4", "5", "6", "7"], width=self.w_param, font=self.my_font)
|
||||||
|
widgits[widgit]['optionmenu'].grid(row=widgits[widgit]['row'], column=widgits[widgit]['col']+1, padx=(5, 10), pady=5, sticky='w')
|
||||||
|
widgits[widgit]['optionmenu'].configure(state='disabled')
|
||||||
|
# =====================================================================
|
||||||
|
# create textbox
|
||||||
|
self.textbox = customtkinter.CTkTextbox(self, wrap='none', font=customtkinter.CTkFont(family="consolas", size=14), text_color="blue", fg_color='#E9E9E9', border_width=2, border_color='#CDCDCD', border_spacing=5)
|
||||||
|
self.textbox.grid(row=5, column=1, rowspan=2, columnspan=13, ipadx=10, ipady=10, padx=10, pady=(5, 10), sticky='nsew')
|
||||||
|
self.textbox.configure(state='disabled')
|
||||||
|
# =====================================================================
|
||||||
|
# version check
|
||||||
|
cur_vers = self.label_version.cget("text").replace('\n', ' @ ').replace("Vers: ", '').replace("Date: ", '')
|
||||||
|
url_vers = 'http://10.2.23.150:10008/vers'
|
||||||
|
try:
|
||||||
|
new_vers = urlopen(url_vers).read().decode('utf-8')
|
||||||
|
if cur_vers.strip() != new_vers.strip():
|
||||||
|
msg = f"""当前版本:{cur_vers}\n更新版本:{new_vers}\n\n请及时更新 http://10.2.23.150:10003/s/jRfM"""
|
||||||
|
tkinter.messagebox.showwarning(title="版本更新", message=msg)
|
||||||
|
except:
|
||||||
|
tkinter.messagebox.showwarning(title="版本更新", message="连接服务器失败,无法确认当前是否是最新版本......")
|
||||||
|
|
||||||
|
def thread_it(self, func, *args):
|
||||||
|
""" 将函数打包进线程 """
|
||||||
|
self.myThread = Thread(target=func, args=args)
|
||||||
|
self.myThread.daemon = True # 主线程退出就直接让子线程跟随退出,不论是否运行完成。
|
||||||
|
self.myThread.start()
|
||||||
|
|
||||||
|
def initialization(self):
|
||||||
|
for widgit in widgits:
|
||||||
|
if widgit in ['path', 'av', 'rc', 'rpm', 'rr', 'dur', 'rc1', 'rc2', 'rc3', 'rc4', 'rc5', 'rc6']:
|
||||||
|
widgits[widgit]['label'].configure(text=f'{widgit.upper()}', text_color='black')
|
||||||
|
widgits[widgit]['entry'].configure(placeholder_text=widgits[widgit]['text'], state='disabled')
|
||||||
|
elif widgit in ['axis', 'vel', 'trq', 'trqh', 'estop']:
|
||||||
|
widgits[widgit]['label'].configure(text=f'{widgit.upper()}', text_color="black")
|
||||||
|
widgits[widgit]['optionmenu'].configure(state='disabled')
|
||||||
|
|
||||||
|
self.menu_sub_dp.grid_forget()
|
||||||
|
self.textbox.delete(index1='1.0', index2='end')
|
||||||
|
self.textbox.configure(state='disabled')
|
||||||
|
|
||||||
|
def func_main_callback(self, func_name):
|
||||||
|
self.initialization()
|
||||||
|
|
||||||
|
if func_name == 'brake':
|
||||||
|
for widgit in widgits:
|
||||||
|
if widgit in ['path', 'av', 'rr']:
|
||||||
|
widgits[widgit]['label'].configure(text_color='red')
|
||||||
|
widgits[widgit]['entry'].configure(state='normal')
|
||||||
|
elif widgit in ['axis', 'vel', 'trq', 'estop']:
|
||||||
|
widgits[widgit]['label'].configure(text_color="red")
|
||||||
|
widgits[widgit]['optionmenu'].configure(state='normal')
|
||||||
|
elif func_name == 'current':
|
||||||
|
self.menu_sub_dp = customtkinter.CTkOptionMenu(self.tabview.tab('Data Process'), values=["max", "avg", "cycle"], font=self.my_font, button_color='red', fg_color='green', command=self.func_sub_callback)
|
||||||
|
self.menu_sub_dp.grid(row=2, column=1, sticky='we', padx=5, pady=5)
|
||||||
|
self.menu_sub_dp.set("--select--")
|
||||||
|
self.menu_sub_dp.configure(text_color='yellow')
|
||||||
|
|
||||||
|
for widgit in widgits:
|
||||||
|
if widgit in ['path', 'rc', 'rc1', 'rc2', 'rc3', 'rc4', 'rc5', 'rc6']:
|
||||||
|
color = 'blue' if widgit == 'rc' else 'red'
|
||||||
|
widgits[widgit]['label'].configure(text_color=color)
|
||||||
|
widgits[widgit]['entry'].configure(state='normal')
|
||||||
|
elif widgit in ['trqh',]:
|
||||||
|
widgits[widgit]['label'].configure(text_color="red")
|
||||||
|
widgits[widgit]['optionmenu'].configure(state='normal')
|
||||||
|
elif func_name == 'iso' or func_name == 'wavelogger':
|
||||||
|
for widgit in widgits:
|
||||||
|
if widgit in ['path',]:
|
||||||
|
widgits[widgit]['label'].configure(text_color='red')
|
||||||
|
widgits[widgit]['entry'].configure(state='normal')
|
||||||
|
else:
|
||||||
|
self.initialization()
|
||||||
|
self.menu_main_dp.set("Start Here!")
|
||||||
|
|
||||||
|
def func_sub_callback(self, func_name):
|
||||||
|
if func_name == "max":
|
||||||
|
for widgit in widgits:
|
||||||
|
if widgit in ['rpm', 'dur']:
|
||||||
|
widgits[widgit]['label'].configure(text_color='black')
|
||||||
|
widgits[widgit]['entry'].configure(state='disabled')
|
||||||
|
elif widgit in ['vel', 'trq']:
|
||||||
|
widgits[widgit]['label'].configure(text_color='black')
|
||||||
|
widgits[widgit]['optionmenu'].configure(state='disabled')
|
||||||
|
elif func_name == 'avg':
|
||||||
|
for widgit in widgits:
|
||||||
|
if widgit in ['rpm', 'dur']:
|
||||||
|
widgits[widgit]['label'].configure(text_color='black')
|
||||||
|
widgits[widgit]['entry'].configure(state='disabled')
|
||||||
|
elif widgit in ['vel', 'trq']:
|
||||||
|
widgits[widgit]['label'].configure(text_color='black')
|
||||||
|
widgits[widgit]['optionmenu'].configure(state='disabled')
|
||||||
|
elif func_name == 'cycle':
|
||||||
|
for widgit in widgits:
|
||||||
|
if widgit in ['rpm', 'dur']:
|
||||||
|
widgits[widgit]['label'].configure(text_color='blue')
|
||||||
|
widgits[widgit]['entry'].configure(state='normal')
|
||||||
|
elif widgit in ['vel', 'trq']:
|
||||||
|
widgits[widgit]['label'].configure(text_color="red")
|
||||||
|
widgits[widgit]['optionmenu'].configure(state='normal')
|
||||||
|
|
||||||
|
def write2textbox(self, text, wait=0, exitcode=0, color='blue'):
|
||||||
|
self.textbox.tag_add(color, 'insert', 'end')
|
||||||
|
self.textbox.tag_config(tagName=color, foreground=color)
|
||||||
|
|
||||||
|
if wait != 0:
|
||||||
|
self.textbox.insert(index='end', text=text, tags=color)
|
||||||
|
self.textbox.update()
|
||||||
|
self.textbox.see('end')
|
||||||
|
elif exitcode != 0:
|
||||||
|
self.textbox.insert(index='end', text=text + '\n', tags=color)
|
||||||
|
self.textbox.update()
|
||||||
|
self.textbox.see('end')
|
||||||
|
self.textbox.configure(state='disabled')
|
||||||
|
raise Exception(f"Error code: {exitcode}")
|
||||||
|
else:
|
||||||
|
self.textbox.insert(index='end', text=text + '\n', tags=color)
|
||||||
|
self.textbox.update()
|
||||||
|
self.textbox.see('end')
|
||||||
|
|
||||||
|
def is_float(self, flag, *args):
|
||||||
|
for item in args:
|
||||||
|
try:
|
||||||
|
if flag == 'optional':
|
||||||
|
item = 0 if item == '' else item
|
||||||
|
_ = float(item)
|
||||||
|
elif flag == 'required':
|
||||||
|
_ = float(item)
|
||||||
|
except Exception as Err:
|
||||||
|
tkinter.messagebox.showerror(title="参数错误", message="请检查对应参数是否填写正确!", )
|
||||||
|
self.write2textbox(f"错误信息:{Err}\n参数数据缺失,或者数据类型错误,更正后重新运行...\n", 0, 3, 'red')
|
||||||
|
return True
|
||||||
|
|
||||||
|
def check_param(self):
|
||||||
|
func_name = self.menu_main_dp.get()
|
||||||
|
if func_name == 'brake':
|
||||||
|
path = widgits['path']['entry'].get().strip()
|
||||||
|
av = widgits['av']['entry'].get().strip('- ')
|
||||||
|
rr = widgits['rr']['entry'].get().strip('- ')
|
||||||
|
axis = widgits['axis']['optionmenu'].get()
|
||||||
|
vel = widgits['vel']['optionmenu'].get()
|
||||||
|
trq = widgits['trq']['optionmenu'].get()
|
||||||
|
estop = widgits['estop']['optionmenu'].get()
|
||||||
|
|
||||||
|
c1 = exists(path)
|
||||||
|
c2 = self.is_float('required', av, rr)
|
||||||
|
c3 = True if len({vel, trq, estop}) == 3 else False
|
||||||
|
|
||||||
|
if c1 and c2 and c3:
|
||||||
|
return 1, path, float(av), float(rr), int(axis), int(vel), int(trq), int(estop)
|
||||||
|
else:
|
||||||
|
return 0, 0
|
||||||
|
# =======================================================
|
||||||
|
elif func_name == 'current':
|
||||||
|
path = widgits['path']['entry'].get().strip()
|
||||||
|
rc = widgits['rc']['entry'].get().strip('- ')
|
||||||
|
rpm = widgits['rpm']['entry'].get().strip()
|
||||||
|
dur = widgits['dur']['entry'].get().strip()
|
||||||
|
rc1 = widgits['rc1']['entry'].get().strip()
|
||||||
|
rc2 = widgits['rc2']['entry'].get().strip()
|
||||||
|
rc3 = widgits['rc3']['entry'].get().strip()
|
||||||
|
rc4 = widgits['rc4']['entry'].get().strip()
|
||||||
|
rc5 = widgits['rc5']['entry'].get().strip()
|
||||||
|
rc6 = widgits['rc6']['entry'].get().strip()
|
||||||
|
vel = widgits['vel']['optionmenu'].get()
|
||||||
|
trq = widgits['trq']['optionmenu'].get()
|
||||||
|
trqh = widgits['trqh']['optionmenu'].get()
|
||||||
|
sub = self.menu_sub_dp.get()
|
||||||
|
|
||||||
|
c1 = exists(path)
|
||||||
|
c2 = sub in ['max', 'avg', 'cycle']
|
||||||
|
c3 = self.is_float('optional', rc, rpm)
|
||||||
|
c4 = self.is_float('required', rc1, rc2, rc3, rc4, rc5, rc6)
|
||||||
|
|
||||||
|
c5 = c6 = True
|
||||||
|
if sub == 'cycle':
|
||||||
|
c5 = True if len({vel, trq}) == 2 else False
|
||||||
|
c6 = self.is_float('optional', dur)
|
||||||
|
|
||||||
|
if c1 and c2 and c3 and c4 and c5 and c6:
|
||||||
|
rcs = []
|
||||||
|
for x in [rc1, rc2, rc3, rc4, rc5, rc6]:
|
||||||
|
rcs.append(float(x))
|
||||||
|
rc = 0 if rc == '' else rc
|
||||||
|
dur = 0 if sub != 'cycle' or dur == '' else dur
|
||||||
|
rpm = 0 if sub != 'cycle' or rpm == '' else rpm
|
||||||
|
rcs.append(float(rc))
|
||||||
|
return 2, path, sub, rcs, int(vel), int(trq), int(trqh), float(dur), float(rpm)
|
||||||
|
else:
|
||||||
|
return 0, 0
|
||||||
|
# =======================================================
|
||||||
|
elif func_name == 'iso':
|
||||||
|
path = widgits['path']['entry'].get().strip()
|
||||||
|
c1 = exists(path)
|
||||||
|
if c1:
|
||||||
|
return 3, path
|
||||||
|
else:
|
||||||
|
return 0, 0
|
||||||
|
# =======================================================
|
||||||
|
elif func_name == 'wavelogger':
|
||||||
|
path = widgits['path']['entry'].get().strip()
|
||||||
|
c1 = exists(path)
|
||||||
|
if c1:
|
||||||
|
return 4, path
|
||||||
|
else:
|
||||||
|
return 0, 0
|
||||||
|
# =======================================================
|
||||||
|
else:
|
||||||
|
return 0, 0
|
||||||
|
|
||||||
|
def func_start_callback(self):
|
||||||
|
self.textbox.configure(state='normal')
|
||||||
|
self.textbox.delete(index1='1.0', index2='end')
|
||||||
|
|
||||||
|
flag, *args = self.check_param()
|
||||||
|
func_dict = {1: brake.main, 2: current.main, 3: iso.main, 4: wavelogger.main}
|
||||||
|
if flag == 1:
|
||||||
|
func_dict[flag](path=args[0], av=args[1], rr=args[2], axis=args[3], vel=args[4], trq=args[5], estop=args[6], w2t=self.write2textbox)
|
||||||
|
elif flag == 2:
|
||||||
|
func_dict[flag](path=args[0], sub=args[1], rcs=args[2], vel=args[3], trq=args[4], trqh=args[5], dur=args[6], rpm=args[7], w2t=self.write2textbox)
|
||||||
|
elif flag == 3:
|
||||||
|
func_dict[flag](path=args[0], w2t=self.write2textbox)
|
||||||
|
elif flag == 4:
|
||||||
|
func_dict[flag](path=args[0], w2t=self.write2textbox)
|
||||||
|
else:
|
||||||
|
tkinter.messagebox.showerror(title="参数错误", message="请检查对应参数是否填写正确!", )
|
||||||
|
|
||||||
|
self.textbox.configure(state='disabled')
|
||||||
|
|
||||||
|
def func_check_callback(self):
|
||||||
|
self.textbox.configure(state='normal')
|
||||||
|
self.textbox.delete(index1='1.0', index2='end')
|
||||||
|
|
||||||
|
flag, *args = self.check_param()
|
||||||
|
if flag:
|
||||||
|
tkinter.messagebox.showinfo(title="参数正确", message="所有参数形式上填写无误,可以开始运行!")
|
||||||
|
else:
|
||||||
|
tkinter.messagebox.showerror(title="参数错误", message="需要检查对应参数是否填写正确!", )
|
||||||
|
|
||||||
|
self.textbox.configure(state='disabled')
|
||||||
|
|
||||||
|
def func_log_callback(self):
|
||||||
|
content = self.textbox.get(index1='1.0', index2='end')
|
||||||
|
if len(content) > 1:
|
||||||
|
try:
|
||||||
|
now = strftime('%Y%m%d%H%M%S', localtime(time()))
|
||||||
|
log_name = f"{now}_aio.log"
|
||||||
|
with open(f'{log_name}', 'w', encoding='utf-8') as objlog:
|
||||||
|
objlog.write(content)
|
||||||
|
tkinter.messagebox.showinfo(title="保存成功", message=f'{log_name}已被保存存至↓↓↓\n{getcwd()}')
|
||||||
|
|
||||||
|
except Exception as Err:
|
||||||
|
self.write2textbox(Err)
|
||||||
|
tkinter.messagebox.showerror(title="保存失败", message="未能保存本次日志,或未能完整保存,请准备好相关数据,联系fanmingfu@rokae.com查看详细信息!", )
|
||||||
|
else:
|
||||||
|
tkinter.messagebox.showwarning(title="未能保存", message="日志数据为空,不可保存!")
|
||||||
|
|
||||||
|
def func_end_callback(self):
|
||||||
|
if tkinter.messagebox.askyesno(title="关闭程序", message="相关数据可能未保存,正在运行程序时有概率会损坏数据文件,确定要终止程序运行吗?"):
|
||||||
|
self.destroy()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
aio = App()
|
||||||
|
aio.mainloop()
|
@ -27,12 +27,12 @@ class GetThreadResult(Thread):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def data_process(result_file, raw_data_dirs, av, rr, axis, vel, trq, w2t, rpm):
|
def data_process(result_file, raw_data_dirs, av, rr, axis, vel, trq, w2t, estop):
|
||||||
# 功能:完成一个结果文件的数据处理
|
# 功能:完成一个结果文件的数据处理
|
||||||
# 参数:结果文件,数据目录,以及预读取的参数
|
# 参数:结果文件,数据目录,以及预读取的参数
|
||||||
# 返回值:-
|
# 返回值:-
|
||||||
file_name = result_file.split('\\')[-1]
|
file_name = result_file.split('\\')[-1]
|
||||||
w2t(f"打开文件 {file_name} 需要 1min 左右", 1)
|
w2t(f"正在打开文件 {file_name} 需要 1min 左右", 1, 0, 'orange')
|
||||||
|
|
||||||
global stop
|
global stop
|
||||||
stop = 0
|
stop = 0
|
||||||
@ -55,21 +55,21 @@ def data_process(result_file, raw_data_dirs, av, rr, axis, vel, trq, w2t, rpm):
|
|||||||
# count = 1
|
# count = 1
|
||||||
# for data_file in data_files:
|
# for data_file in data_files:
|
||||||
# now_doing_msg(data_file, 'start', w2t)
|
# now_doing_msg(data_file, 'start', w2t)
|
||||||
# single_file_process(data_file, wb_result, count, av, rr, axis, vel, trq, w2t, rpm)
|
# single_file_process(data_file, wb_result, count, av, rr, axis, vel, trq, w2t, estop)
|
||||||
# count += 1
|
# count += 1
|
||||||
# now_doing_msg(data_file, 'done', w2t)
|
# now_doing_msg(data_file, 'done', w2t)
|
||||||
# ---------------------------------------------------
|
# ---------------------------------------------------
|
||||||
# 数据文件并行处理模式---------------------------------
|
# 数据文件并行处理模式---------------------------------
|
||||||
threads = [Thread(target=single_file_process, args=(data_files[0], wb_result, 1, av, rr, axis, vel, trq, w2t, rpm)),
|
threads = [Thread(target=single_file_process, args=(data_files[0], wb_result, 1, av, rr, axis, vel, trq, w2t, estop)),
|
||||||
Thread(target=single_file_process, args=(data_files[1], wb_result, 2, av, rr, axis, vel, trq, w2t, rpm)),
|
Thread(target=single_file_process, args=(data_files[1], wb_result, 2, av, rr, axis, vel, trq, w2t, estop)),
|
||||||
Thread(target=single_file_process, args=(data_files[2], wb_result, 3, av, rr, axis, vel, trq, w2t, rpm))]
|
Thread(target=single_file_process, args=(data_files[2], wb_result, 3, av, rr, axis, vel, trq, w2t, estop))]
|
||||||
[t.start() for t in threads]
|
[t.start() for t in threads]
|
||||||
[t.join() for t in threads]
|
[t.join() for t in threads]
|
||||||
# ---------------------------------------------------
|
# ---------------------------------------------------
|
||||||
now_doing_msg(raw_data_dir, 'done', w2t)
|
now_doing_msg(raw_data_dir, 'done', w2t)
|
||||||
|
|
||||||
now_doing_msg(result_file, 'done', w2t)
|
now_doing_msg(result_file, 'done', w2t)
|
||||||
w2t(f"保存文件 {file_name} 需要 1min 左右", 1)
|
w2t(f"正在保存文件 {file_name} 需要 1min 左右", 1, 0, 'orange')
|
||||||
stop = 0
|
stop = 0
|
||||||
t_excel = Thread(target=wb_result.save, args=(result_file, ))
|
t_excel = Thread(target=wb_result.save, args=(result_file, ))
|
||||||
t_wait = Thread(target=w2t_local, args=('.', 1, w2t))
|
t_wait = Thread(target=w2t_local, args=('.', 1, w2t))
|
||||||
@ -89,41 +89,40 @@ def check_files(raw_data_dirs, result_files, w2t):
|
|||||||
msg = "结果文件数目错误,结果文件有且只有三个,请确认!"
|
msg = "结果文件数目错误,结果文件有且只有三个,请确认!"
|
||||||
for result_file in result_files:
|
for result_file in result_files:
|
||||||
w2t(result_file)
|
w2t(result_file)
|
||||||
w2t(msg, 0, 2)
|
w2t(msg, 0, 2, 'red')
|
||||||
|
|
||||||
prefix = []
|
prefix = []
|
||||||
for result_file in result_files:
|
for result_file in result_files:
|
||||||
prefix.append(result_file.split('\\')[-1].split('_')[0])
|
prefix.append(result_file.split('\\')[-1].split('_')[0])
|
||||||
if not sorted(prefix) == sorted(['load33', 'load66', 'load100']):
|
if not sorted(prefix) == sorted(['reach33', 'reach66', 'reach100']):
|
||||||
wd = result_files[0].split('\\')
|
wd = result_files[0].split('\\')
|
||||||
del wd[-1]
|
del wd[-1]
|
||||||
wd = '\\'.join(wd)
|
wd = '\\'.join(wd)
|
||||||
msg = f"""请关闭所有相关数据文件,并检查工作目录 {wd} 下,有且只允许有类似如下三个文件:
|
msg = f"""请关闭所有相关数据文件,并检查工作目录 {wd} 下,有且只允许有类似如下三个文件:
|
||||||
1. load33_自研_制动性能测试.xlsx
|
1. reach33_XXX制动性能测试.xlsx
|
||||||
2. load66_自研_制动性能测试.xlsx
|
2. reach66_XXX制动性能测试.xlsx
|
||||||
3. load100_自研_制动性能测试.xlsx"""
|
3. reach100_XX制动性能测试.xlsx"""
|
||||||
w2t(msg, 0, 3)
|
w2t(msg, 0, 3, 'red')
|
||||||
|
|
||||||
for raw_data_dir in raw_data_dirs:
|
for raw_data_dir in raw_data_dirs:
|
||||||
components = raw_data_dir.split('\\')[-1].split('_')
|
components = raw_data_dir.split('\\')[-1].split('_')
|
||||||
sorted(components)
|
sorted(components)
|
||||||
if components[0] not in ['load33', 'load66', 'load100'] or \
|
if components[0] not in ['reach33', 'reach66', 'reach100'] or \
|
||||||
components[1] not in ['speed33', 'speed66', 'speed100'] or \
|
components[1] not in ['load33', 'load66', 'load100'] or \
|
||||||
components[2] not in ['reach33', 'reach66', 'reach100']:
|
components[2] not in ['speed33', 'speed66', 'speed100']:
|
||||||
msg = f"报错信息:数据目录 {raw_data_dir} 命名不合规,请参考如下形式\n" \
|
msg = f"""报错信息:数据目录 {raw_data_dir} 命名不合规,请参考如下形式:
|
||||||
f"命名规则:\n 1. loadAA_speedBB_reachCC\n 2. loadAA_reachBB_speedCC\n" \
|
命名规则:reachAA_loadBB_speedCC
|
||||||
f"规则解释:AA/BB/CC 指的是负载/速度/臂展的比例\n" \
|
规则解释:AA/BB/CC 指的是臂展/负载/速度的比例,例如reach66_load100_speed33:66%臂展,100%负载以及33%速度情况下的测试结果文件夹"""
|
||||||
f"load66_speed100_reach33:66% 负载,100% 速度以及 33% 臂展情况下的测试结果文件夹"
|
w2t(msg, 0, 4, 'red')
|
||||||
w2t(msg, 0, 4)
|
|
||||||
|
|
||||||
_, raw_data_files = traversal_files(raw_data_dir, w2t)
|
_, raw_data_files = traversal_files(raw_data_dir, w2t)
|
||||||
if len(raw_data_files) != 3:
|
if len(raw_data_files) != 3:
|
||||||
msg = f"数据目录 {raw_data_dir} 下数据文件个数错误,每个数据目录下有且只能有三个以 .data 为后缀的数据文件"
|
msg = f"数据目录 {raw_data_dir} 下数据文件个数错误,每个数据目录下有且只能有三个以 .data 为后缀的数据文件"
|
||||||
w2t(msg, 0, 5)
|
w2t(msg, 0, 5, 'red')
|
||||||
for raw_data_file in raw_data_files:
|
for raw_data_file in raw_data_files:
|
||||||
if not (raw_data_file.split('\\')[-1].endswith('.data') or raw_data_file.split('\\')[-1].endswith('.csv')):
|
if not raw_data_file.split('\\')[-1].endswith('.data'):
|
||||||
msg = f"数据文件 {raw_data_file} 后缀错误,每个数据目录下有且只能有三个以 .data/csv 为后缀的数据文件"
|
msg = f"数据文件 {raw_data_file} 后缀错误,每个数据目录下有且只能有三个以 .data 为后缀的数据文件"
|
||||||
w2t(msg, 0, 6)
|
w2t(msg, 0, 6, 'red')
|
||||||
|
|
||||||
w2t("数据目录合规性检查结束,未发现问题......")
|
w2t("数据目录合规性检查结束,未发现问题......")
|
||||||
|
|
||||||
@ -139,9 +138,9 @@ def now_doing_msg(docs, flag, w2t):
|
|||||||
elif flag == 'start' and file_type == 'file':
|
elif flag == 'start' and file_type == 'file':
|
||||||
w2t(f"[{now}] 正在处理文件 {docs} 中的数据......")
|
w2t(f"[{now}] 正在处理文件 {docs} 中的数据......")
|
||||||
elif flag == 'done' and file_type == 'dir':
|
elif flag == 'done' and file_type == 'dir':
|
||||||
w2t(f"[{now}] 目录 {docs} 数据文件已处理完毕......")
|
w2t(f"[{now}] 目录 {docs} 数据文件已处理完毕")
|
||||||
elif flag == 'done' and file_type == 'file':
|
elif flag == 'done' and file_type == 'file':
|
||||||
w2t(f"[{now}] 文件 {docs} 数据已处理完毕......")
|
w2t(f"[{now}] 文件 {docs} 数据已处理完毕")
|
||||||
|
|
||||||
|
|
||||||
def w2t_local(msg, wait, w2t):
|
def w2t_local(msg, wait, w2t):
|
||||||
@ -149,122 +148,94 @@ def w2t_local(msg, wait, w2t):
|
|||||||
global stop
|
global stop
|
||||||
if stop == 0 and wait != 0:
|
if stop == 0 and wait != 0:
|
||||||
sleep(1)
|
sleep(1)
|
||||||
w2t(msg, wait)
|
w2t(msg, wait, 0, 'orange')
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def single_file_process(data_file, wb_result, count, av, rr, axis, vel, trq, w2t, rpm):
|
def single_file_process(data_file, wb_result, count, av, rr, axis, vel, trq, w2t, estop):
|
||||||
# 功能:完成单个数据文件的处理
|
# 功能:完成单个数据文件的处理
|
||||||
# 参数:如上
|
# 参数:如上
|
||||||
# 返回值:-
|
# 返回值:-
|
||||||
if data_file.endswith('.data'):
|
df = read_csv(data_file, sep='\t')
|
||||||
sep = '\t'
|
|
||||||
df = read_csv(data_file, sep=sep)
|
|
||||||
elif data_file.endswith('.csv'):
|
|
||||||
sep = ','
|
|
||||||
df = read_csv(data_file, sep=sep, encoding='gbk', header=8)
|
|
||||||
|
|
||||||
conditions = sorted(data_file.split('\\')[-2].split('_')[1:])
|
conditions = sorted(data_file.split('\\')[-2].split('_')) # ['loadxx', 'reachxx', 'speedxx']
|
||||||
result_sheet_name = find_result_sheet_name(conditions, count)
|
result_sheet_name = find_result_sheet_name(conditions, count)
|
||||||
ws_result = wb_result[result_sheet_name]
|
ws_result = wb_result[result_sheet_name]
|
||||||
|
|
||||||
row_max, row_start, flag = find_row_start(data_file, df, conditions, av, rr, axis, vel, w2t, rpm)
|
row_start, row_end = find_row_start(data_file, df, conditions, av, rr, axis, vel, w2t, estop)
|
||||||
|
copy_data_to_result(df, ws_result, row_start, row_end, vel, trq, estop)
|
||||||
copy_data_to_result(flag, df, ws_result, row_max, row_start, vel, trq, rpm)
|
|
||||||
ws_result["C2"] = int(2)
|
|
||||||
ws_result["G2"] = int(10+4)
|
|
||||||
|
|
||||||
|
|
||||||
def copy_data_to_result(flag, df, ws_result, row_max, row_start, vel, trq, rpm):
|
def copy_data_to_result(df, ws_result, row_start, row_end, vel, trq, estop):
|
||||||
# 功能:将数据文件中有效数据拷贝至结果文件对应的 sheet
|
# 功能:将数据文件中有效数据拷贝至结果文件对应的 sheet
|
||||||
# 参数:如上
|
# 参数:如上
|
||||||
# 返回值:-
|
# 返回值:-
|
||||||
# 结果文件数据清零
|
# 结果文件数据清零
|
||||||
for row in ws_result.iter_rows(min_row=2, min_col=1, max_row=2000, max_col=2):
|
|
||||||
for cell in row:
|
|
||||||
cell.value = None
|
|
||||||
|
|
||||||
if flag == 1:
|
|
||||||
# 将合适的数据复制到结果文件
|
|
||||||
row_max = row_start + 399 if row_max-row_start > 400 else row_max
|
|
||||||
rc = 1 if rpm == 1 else 1000
|
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for i in range(row_start, row_max+1):
|
for _row in range(row_start, row_end + 1):
|
||||||
data.append(df.iloc[i, vel-1] * rpm)
|
data.append(df.iloc[_row, vel-1])
|
||||||
data.append(df.iloc[i, trq-1] * rc)
|
data.append(df.iloc[_row, trq-1])
|
||||||
|
data.append(df.iloc[_row, estop-1])
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for row in ws_result.iter_rows(min_row=2, min_col=1, max_row=row_max - row_start + 2, max_col=2):
|
row_max = 2000 if row_end-row_start < 2000 else row_end-row_start+20
|
||||||
for cell in row:
|
for _row in range(2, row_max):
|
||||||
cell.value = data[i]
|
try:
|
||||||
i = i + 1
|
ws_result.cell(row=_row, column=1).value = data[i]
|
||||||
else:
|
ws_result.cell(row=_row, column=2).value = data[i+1]
|
||||||
pass
|
ws_result.cell(row=_row, column=3).value = data[i+2]
|
||||||
|
i += 3
|
||||||
|
except:
|
||||||
|
ws_result.cell(row=_row, column=1).value = None
|
||||||
|
ws_result.cell(row=_row, column=2).value = None
|
||||||
|
ws_result.cell(row=_row, column=3).value = None
|
||||||
|
|
||||||
|
|
||||||
def find_result_sheet_name(conditions, count):
|
def find_result_sheet_name(conditions, count):
|
||||||
# 功能:获取结果文件准确的sheet页名称
|
# 功能:获取结果文件准确的sheet页名称
|
||||||
# 参数:臂展和速度的列表
|
# 参数:臂展和速度的列表
|
||||||
# 返回值:结果文件对应的sheet name
|
# 返回值:结果文件对应的sheet name
|
||||||
# 33%臂展_33%速度_正1
|
# 33%负载_33%速度_1 - ['loadxx', 'reachxx', 'speedxx']
|
||||||
reach = conditions[0].removeprefix('reach')
|
load = conditions[0].removeprefix('load')
|
||||||
speed = conditions[1].removeprefix('speed')
|
speed = conditions[2].removeprefix('speed')
|
||||||
result_sheet_name = f"{reach}%臂展_{speed}%速度_正{count}"
|
result_sheet_name = f"{load}%负载_{speed}%速度_{count}"
|
||||||
|
|
||||||
return result_sheet_name
|
return result_sheet_name
|
||||||
|
|
||||||
|
|
||||||
def find_row_start(data_file, df, conditions, av, rr, axis, vel, w2t, rpm):
|
def find_row_start(data_file, df, conditions, av, rr, axis, vel, w2t, estop):
|
||||||
# 功能:查找数据文件中有效数据的行号,也即最后一个速度下降的点位
|
# 功能:查找数据文件中有效数据的行号,也即最后一个速度下降的点位
|
||||||
# 参数:如上
|
# 参数:如上
|
||||||
# 返回值:速度下降点位,最后的数据点位
|
# 返回值:速度下降点位,最后的数据点位
|
||||||
ratio = float(conditions[1].removeprefix('speed'))/100
|
ratio = float(conditions[2].removeprefix('speed'))/100
|
||||||
speed_max = av * ratio * rr / 6
|
av_max = av * ratio
|
||||||
row_max = row_start = df.index[-1]
|
row_max = df.index[-1]
|
||||||
|
# threshold = 30 if axis == 2 and conditions[0].removeprefix('load') == '100' else 10
|
||||||
|
threshold = 0.95
|
||||||
|
|
||||||
threshold, step = get_threshold_step(data_file, axis)
|
for _row in range(row_max, -1, -1):
|
||||||
while row_start > step+1:
|
if df.iloc[_row, estop-1] != 0:
|
||||||
speed = abs(df.iloc[row_start, vel-1] * rpm)
|
row_start = _row-20 if _row-20 > 0 else 0
|
||||||
if int(speed) < 1:
|
|
||||||
row_start -= 50
|
|
||||||
continue
|
|
||||||
|
|
||||||
_ = []
|
|
||||||
for i in range(row_start, row_start-step+1, -1):
|
|
||||||
_.append(df.iloc[i, vel-1] * rpm)
|
|
||||||
speed_avg = abs(sum(_))/len(_)
|
|
||||||
|
|
||||||
if abs(speed_avg-speed_max) < threshold:
|
|
||||||
row_start = row_start - 10
|
|
||||||
flag = 1
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
row_start -= step
|
w2t(f"数据文件 {data_file} 采集的数据中没有 ESTOP 为非 0 的情况,需要确认", 0, 9, 'red')
|
||||||
|
|
||||||
|
for _row in range(row_start, row_max):
|
||||||
|
speed_row = (df.iloc[_row, vel-1] * 180) / 3.1415926 * rr * 60 / 360
|
||||||
|
if abs(speed_row) < 1:
|
||||||
|
row_end = _row+100 if _row+100 <= row_max else row_max
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
msg = f"可能是{data_file}这个文件数据采集有问题,比如未采集理论速度值,也有可能是程序步长设定问题,请检查......"
|
w2t(f"数据文件 {data_file} 最后的速度未降为零 ", 0, 10, 'red')
|
||||||
w2t(msg)
|
|
||||||
flag = 0
|
|
||||||
|
|
||||||
return row_max, row_start, flag
|
av_estop = abs((df.iloc[row_start-10:row_start+10, vel-1].abs().mean() * 180) / 3.1415926)
|
||||||
|
if abs(av_estop/av_max) < threshold:
|
||||||
|
filename = data_file.split('\\')[-1]
|
||||||
|
w2t(f"[av_estop: {av_estop:.2f} | shouldbe: {av_max:.2f}] 数据文件 {filename} 触发 ESTOP 时未采集到指定百分比的最大速度,需要检查", 0, 0, '#8A2BE2')
|
||||||
|
|
||||||
|
return row_start, row_end
|
||||||
def get_threshold_step(excel_file, axis):
|
|
||||||
# 功能:负载和速度100%,且是j2的时候,做特殊处理
|
|
||||||
# 参数:新生成的excel,轴号
|
|
||||||
# 返回值:速度差阈值,处理步长
|
|
||||||
conditions = sorted(excel_file.split('\\')[-2].split('_'))
|
|
||||||
# 只有负载和速度是100%时,才会启用更敏感的step
|
|
||||||
flg = 1 if conditions[0][-3:] == '100' and conditions[2][-3:] == '100' else 0
|
|
||||||
if flg == 1 and axis == 2:
|
|
||||||
threshold = 30
|
|
||||||
step = 5
|
|
||||||
else:
|
|
||||||
threshold = 10
|
|
||||||
step = 5
|
|
||||||
|
|
||||||
return threshold, step
|
|
||||||
|
|
||||||
|
|
||||||
def traversal_files(path, w2t):
|
def traversal_files(path, w2t):
|
||||||
@ -273,7 +244,7 @@ def traversal_files(path, w2t):
|
|||||||
# 返回值:路径下的文件夹列表 路径下的文件列表
|
# 返回值:路径下的文件夹列表 路径下的文件列表
|
||||||
if not exists(path):
|
if not exists(path):
|
||||||
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
||||||
w2t(msg, 0, 1)
|
w2t(msg, 0, 1, 'red')
|
||||||
else:
|
else:
|
||||||
dirs = []
|
dirs = []
|
||||||
files = []
|
files = []
|
||||||
@ -286,32 +257,33 @@ def traversal_files(path, w2t):
|
|||||||
return dirs, files
|
return dirs, files
|
||||||
|
|
||||||
|
|
||||||
def main(path, av, rr, rpm, axis, vel, trq, w2t):
|
def main(path, av, rr, axis, vel, trq, estop, w2t):
|
||||||
# 功能:执行处理所有数据文件
|
# 功能:执行处理所有数据文件
|
||||||
# 参数:initialization函数的返回值
|
# 参数:initialization函数的返回值
|
||||||
# 返回值:-
|
# 返回值:-
|
||||||
time_start = time()
|
time_start = time()
|
||||||
raw_data_dirs, result_files = traversal_files(path, w2t)
|
raw_data_dirs, result_files = traversal_files(path, w2t)
|
||||||
prefix = []
|
|
||||||
for raw_data_dir in raw_data_dirs:
|
|
||||||
prefix.append(raw_data_dir.split('\\')[-1].split("_")[0])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# threads = []
|
# threads = []
|
||||||
check_files(raw_data_dirs, result_files, w2t)
|
check_files(raw_data_dirs, result_files, w2t)
|
||||||
|
|
||||||
|
prefix = []
|
||||||
|
for raw_data_dir in raw_data_dirs:
|
||||||
|
prefix.append(raw_data_dir.split('\\')[-1].split("_")[0])
|
||||||
|
|
||||||
for result_file in result_files:
|
for result_file in result_files:
|
||||||
if result_file.split('\\')[-1].split('_')[0] not in set(prefix):
|
if result_file.split('\\')[-1].split('_')[0] not in set(prefix):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
now_doing_msg(result_file, 'start', w2t)
|
now_doing_msg(result_file, 'start', w2t)
|
||||||
data_process(result_file, raw_data_dirs, av, rr, axis, vel, trq, w2t, rpm)
|
data_process(result_file, raw_data_dirs, av, rr, axis, vel, trq, w2t, estop)
|
||||||
# threads.append(Thread(target=data_process, args=(result_file, raw_data_dirs, AV, RR, RC, AXIS)))
|
# threads.append(Thread(target=data_process, args=(result_file, raw_data_dirs, AV, RR, RC, AXIS)))
|
||||||
# [t.start() for t in threads]
|
# [t.start() for t in threads]
|
||||||
# [t.join() for t in threads]
|
# [t.join() for t in threads]
|
||||||
except Exception as Err:
|
except Exception as Err:
|
||||||
msg = f"出现错误:{Err}\n程序运行错误,请检查配置文件是否准确设定,以及数据文件组织是否正确,也有可能是结果文件损坏,尝试重新复制一份,再运行!"
|
msg = f"出现错误:{Err}\n程序运行错误,请检查配置文件是否准确设定,以及数据文件组织是否正确,也有可能是结果文件损坏,尝试重新复制一份,再运行!"
|
||||||
w2t(msg)
|
w2t(msg, 0, 11, 'red')
|
||||||
|
|
||||||
w2t("----------------------------------------------------------")
|
w2t("----------------------------------------------------------")
|
||||||
w2t("全部处理完毕")
|
w2t("全部处理完毕")
|
||||||
@ -323,4 +295,4 @@ def main(path, av, rr, rpm, axis, vel, trq, w2t):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
stop = 0
|
stop = 0
|
||||||
main(path=argv[1], av=argv[2], rr=argv[3], rpm=argv[4], axis=argv[5], vel=argv[6], trq=argv[7], w2t=argv[8])
|
main(path=argv[1], av=argv[2], rr=argv[3], axis=argv[4], vel=argv[5], trq=argv[6], estop=argv[7], w2t=argv[8])
|
@ -7,6 +7,8 @@ from re import match
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from csv import reader
|
from csv import reader
|
||||||
|
|
||||||
|
|
||||||
class GetThreadResult(Thread):
|
class GetThreadResult(Thread):
|
||||||
def __init__(self, func, args=()):
|
def __init__(self, func, args=()):
|
||||||
super(GetThreadResult, self).__init__()
|
super(GetThreadResult, self).__init__()
|
||||||
@ -31,7 +33,7 @@ def w2t_local(msg, wait, w2t):
|
|||||||
global stop
|
global stop
|
||||||
if stop == 0 and wait != 0:
|
if stop == 0 and wait != 0:
|
||||||
sleep(1)
|
sleep(1)
|
||||||
w2t(msg, wait)
|
w2t(msg, wait, 0, 'orange')
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -42,7 +44,7 @@ def traversal_files(path, w2t):
|
|||||||
# 返回值:路径下的文件夹列表 路径下的文件列表
|
# 返回值:路径下的文件夹列表 路径下的文件列表
|
||||||
if not exists(path):
|
if not exists(path):
|
||||||
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
||||||
w2t(msg, 0, 8)
|
w2t(msg, 0, 8, 'red')
|
||||||
else:
|
else:
|
||||||
dirs = []
|
dirs = []
|
||||||
files = []
|
files = []
|
||||||
@ -64,16 +66,16 @@ def initialization(path, sub, w2t):
|
|||||||
if sub != 'cycle':
|
if sub != 'cycle':
|
||||||
if not (match('j[1-7].*\\.data', filename) or match('j[1-7].*\\.csv', filename)):
|
if not (match('j[1-7].*\\.data', filename) or match('j[1-7].*\\.csv', filename)):
|
||||||
msg = f"所有文件必须以 jx_ 开头,以 .data/csv 结尾(x取值1-7),请检查后重新运行。"
|
msg = f"所有文件必须以 jx_ 开头,以 .data/csv 结尾(x取值1-7),请检查后重新运行。"
|
||||||
w2t(msg, 0, 6)
|
w2t(msg, 0, 6, 'red')
|
||||||
else:
|
else:
|
||||||
if filename.endswith('.xlsx'):
|
if filename.endswith('.xlsx'):
|
||||||
count += 1
|
count += 1
|
||||||
elif not (match('j[1-7].*\\.data', filename) or match('j[1-7].*\\.csv', filename)):
|
elif not (match('j[1-7].*\\.data', filename) or match('j[1-7].*\\.csv', filename)):
|
||||||
msg = f"所有文件必须以 jx_ 开头,以 .data/csv 结尾(x取值1-7),请检查后重新运行。"
|
msg = f"所有文件必须以 jx_ 开头,以 .data/csv 结尾(x取值1-7),请检查后重新运行。"
|
||||||
w2t(msg, 0, 7)
|
w2t(msg, 0, 7, 'red')
|
||||||
|
|
||||||
if sub == 'cycle' and count != 1:
|
if sub == 'cycle' and count != 1:
|
||||||
w2t("未找到电机电流数据处理excel表格,确认后重新运行!", 0, 5)
|
w2t("未找到电机电流数据处理excel表格,确认后重新运行!", 0, 5, 'red')
|
||||||
|
|
||||||
return data_files
|
return data_files
|
||||||
|
|
||||||
@ -138,8 +140,7 @@ def current_cycle(dur, data_files, rcs, vel, trq, trqh, rpm, w2t):
|
|||||||
else:
|
else:
|
||||||
single.append(data_file)
|
single.append(data_file)
|
||||||
|
|
||||||
w2t(f"正在打开文件 {result},需要 10s 左右", 1)
|
w2t(f"正在打开文件 {result},需要 10s 左右", 1, 0, 'orange')
|
||||||
|
|
||||||
global stop
|
global stop
|
||||||
stop = 0
|
stop = 0
|
||||||
t_excel = GetThreadResult(load_workbook, args=(result, ))
|
t_excel = GetThreadResult(load_workbook, args=(result, ))
|
||||||
@ -166,7 +167,7 @@ def current_cycle(dur, data_files, rcs, vel, trq, trqh, rpm, w2t):
|
|||||||
else:
|
else:
|
||||||
p_scenario(wb, single, vel, trq, rpm, dur, w2t)
|
p_scenario(wb, single, vel, trq, rpm, dur, w2t)
|
||||||
|
|
||||||
w2t(f"正在保存文件 {result},需要 10s 左右", 1)
|
w2t(f"正在保存文件 {result},需要 10s 左右", 1, 0, 'orange')
|
||||||
stop = 0
|
stop = 0
|
||||||
t_excel = Thread(target=wb.save, args=(result, ))
|
t_excel = Thread(target=wb.save, args=(result, ))
|
||||||
t_wait = Thread(target=w2t_local, args=('.', 1, w2t))
|
t_wait = Thread(target=w2t_local, args=('.', 1, w2t))
|
||||||
@ -180,7 +181,7 @@ def current_cycle(dur, data_files, rcs, vel, trq, trqh, rpm, w2t):
|
|||||||
w2t("全部处理完毕")
|
w2t("全部处理完毕")
|
||||||
|
|
||||||
|
|
||||||
def find_point(flag, df, _row_s, _row_e, w2t, exitcode, threshold, step, end_point):
|
def find_point(data_file, pos, flag, df, _row_s, _row_e, w2t, exitcode, threshold, step, end_point):
|
||||||
if flag == 'lt':
|
if flag == 'lt':
|
||||||
while _row_e > end_point:
|
while _row_e > end_point:
|
||||||
speed_avg = df.iloc[_row_s:_row_e, 0].abs().mean()
|
speed_avg = df.iloc[_row_s:_row_e, 0].abs().mean()
|
||||||
@ -191,7 +192,7 @@ def find_point(flag, df, _row_s, _row_e, w2t, exitcode, threshold, step, end_poi
|
|||||||
else:
|
else:
|
||||||
return _row_s, _row_e
|
return _row_s, _row_e
|
||||||
else:
|
else:
|
||||||
w2t(f"数据有误,需要检查,无法找到第{exitcode}个有效点...", 0, exitcode)
|
w2t(f"[{pos}] {data_file}数据有误,需要检查,无法找到第{exitcode}个有效点...", 0, exitcode, 'red')
|
||||||
elif flag == 'gt':
|
elif flag == 'gt':
|
||||||
while _row_e > end_point:
|
while _row_e > end_point:
|
||||||
speed_avg = df.iloc[_row_s:_row_e, 0].abs().mean()
|
speed_avg = df.iloc[_row_s:_row_e, 0].abs().mean()
|
||||||
@ -202,7 +203,7 @@ def find_point(flag, df, _row_s, _row_e, w2t, exitcode, threshold, step, end_poi
|
|||||||
else:
|
else:
|
||||||
return _row_s, _row_e
|
return _row_s, _row_e
|
||||||
else:
|
else:
|
||||||
w2t(f"数据有误,需要检查,无法找到有效起始点或结束点...", 0, exitcode)
|
w2t(f"[{pos}] {data_file}数据有误,需要检查,无法找到有效起始点或结束点...", 0, exitcode, 'red')
|
||||||
|
|
||||||
|
|
||||||
def p_single(wb, single, vel, trq, rpm, w2t):
|
def p_single(wb, single, vel, trq, rpm, w2t):
|
||||||
@ -244,28 +245,28 @@ def p_single(wb, single, vel, trq, rpm, w2t):
|
|||||||
speed_avg = df.iloc[_row_s:_row_e, 0].abs().mean()
|
speed_avg = df.iloc[_row_s:_row_e, 0].abs().mean()
|
||||||
if speed_avg < 2:
|
if speed_avg < 2:
|
||||||
# 过滤尾部为零无效数据
|
# 过滤尾部为零无效数据
|
||||||
_row_s, _row_e = find_point('lt', df, _row_s, _row_e, w2t, 1, threshold=2, step=_step, end_point=_end_point)
|
_row_s, _row_e = find_point(data_file, 'a1', 'lt', df, _row_s, _row_e, w2t, 1, threshold=5, step=_step, end_point=_end_point)
|
||||||
# 找到第一个起始点 row_end,继续找到有数据的部分,后面有一段有效数据区
|
# 找到第一个起始点 row_end,继续找到有数据的部分,后面有一段有效数据区
|
||||||
row_end = _row_e - _adjust
|
row_end = _row_e - _adjust
|
||||||
_row_e -= _end_point
|
_row_e -= _end_point
|
||||||
_row_s -= _end_point
|
_row_s -= _end_point
|
||||||
_row_s, _row_e = find_point('gt', df, _row_s, _row_e, w2t, 3, threshold=2, step=_step, end_point=_end_point)
|
_row_s, _row_e = find_point(data_file, 'a2', 'gt', df, _row_s, _row_e, w2t, 3, threshold=5, step=_step, end_point=_end_point)
|
||||||
# 速度已经快要降为零了,继续寻找下一个速度上升点
|
# 速度已经快要降为零了,继续寻找下一个速度上升点
|
||||||
_row_e -= _end_point
|
_row_e -= _end_point
|
||||||
_row_s -= _end_point
|
_row_s -= _end_point
|
||||||
_row_s, _row_e = find_point('lt', df, _row_s, _row_e, w2t, 3, threshold=2, step=_step, end_point=_end_point)
|
_row_s, _row_e = find_point(data_file, 'a3', 'lt', df, _row_s, _row_e, w2t, 3, threshold=5, step=_step, end_point=_end_point)
|
||||||
elif speed_avg > 2:
|
elif speed_avg > 2:
|
||||||
# 过滤尾部非零无效数据
|
# 过滤尾部非零无效数据
|
||||||
_row_s, _row_e = find_point('gt', df, _row_s, _row_e, w2t, 2, threshold=2, step=_step, end_point=_end_point)
|
_row_s, _row_e = find_point(data_file, 'b1', 'gt', df, _row_s, _row_e, w2t, 2, threshold=5, step=_step, end_point=_end_point)
|
||||||
# 找到第一个起始点 row_end,继续找到有数据的部分,后面有一段零数据区
|
# 找到第一个起始点 row_end,继续找到有数据的部分,后面有一段零数据区
|
||||||
row_end = _row_e - _adjust
|
row_end = _row_e - _adjust
|
||||||
_row_e -= _end_point
|
_row_e -= _end_point
|
||||||
_row_s -= _end_point
|
_row_s -= _end_point
|
||||||
_row_s, _row_e = find_point('lt', df, _row_s, _row_e, w2t, 4, threshold=2, step=_step, end_point=_end_point)
|
_row_s, _row_e = find_point(data_file, 'b2', 'lt', df, _row_s, _row_e, w2t, 4, threshold=5, step=_step, end_point=_end_point)
|
||||||
# 目前已经有一点的速度值了,继续往前搜寻下一个速度为零的点
|
# 目前已经有一点的速度值了,继续往前搜寻下一个速度为零的点
|
||||||
_row_e -= _end_point
|
_row_e -= _end_point
|
||||||
_row_s -= _end_point
|
_row_s -= _end_point
|
||||||
_row_s, _row_e = find_point('gt', df, _row_s, _row_e, w2t, 4, threshold=2, step=_step, end_point=_end_point)
|
_row_s, _row_e = find_point(data_file, 'b3', 'gt', df, _row_s, _row_e, w2t, 4, threshold=5, step=_step, end_point=_end_point)
|
||||||
|
|
||||||
row_start = _row_s + _adjust
|
row_start = _row_s + _adjust
|
||||||
data = []
|
data = []
|
||||||
@ -274,7 +275,7 @@ def p_single(wb, single, vel, trq, rpm, w2t):
|
|||||||
data.append(df.iloc[row, 1])
|
data.append(df.iloc[row, 1])
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for row in ws.iter_rows(min_row=2, min_col=2, max_row=15000, max_col=3):
|
for row in ws.iter_rows(min_row=2, min_col=2, max_row=70000, max_col=3):
|
||||||
for cell in row:
|
for cell in row:
|
||||||
try:
|
try:
|
||||||
_ = f"{data[i]:.2f}"
|
_ = f"{data[i]:.2f}"
|
||||||
@ -316,7 +317,7 @@ def p_scenario(wb, single, vel, trq, rpm, dur, w2t):
|
|||||||
row_start = 300
|
row_start = 300
|
||||||
row_end = row_start + int(dur/cycle)
|
row_end = row_start + int(dur/cycle)
|
||||||
if row_end > df.index[-1]:
|
if row_end > df.index[-1]:
|
||||||
w2t(f"位置超限:{data_file} 共有 {df.index[-1]} 条数据,无法取到第 {row_end} 条数据...", 0, 9)
|
w2t(f"位置超限:{data_file} 共有 {df.index[-1]} 条数据,无法取到第 {row_end} 条数据,需要确认场景周期时间...", 0, 9, 'red')
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for row in range(row_start, row_end):
|
for row in range(row_start, row_end):
|
||||||
@ -324,7 +325,7 @@ def p_scenario(wb, single, vel, trq, rpm, dur, w2t):
|
|||||||
data.append(df.iloc[row, 1])
|
data.append(df.iloc[row, 1])
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for row in ws.iter_rows(min_row=2, min_col=2, max_row=15000, max_col=3):
|
for row in ws.iter_rows(min_row=2, min_col=2, max_row=70000, max_col=3):
|
||||||
for cell in row:
|
for cell in row:
|
||||||
try:
|
try:
|
||||||
_ = f"{data[i]:.2f}"
|
_ = f"{data[i]:.2f}"
|
@ -12,7 +12,7 @@ def traversal_files(path, w2t):
|
|||||||
# 返回值:路径下的文件夹列表 路径下的文件列表
|
# 返回值:路径下的文件夹列表 路径下的文件列表
|
||||||
if not exists(path):
|
if not exists(path):
|
||||||
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
msg = f'数据文件夹{path}不存在,请确认后重试......'
|
||||||
w2t(msg, 0, 1)
|
w2t(msg, 0, 1, 'red')
|
||||||
else:
|
else:
|
||||||
dirs = files = []
|
dirs = files = []
|
||||||
for item in scandir(path):
|
for item in scandir(path):
|
||||||
@ -162,7 +162,7 @@ def main(path, w2t):
|
|||||||
ws.cell(row=i, column=7).value = None
|
ws.cell(row=i, column=7).value = None
|
||||||
tmpfile = f"{path}\\data.txt"
|
tmpfile = f"{path}\\data.txt"
|
||||||
except Exception as Err:
|
except Exception as Err:
|
||||||
w2t(f"发生错误:{Err}", 0, 2)
|
w2t(f"发生错误:{Err}", 0, 2, 'red')
|
||||||
|
|
||||||
p_files = []
|
p_files = []
|
||||||
for file in files:
|
for file in files:
|
||||||
@ -187,7 +187,7 @@ def main(path, w2t):
|
|||||||
wb.close()
|
wb.close()
|
||||||
|
|
||||||
if len(p_files) == 0:
|
if len(p_files) == 0:
|
||||||
w2t(f"目录 {path} 下没有需要处理的文件,需要确认......", 0, 3)
|
w2t(f"目录 {path} 下没有需要处理的文件,需要确认......", 0, 3, 'red')
|
||||||
else:
|
else:
|
||||||
remove(tmpfile)
|
remove(tmpfile)
|
||||||
w2t("------------------------------------------")
|
w2t("------------------------------------------")
|
186
aio/code/wavelogger.py
Normal file
186
aio/code/wavelogger.py
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
def find_point(bof, step, pos, data_file, flag, df, row, w2t):
|
||||||
|
# bof: backward or forward
|
||||||
|
# pos: used for debug
|
||||||
|
# flag: greater than or lower than
|
||||||
|
if flag == 'gt':
|
||||||
|
while 0 < row < df.index[-1]-100:
|
||||||
|
_value = df.iloc[row, 2]
|
||||||
|
if _value > 2:
|
||||||
|
if bof == 'backward':
|
||||||
|
row -= step
|
||||||
|
elif bof == 'forward':
|
||||||
|
row += step
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
if bof == 'backward':
|
||||||
|
row_target = row - step
|
||||||
|
elif bof == 'forward':
|
||||||
|
row_target = row + step
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
if bof == 'backward':
|
||||||
|
w2t(f"[{pos}] 在 {data_file} 中,无法正确识别数据,需要确认...", 0, 2, 'red')
|
||||||
|
elif bof == 'forward':
|
||||||
|
row_target = row + 100
|
||||||
|
elif flag == 'lt':
|
||||||
|
while 0 < row < df.index[-1]-100:
|
||||||
|
_value = df.iloc[row, 2]
|
||||||
|
if _value < 2:
|
||||||
|
if bof == 'backward':
|
||||||
|
row -= step
|
||||||
|
elif bof == 'forward':
|
||||||
|
row += step
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
if bof == 'backward':
|
||||||
|
row_target = row - step
|
||||||
|
elif bof == 'forward':
|
||||||
|
row_target = row + step
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
if bof == 'backward':
|
||||||
|
w2t(f"[{pos}] 在 {data_file} 中,无法正确识别数据,需要确认...", 0, 3, 'red')
|
||||||
|
elif bof == 'forward':
|
||||||
|
row_target = row + 100
|
||||||
|
|
||||||
|
return row_target
|
||||||
|
|
||||||
|
|
||||||
|
def get_cycle_info(data_file, df, row, step, w2t):
|
||||||
|
# end -> middle: low
|
||||||
|
# middle -> start: high
|
||||||
|
# 1. 从最后读取数据,无论是大于1还是小于1,都舍弃,找到相反的值的起始点
|
||||||
|
# 2. 从起始点,继续往前寻找,找到与之数值相反的中间点
|
||||||
|
# 3. 从中间点,继续往前寻找,找到与之数值相反的结束点,至此,得到了高低数值的时间区间以及一轮的周期时间
|
||||||
|
if df.iloc[row, 2] < 2:
|
||||||
|
row = find_point('backward', step, 'a1', data_file, 'lt', df, row, w2t)
|
||||||
|
|
||||||
|
_row = find_point('backward', step, 'a2', data_file, 'gt', df, row, w2t)
|
||||||
|
_row = find_point('backward', step, 'a3', data_file, 'lt', df, _row, w2t)
|
||||||
|
row_end = find_point('backward', step, 'a4', data_file, 'gt', df, _row, w2t)
|
||||||
|
row_middle = find_point('backward', step, 'a5', data_file, 'lt', df, row_end, w2t)
|
||||||
|
row_start = find_point('backward', step, 'a6', data_file, 'gt', df, row_middle, w2t)
|
||||||
|
|
||||||
|
return row_end-row_middle, row_middle-row_start, row_end-row_start
|
||||||
|
|
||||||
|
|
||||||
|
def initialization(path, w2t):
|
||||||
|
_, data_files = traversal_files(path, w2t)
|
||||||
|
|
||||||
|
for data_file in data_files:
|
||||||
|
if not data_file.lower().endswith('.csv'):
|
||||||
|
w2t(f"{data_file} 文件后缀错误,只允许 .csv 文件,需要确认!", 0, 1, 'red')
|
||||||
|
|
||||||
|
return data_files
|
||||||
|
|
||||||
|
|
||||||
|
def preparation(data_file, wb, w2t):
|
||||||
|
shtname = data_file.split('\\')[-1].split('.')[0]
|
||||||
|
ws = wb.create_sheet(shtname)
|
||||||
|
csv_reader = reader(open(data_file))
|
||||||
|
i = 0
|
||||||
|
begin = 70
|
||||||
|
for row in csv_reader:
|
||||||
|
i += 1
|
||||||
|
if i == 1:
|
||||||
|
begin = int(row[1])
|
||||||
|
break
|
||||||
|
df = read_csv(data_file, sep=',', encoding='gbk', skip_blank_lines=False, header=begin - 1, on_bad_lines='warn')
|
||||||
|
low, high, cycle = get_cycle_info(data_file, df, df.index[-1]-110, 5, w2t)
|
||||||
|
|
||||||
|
return ws, df, low, high, cycle
|
||||||
|
|
||||||
|
|
||||||
|
def single_file_proc(ws, data_file, df, low, high, cycle, w2t):
|
||||||
|
_row = _row_lt = _row_gt = count = 1
|
||||||
|
_step = 5
|
||||||
|
_data = {}
|
||||||
|
row_max = df.index[-1]-100
|
||||||
|
print(data_file)
|
||||||
|
while _row < row_max:
|
||||||
|
if count not in _data.keys():
|
||||||
|
_data[count] = []
|
||||||
|
|
||||||
|
_value = df.iloc[_row, 2]
|
||||||
|
if _value < 2:
|
||||||
|
_row_lt = find_point('forward', _step, 'c'+str(_row), data_file, 'lt', df, _row, w2t)
|
||||||
|
_start = int(_row_gt + (_row_lt - _row_gt - 50) / 2)
|
||||||
|
_end = _start + 50
|
||||||
|
value = df.iloc[_start:_end, 2].mean() + df.iloc[_start:_end, 2].std()
|
||||||
|
_data[count].append(value)
|
||||||
|
else:
|
||||||
|
_row_gt = find_point('forward', _step, 'c'+str(_row), data_file, 'gt', df, _row, w2t)
|
||||||
|
if _row_gt - _row_lt > cycle * 2:
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
_row = max(_row_gt, _row_lt)
|
||||||
|
|
||||||
|
for i in range(2, 10):
|
||||||
|
ws.cell(row=1, column=i).value = f"第{i-1}次测试"
|
||||||
|
ws.cell(row=i, column=1).value = f"第{i-1}次精度变化"
|
||||||
|
|
||||||
|
print(_data)
|
||||||
|
for i in sorted(_data.keys()):
|
||||||
|
_row = 2
|
||||||
|
_column = i + 1
|
||||||
|
for value in _data[i]:
|
||||||
|
ws.cell(row=_row, column=_column).value = float(value)
|
||||||
|
_row += 1
|
||||||
|
|
||||||
|
|
||||||
|
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}")
|
||||||
|
single_file_proc(ws, data_file, df, low, high, cycle, w2t)
|
||||||
|
|
||||||
|
wd = data_files[0].split('\\')
|
||||||
|
del wd[-1]
|
||||||
|
wd = '\\'.join(wd)
|
||||||
|
filename = wd + '\\result.xlsx'
|
||||||
|
wb.save(filename)
|
||||||
|
wb.close()
|
||||||
|
w2t('----------------------------------------')
|
||||||
|
w2t('所有文件均已处理完毕')
|
||||||
|
|
||||||
|
|
||||||
|
def main(path, w2t):
|
||||||
|
data_files = initialization(path, w2t)
|
||||||
|
execution(data_files, w2t)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(path=argv[1], w2t=argv[2])
|
BIN
aio/layout.xlsx
BIN
aio/layout.xlsx
Binary file not shown.
Reference in New Issue
Block a user