pyqt5实现振动波形数据标注工具
1、效果图
2、实现功能
1 、数据库连接
2 、数据筛选
3 、波形图展示、频谱图展示
4 、特征展示:时域、频域
5 、数据标注与添加
6 、模型训练与分类识别
3、部分核心代码
3.1、连接数据库
"""
@contact: 微信 1257309054
@file: mark_main.py
@time: 2023/12/16 20:14
@author: LDC
"""
def btn_link_clicked ( self) :
self. is_link = True
try :
self. source_cur. close( )
self. source_con. close( )
self. target_cur. close( )
self. target_con. close( )
except :
pass
try :
self. source_con = pymysql. connect(
host= '127.0.0.1' ,
user= 'root' ,
password= self. source_password_edit. text( ) ,
database= self. source_database_edit. text( ) ,
port= 3306 ,
charset= 'utf8'
)
self. source_cur = self. source_con. cursor( )
except Exception as e:
self. feature_text. setText( '源数据库连接错误:{}' . format ( e) )
return False
try :
self. target_con = pymysql. connect(
host= '127.0.0.1' ,
user= 'root' ,
password= self. target_password_edit. text( ) ,
database= self. target_database_edit. text( ) ,
port= 3306 ,
charset= 'utf8'
)
self. target_cur = self. target_con. cursor( )
except Exception as e:
self. feature_text. setText( '目标数据库连接错误:{}' . format ( e) )
return False
self. btn_link. setText( '已连接' )
sql = 'SELECT MAX(ID) AS lastRecordId FROM alert_log'
self. target_cur. execute( sql)
self. target_alert_log_id = self. target_cur. fetchone( )
if self. target_alert_log_id[ 0 ] :
self. target_alert_log_id = self. target_alert_log_id[ 0 ] + 1
else :
self. target_alert_log_id = 1
self. target_alert_log_id_edit. setText( str ( self. target_alert_log_id) )
self. feature_text. setText( '源数据库、目标数据库连接成功。表最大记录是:{}' . format ( self. target_alert_log_id) )
3.2、添加到数据库:
"""
@contact: 微信 1257309054
@file: mark_main.py
@time: 2023/12/16 20:14
@author: LDC
"""
def btn_add_clicked ( self) :
try :
sql = """select * from alert_log where id={}""" . format ( self. source_alert_log_ids[ self. source_alert_log_ids_index] )
self. source_cur. execute( sql)
desc = self. source_cur. description
row = self. source_cur. fetchone( )
data_dict = dict ( zip ( [ col[ 0 ] for col in desc] , row) )
data_dict[ 'id' ] = self. target_alert_log_id
data_dict[ 'type_label' ] = self. type_edit. text( )
clos, value = zip ( * data_dict. items( ) )
sql = """INSERT INTO `alert_log` (%s) VALUES (%s)""" % ( ',' . join( clos) , ',' . join( [ '%s' ] * len ( value) ) )
self. target_cur. execute( sql, value)
self. target_con. commit( )
self. feature_text. setText( '添加成功' )
except Exception as e:
self. feature_text. setText( '添加失败:{}' . format ( e) )