|
@@ -16,6 +16,7 @@ import time, datetime
|
|
from pandas.core.frame import DataFrame
|
|
from pandas.core.frame import DataFrame
|
|
from apscheduler.schedulers.blocking import BlockingScheduler
|
|
from apscheduler.schedulers.blocking import BlockingScheduler
|
|
from LIB.MIDDLE.SaftyCenter.DataDiag_Static.DataStatistics import DataSta
|
|
from LIB.MIDDLE.SaftyCenter.DataDiag_Static.DataStatistics import DataSta
|
|
|
|
+from LIB.MIDDLE.SaftyCenter.DataDiag_Static.SC_CtrlSafty import CtrlSafty
|
|
from LIB.MIDDLE.SaftyCenter.DataDiag_Static.DiagDataMerge import DiagDataMerge
|
|
from LIB.MIDDLE.SaftyCenter.DataDiag_Static.DiagDataMerge import DiagDataMerge
|
|
from LIB.MIDDLE.SaftyCenter.DataDiag_Static.SC_SamplingSafty import SamplingSafty
|
|
from LIB.MIDDLE.SaftyCenter.DataDiag_Static.SC_SamplingSafty import SamplingSafty
|
|
from LIB.MIDDLE.SaftyCenter.DataDiag_Static import CBMSBatDiag
|
|
from LIB.MIDDLE.SaftyCenter.DataDiag_Static import CBMSBatDiag
|
|
@@ -29,15 +30,35 @@ import pymysql
|
|
def diag_cal():
|
|
def diag_cal():
|
|
task_on=1
|
|
task_on=1
|
|
global SNnums
|
|
global SNnums
|
|
- global df_Diag_Ram
|
|
|
|
|
|
+ # global df_Diag_Ram
|
|
global start
|
|
global start
|
|
global df_sn
|
|
global df_sn
|
|
|
|
+
|
|
|
|
+ # 算法参数
|
|
|
|
+ host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
|
|
+ port=3306
|
|
|
|
+ db='safety_platform'
|
|
|
|
+ user='qx_algo_rw'
|
|
|
|
+ password=parse.quote_plus('qx@123456')
|
|
|
|
+ db_engine = create_engine(
|
|
|
|
+ "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
|
|
|
|
+ user, password, host, port, db
|
|
|
|
+ ))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................``
|
|
|
|
+ # print("select start_time, end_time, product_id, code, level, info, advice, factory from {}".format(tablename))
|
|
|
|
+ try:
|
|
|
|
+ df_Diag_Ram=pd.read_sql("select start_time, end_time, product_id, code, level, info, advice, Batpos from all_fault_info where factory = '{}'".format('骑享'), db_engine)
|
|
|
|
+ finally:
|
|
|
|
+ db_engine.dispose()
|
|
|
|
+
|
|
#读取结果数据库数据........................................................................................................................................................
|
|
#读取结果数据库数据........................................................................................................................................................
|
|
host1='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
host1='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
port1=3306
|
|
port1=3306
|
|
db1='qx_cas'
|
|
db1='qx_cas'
|
|
- user1='qx_read'
|
|
|
|
- password1='Qx@123456'
|
|
|
|
|
|
+ user1='qx_algo_rw'
|
|
|
|
+ password1='qx@123456'
|
|
mode=1
|
|
mode=1
|
|
tablename1='cellstateestimation_soh'
|
|
tablename1='cellstateestimation_soh'
|
|
tablename2='cellstateestimation_uniform_socvoltdiff'
|
|
tablename2='cellstateestimation_uniform_socvoltdiff'
|
|
@@ -48,8 +69,8 @@ def diag_cal():
|
|
host2='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
|
|
host2='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
|
|
port2=3306
|
|
port2=3306
|
|
db2='qixiang_manage'
|
|
db2='qixiang_manage'
|
|
- user2='qx_query'
|
|
|
|
- password2='@Qx_query'
|
|
|
|
|
|
+ user2='qx_algo_rw'
|
|
|
|
+ password2='qx@123456'
|
|
mode=4
|
|
mode=4
|
|
tablename3='py_battery'
|
|
tablename3='py_battery'
|
|
DBReadOpe=DBDw.DBDownload(host2, port2, db2, user2, password2,mode)
|
|
DBReadOpe=DBDw.DBDownload(host2, port2, db2, user2, password2,mode)
|
|
@@ -58,8 +79,8 @@ def diag_cal():
|
|
host3='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
host3='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
port3=3306
|
|
port3=3306
|
|
db3='safety_platform'
|
|
db3='safety_platform'
|
|
- user3='qx_read'
|
|
|
|
- password3='Qx@123456'
|
|
|
|
|
|
+ user3='qx_algo_rw'
|
|
|
|
+ password3='qx@123456'
|
|
db_engine = create_engine(
|
|
db_engine = create_engine(
|
|
"mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
|
|
"mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
|
|
user3, parse.quote_plus(password3), host3, port3, db3
|
|
user3, parse.quote_plus(password3), host3, port3, db3
|
|
@@ -107,18 +128,20 @@ def diag_cal():
|
|
#电池诊断.....................................................................................................................................................................
|
|
#电池诊断.....................................................................................................................................................................
|
|
CellFltInfo=DataFrame(columns=['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice'])
|
|
CellFltInfo=DataFrame(columns=['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice'])
|
|
df_Diag_Ram_sn = df_Diag_Ram.loc[df_Diag_Ram['product_id']==sn]#历史故障
|
|
df_Diag_Ram_sn = df_Diag_Ram.loc[df_Diag_Ram['product_id']==sn]#历史故障
|
|
- df_Diag_Ram_sn_else = pd.concat([df_Diag_Ram,df_Diag_Ram_sn,df_Diag_Ram_sn]).drop_duplicates(subset=['product_id','code','start_time','Batpos','info'],keep=False)#sn之外的故障
|
|
|
|
|
|
+ df_Diag_Ram_sn_else = df_Diag_Ram.loc[df_Diag_Ram['product_id']!=sn]#sn之外的故障
|
|
CellFltInfo = df_Diag_Ram_sn.drop('Batpos',axis=1)
|
|
CellFltInfo = df_Diag_Ram_sn.drop('Batpos',axis=1)
|
|
#获取当前故障电池的历史故障信息↑↑↑↑↑↑↑↑↑↑↑.......................................................................................................................................
|
|
#获取当前故障电池的历史故障信息↑↑↑↑↑↑↑↑↑↑↑.......................................................................................................................................
|
|
if not df_bms.empty:
|
|
if not df_bms.empty:
|
|
- df_Diag_Batdiag_update_xq=SamplingSafty.main(sn,param,df_bms,CellFltInfo)#学琦计算故障
|
|
|
|
- batDiag=CBMSBatDiag.BatDiag(sn,celltype,df_bms, df_soh, df_uniform, CellFltInfo)#鹏飞计算
|
|
|
|
|
|
+ df_Diag_Batdiag_update_xq=SamplingSafty.main(sn,param,df_bms,CellFltInfo)#学琦计算故障
|
|
|
|
+ df_Diag_Batdiag_update_xq2=CtrlSafty.main(sn,param,df_bms,df_Diag_Batdiag_update_xq)
|
|
|
|
+
|
|
|
|
+ batDiag=CBMSBatDiag.BatDiag(sn,celltype,df_bms, df_soh, df_uniform, df_Diag_Batdiag_update_xq2)#鹏飞计算
|
|
df_Diag_Batdiag_update=batDiag.diag()
|
|
df_Diag_Batdiag_update=batDiag.diag()
|
|
# df_Diag_Batdiag_update=BatDiag.diag()
|
|
# df_Diag_Batdiag_update=BatDiag.diag()
|
|
else:
|
|
else:
|
|
df_Diag_Batdiag_update_xq=DataFrame(columns=['start_time','end_time','product_id','code','level','info','advice','Batpos'])
|
|
df_Diag_Batdiag_update_xq=DataFrame(columns=['start_time','end_time','product_id','code','level','info','advice','Batpos'])
|
|
df_Diag_Batdiag_update=DataFrame(columns=['start_time','end_time','product_id','code','level','info','advice','Batpos'])
|
|
df_Diag_Batdiag_update=DataFrame(columns=['start_time','end_time','product_id','code','level','info','advice','Batpos'])
|
|
- df_Diag_Ram,df_Diag_Ram_add,df_Diag_Ram_Update=DiagDataMerge.DetaMerge(df_Diag_Ram_sn,df_Diag_Batdiag_update_xq,df_Diag_Batdiag_update,df_OprtnSta,df_Diag_Ram_sn_else)
|
|
|
|
|
|
+ df_Diag_Ram_add,df_Diag_Ram_Update=DiagDataMerge.DetaMerge(df_Diag_Ram_sn,df_Diag_Batdiag_update,df_OprtnSta,df_Diag_Ram_sn_else)
|
|
# df_Diag_Ram.to_csv('df_Diag_Ram.csv')
|
|
# df_Diag_Ram.to_csv('df_Diag_Ram.csv')
|
|
# df_Diag_Ram_add.to_csv('df_Diag_Ram_add.csv')
|
|
# df_Diag_Ram_add.to_csv('df_Diag_Ram_add.csv')
|
|
# df_Diag_Ram_Update.to_csv('df_Diag_Ram_add.csv')
|
|
# df_Diag_Ram_Update.to_csv('df_Diag_Ram_add.csv')
|
|
@@ -126,6 +149,7 @@ def diag_cal():
|
|
|
|
|
|
df_Diag_Ram_add.columns = ['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice', 'Batpos']
|
|
df_Diag_Ram_add.columns = ['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice', 'Batpos']
|
|
df_Diag_Ram_add['factory'] = '骑享'
|
|
df_Diag_Ram_add['factory'] = '骑享'
|
|
|
|
+ df_Diag_Ram_add['add_time'] = datetime.datetime.now()
|
|
df_Diag_Ram_add.to_sql("all_fault_info",con=db_engine, if_exists="append",index=False)
|
|
df_Diag_Ram_add.to_sql("all_fault_info",con=db_engine, if_exists="append",index=False)
|
|
# df_Diag_Ram_add.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\01Screen_Problem\result_add.csv',index=False,encoding='GB18030')
|
|
# df_Diag_Ram_add.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\01Screen_Problem\result_add.csv',index=False,encoding='GB18030')
|
|
if len(df_Diag_Ram_Update) > 0:#更改故障
|
|
if len(df_Diag_Ram_Update) > 0:#更改故障
|
|
@@ -134,8 +158,8 @@ def diag_cal():
|
|
logger.info(df_Diag_Ram_Update)
|
|
logger.info(df_Diag_Ram_Update)
|
|
for i in range(0,len(df_Diag_Ram_Update)):
|
|
for i in range(0,len(df_Diag_Ram_Update)):
|
|
sql = '''
|
|
sql = '''
|
|
- update all_fault_info set end_time='{}', Batpos={} where product_id='{}' and code={} and start_time='{}'
|
|
|
|
- '''.format(df_Diag_Ram_Update.loc[i,'end_time'], df_Diag_Ram_Update.loc[i, 'Batpos'],
|
|
|
|
|
|
+ update all_fault_info set update_time={}, end_time='{}', Batpos={} where product_id='{}' and code={} and start_time='{}'
|
|
|
|
+ '''.format(datetime.datetime.now(), df_Diag_Ram_Update.loc[i,'end_time'], df_Diag_Ram_Update.loc[i, 'Batpos'],
|
|
df_Diag_Ram_Update.loc[i,'product_id'], df_Diag_Ram_Update.loc[i,'code'],
|
|
df_Diag_Ram_Update.loc[i,'product_id'], df_Diag_Ram_Update.loc[i,'code'],
|
|
df_Diag_Ram_Update.loc[i,'start_time'])
|
|
df_Diag_Ram_Update.loc[i,'start_time'])
|
|
cursor_platform.execute(sql)
|
|
cursor_platform.execute(sql)
|
|
@@ -152,6 +176,7 @@ def diag_cal():
|
|
logger.error(traceback.format_exc)
|
|
logger.error(traceback.format_exc)
|
|
logger.error(str(e))
|
|
logger.error(str(e))
|
|
logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
|
|
logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
|
|
|
|
+
|
|
DBReadOpe.close()
|
|
DBReadOpe.close()
|
|
DBRead.close()
|
|
DBRead.close()
|
|
cursor_platform.close()
|
|
cursor_platform.close()
|
|
@@ -169,8 +194,8 @@ def DaTa_Sta_Week_Task():
|
|
host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
port=3306
|
|
port=3306
|
|
db='safety_platform'
|
|
db='safety_platform'
|
|
- user='qx_read'
|
|
|
|
- password='Qx@123456'
|
|
|
|
|
|
+ user='qx_algo_rw'
|
|
|
|
+ password='qx@123456'
|
|
mode=2
|
|
mode=2
|
|
tablename1='all_fault_info'
|
|
tablename1='all_fault_info'
|
|
|
|
|
|
@@ -188,11 +213,11 @@ def DaTa_Sta_Week_Task():
|
|
#............................获取时间................................
|
|
#............................获取时间................................
|
|
end_time=datetime.datetime.now()
|
|
end_time=datetime.datetime.now()
|
|
# end_time=datetime.datetime.strptime(end_time,'%Y-%m-%d')
|
|
# end_time=datetime.datetime.strptime(end_time,'%Y-%m-%d')
|
|
- start_time=end_time-datetime.timedelta(days=7)
|
|
|
|
- start_time=start_time.strftime('%Y-%m-%d')
|
|
|
|
|
|
+ start_time_week=end_time-datetime.timedelta(days=7)
|
|
|
|
+ start_time_week=start_time_week.strftime('%Y-%m-%d')
|
|
end_time=end_time.strftime('%Y-%m-%d')
|
|
end_time=end_time.strftime('%Y-%m-%d')
|
|
- FltAlarmInfo,Celltype=DataSta.SaftyWarningSta(df_fltinfo,start_time,end_time)
|
|
|
|
- FaultLvlCount=DataSta.WeekInfoSta(df_fltinfo,start_time,end_time)
|
|
|
|
|
|
+ FltAlarmInfo,Celltype=DataSta.SaftyWarningSta(df_fltinfo,start_time_week,end_time)
|
|
|
|
+ FaultLvlCount=DataSta.WeekInfoSta(df_fltinfo,start_time_week,end_time)
|
|
for i in range(1,6):
|
|
for i in range(1,6):
|
|
if not FaultLvlCount[FaultLvlCount['level']==i]['product_id'].empty:
|
|
if not FaultLvlCount[FaultLvlCount['level']==i]['product_id'].empty:
|
|
all_period_fault_info.loc[0,'level'+str(i)+'_count']=int(FaultLvlCount[FaultLvlCount['level']==i]['product_id'].values)
|
|
all_period_fault_info.loc[0,'level'+str(i)+'_count']=int(FaultLvlCount[FaultLvlCount['level']==i]['product_id'].values)
|
|
@@ -234,8 +259,8 @@ def DaTa_Sta_Minutes_Task():
|
|
host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
port=3306
|
|
port=3306
|
|
db='qx_cas'
|
|
db='qx_cas'
|
|
- user='qx_read'
|
|
|
|
- password='Qx@123456'
|
|
|
|
|
|
+ user='qx_algo_rw'
|
|
|
|
+ password='qx@123456'
|
|
mode=3
|
|
mode=3
|
|
tablename2='bat_first_data_time'
|
|
tablename2='bat_first_data_time'
|
|
DBRead=DBDw.DBDownload(host, port, db, user, password,mode)
|
|
DBRead=DBDw.DBDownload(host, port, db, user, password,mode)
|
|
@@ -246,8 +271,8 @@ def DaTa_Sta_Minutes_Task():
|
|
host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
port=3306
|
|
port=3306
|
|
db='safety_platform'
|
|
db='safety_platform'
|
|
- user='qx_read'
|
|
|
|
- password='Qx@123456'
|
|
|
|
|
|
+ user='qx_algo_rw'
|
|
|
|
+ password='qx@123456'
|
|
mode=2
|
|
mode=2
|
|
tablename1='all_fault_info'
|
|
tablename1='all_fault_info'
|
|
db_engine = create_engine(
|
|
db_engine = create_engine(
|
|
@@ -258,7 +283,7 @@ def DaTa_Sta_Minutes_Task():
|
|
with DBRead as DBRead:
|
|
with DBRead as DBRead:
|
|
df_fltinfo=DBRead.getdata('product_id','level','code','start_time','batpos',tablename=tablename1,factory='骑享',sn='',timename='',st='',sp='')#dbdownload经过了改编
|
|
df_fltinfo=DBRead.getdata('product_id','level','code','start_time','batpos',tablename=tablename1,factory='骑享',sn='',timename='',st='',sp='')#dbdownload经过了改编
|
|
|
|
|
|
- df_Diag_Ram=pd.read_sql("select start_time, end_time, product_id, code, level, info, advice, Batpos from all_fault_info where factory = '{}' and Batpos=1".format('骑享'), db_engine)
|
|
|
|
|
|
+ # df_Diag_Ram=pd.read_sql("select start_time, end_time, product_id, code, level, info, advice, Batpos from all_fault_info where factory = '{}' and Batpos=1".format('骑享'), db_engine)
|
|
|
|
|
|
#............................获取时间................................
|
|
#............................获取时间................................
|
|
end_time=datetime.datetime.now()
|
|
end_time=datetime.datetime.now()
|
|
@@ -270,7 +295,7 @@ def DaTa_Sta_Minutes_Task():
|
|
FltAlarmInfo,Celltype=DataSta.SaftyWarningSta(df_fltinfo,start_time,end_time)
|
|
FltAlarmInfo,Celltype=DataSta.SaftyWarningSta(df_fltinfo,start_time,end_time)
|
|
SatftyCount=DataSta.SftyWrngClsfy(df_fltinfo)
|
|
SatftyCount=DataSta.SftyWrngClsfy(df_fltinfo)
|
|
MaxAccumAh,TotalAccumAh,MaxCycle,MaxRunningHour,TotalRunHour=DataSta.AccumInfo(df_last_accum,df_FirstDataTime,end_time)
|
|
MaxAccumAh,TotalAccumAh,MaxCycle,MaxRunningHour,TotalRunHour=DataSta.AccumInfo(df_last_accum,df_FirstDataTime,end_time)
|
|
- all_location_info=DataSta.FltBatPosition(df_last_pos,df_Diag_Ram)
|
|
|
|
|
|
+ all_location_info=DataSta.FltBatPosition(df_last_pos,df_fltinfo)
|
|
|
|
|
|
all_statistic_info=DataFrame(columns=['factory','total_alarm','alarm_total_today','alarm_not_close_today','alarm_close_today','alarm_uregent_total_today','alarm_uregent_close_today','alarm_uregent_not_close_today','run_time_total','dischrg_total','odo_total','max_dischrg_one','max_runtime_one','max_cycle_one','max_odo_one','alarm_close_total','alarm_total','cell_type','cell_type_count','cell_safety_risk_count','data_safety_risk_count','status_safety_risk_count','hv_safety_risk_count','system_safety_risk_count','sample_safety_risk_count','controller_safety_risk_count','design_safety_risk_count'])
|
|
all_statistic_info=DataFrame(columns=['factory','total_alarm','alarm_total_today','alarm_not_close_today','alarm_close_today','alarm_uregent_total_today','alarm_uregent_close_today','alarm_uregent_not_close_today','run_time_total','dischrg_total','odo_total','max_dischrg_one','max_runtime_one','max_cycle_one','max_odo_one','alarm_close_total','alarm_total','cell_type','cell_type_count','cell_safety_risk_count','data_safety_risk_count','status_safety_risk_count','hv_safety_risk_count','system_safety_risk_count','sample_safety_risk_count','controller_safety_risk_count','design_safety_risk_count'])
|
|
all_statistic_info.loc[0,'factory']='骑享'
|
|
all_statistic_info.loc[0,'factory']='骑享'
|
|
@@ -362,8 +387,8 @@ if __name__ == "__main__":
|
|
host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
|
|
host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
|
|
port=3306
|
|
port=3306
|
|
db='qixiang_oss'
|
|
db='qixiang_oss'
|
|
- user='qixiang_oss'
|
|
|
|
- password='Qixiang2021'
|
|
|
|
|
|
+ user='qx_algo_rw'
|
|
|
|
+ password='qx@123456'
|
|
conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
|
|
conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
|
|
cursor = conn.cursor()
|
|
cursor = conn.cursor()
|
|
cursor.execute("select sn, imei, add_time from app_device")
|
|
cursor.execute("select sn, imei, add_time from app_device")
|
|
@@ -407,8 +432,8 @@ if __name__ == "__main__":
|
|
host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
|
|
port=3306
|
|
port=3306
|
|
db='safety_platform'
|
|
db='safety_platform'
|
|
- user='qx_read'
|
|
|
|
- password=parse.quote_plus('Qx@123456')
|
|
|
|
|
|
+ user='qx_algo_rw'
|
|
|
|
+ password=parse.quote_plus('qx@123456')
|
|
tablename='all_fault_info'
|
|
tablename='all_fault_info'
|
|
db_engine = create_engine(
|
|
db_engine = create_engine(
|
|
"mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
|
|
"mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
|
|
@@ -429,8 +454,8 @@ if __name__ == "__main__":
|
|
|
|
|
|
task_on=0
|
|
task_on=0
|
|
diag_cal()
|
|
diag_cal()
|
|
- DaTa_Sta_Minutes_Task()
|
|
|
|
- DaTa_Sta_Week_Task()
|
|
|
|
|
|
+ # DaTa_Sta_Minutes_Task()
|
|
|
|
+ # DaTa_Sta_Week_Task()
|
|
|
|
|
|
#定时任务.......................................................................................................................................................................
|
|
#定时任务.......................................................................................................................................................................
|
|
scheduler = BlockingScheduler()
|
|
scheduler = BlockingScheduler()
|