123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import CBMSBatDiag
- from SC_SamplingSafty import SamplingSafty
- import datetime
- import pandas as pd
- from LIB.BACKEND import DBManager, Log
- from sqlalchemy import create_engine
- import time, datetime
- from apscheduler.schedulers.blocking import BlockingScheduler
- from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload as DBDownload
- from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
- from pandas.core.frame import DataFrame
- from LIB.MIDDLE.SaftyCenter.Common import QX_BatteryParam
- from LIB.MIDDLE.SaftyCenter.Common import DBDownload as DBDw
- from DiagDataMerge import DiagDataMerge
- import pymysql
- #...................................电池包电芯安全诊断函数......................................................................................................................
- def diag_cal():
- task_on=1
- global SNnums
- #..................................设置时间..........................................................
- start=time.time()
- end_time=datetime.datetime.now()
- start_time=end_time-datetime.timedelta(seconds=600)#10分钟跑一次,一次取10分钟数据
- start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
- end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
- #数据库配置
- host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
- port=3306
- user='qx_read'
- password='Qx@123456'
- #读取故障结果库中code==110且end_time='0000-00-00 00:00:00'...............................
- db='safety_platform'
- mysql = pymysql.connect (host=host, user=user, password=password, port=port, database=db)
- cursor = mysql.cursor()
- param='start_time,end_time,product_id,code,level,info,advice,Batpos'
- tablename='all_fault_info'
- sql = "select %s from %s where end_time='0000-00-00 00:00:00'" %(param,tablename)
- cursor.execute(sql)
- res = cursor.fetchall()
- df_Diag_Ram= pd.DataFrame(res,columns=param.split(','))
- cursor.close()
- mysql.close()
- for sn in SNnums:#SN遍历
- print(sn)
- if 'PK500' in sn:
- celltype=1 #6040三元电芯
- elif 'PK502' in sn:
- celltype=2 #4840三元电芯
- elif 'K504B' in sn:
- celltype=99 #60ah林磷酸铁锂电芯
- elif 'MGMLXN750' in sn:
- celltype=3 #力信50ah三元电芯
- elif 'MGMCLN750' or 'UD' in sn:
- celltype=4 #CATL 50ah三元电芯
- else:
- print('SN:{},未找到对应电池类型!!!'.format(sn))
- continue
- # sys.exit()
- param=QX_BatteryParam.BatteryInfo(celltype)
- #读取原始数据库数据........................................................................................................................................................
- dbManager = DBManager.DBManager()
- df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
- df_bms = df_data['bms']
- #读取结果数据库数据........................................................................................................................................................
- db='qx_cas'
- mode=1
- tablename1='cellstateestimation_soh'
- tablename2='cellstateestimation_uniform_socvoltdiff'
- DBRead=DBDownload.DBDownload(host, port, db, user, password,mode)
- with DBRead as DBRead:
- df_soh=DBRead.getdata('time_st,sn,soh,cellsoh', tablename=tablename1, sn=sn, timename='time_sp', st=start_time, sp=end_time)
- df_uniform=DBRead.getdata('time,sn,cellsoc_diff,cellmin_num,cellmax_num', tablename=tablename2, sn=sn, timename='time', st=start_time, sp=end_time)
- #电池诊断.....................................................................................................................................................................
- 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_else = pd.concat([df_Diag_Ram,df_Diag_Ram_sn,df_Diag_Ram_sn]).drop_duplicates(subset=['product_id'],keep=False)#sn之外的故障
- df_Diag_Ram_sn_else=df_Diag_Ram.drop(df_Diag_Ram[df_Diag_Ram.product_id==sn].index)#sn之外的故障
- CellFltInfo = df_Diag_Ram_sn.drop('Batpos',axis=1)
- #获取当前故障电池的历史故障信息↑↑↑↑↑↑↑↑↑↑↑.......................................................................................................................................
- 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=batDiag.diag()
- # df_Diag_Batdiag_update=BatDiag.diag()
- if not df_Diag_Batdiag_update.empty:
- with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\电压排名.txt','a') as file:
- file.write(str(df_Diag_Batdiag_update)+'\n')
- else:
- pass
- #...............................................主函数.......................................................................................................................
- if __name__ == "__main__":
-
- excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\sn-20210903.xlsx'
- SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
- SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
- SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
- SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
- SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
- SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
- SNnums_6060=SNdata_6060['SN号'].tolist()
- SNnums_6040=SNdata_6040['SN号'].tolist()
- SNnums_4840=SNdata_4840['SN号'].tolist()
- SNnums_L7255=SNdata_L7255['SN号'].tolist()
- SNnums_C7255=SNdata_C7255['SN号'].tolist()
- SNnums_U7255=SNdata_U7255['SN号'].tolist()
- SNnums=SNnums_L7255 + SNnums_C7255 + SNnums_U7255 + SNnums_6040 + SNnums_4840 + SNnums_6060
- SNnums=SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255+ SNnums_6060
- # SNnums=['MGMCLN750N215I005','PK504B10100004341','PK504B00100004172','MGMLXN750N2189014']
- SNnums = ['MGMLXN750N218N004'] #SNnums_6040
-
- mylog=log.Mylog('log_diag.txt','error')
- mylog.logcfg()
- diag_cal()
- #定时任务.......................................................................................................................................................................
- scheduler = BlockingScheduler()
- scheduler.add_job(diag_cal, 'interval', seconds=5, id='diag_job')
- try:
- scheduler.start()
- except Exception as e:
- scheduler.shutdown()
- print(repr(e))
- mylog.logopt(e)
|