瀏覽代碼

Merge branch 'dev' of http://git.fast-fun.cn:92/lmstack/data_analyze_platform into dev

Eric412V 3 年之前
父節點
當前提交
3328c48811

+ 33 - 25
LIB/MIDDLE/CellStateEstimation/BatSafetyAlarm/main.py

@@ -1,4 +1,6 @@
 import CBMSSafetyAlarm
+import pymysql
+from urllib import parse
 import datetime
 import pandas as pd
 import multiprocessing
@@ -9,14 +11,33 @@ from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
 
 
 #...................................电池包电芯安全诊断函数......................................................................................................................
-def diag_cal(sn_list, df_diag_ram, df_bms_ram):
-    
+def diag_cal(sn_list, df_bms_ram):
+
     start=time.time()
     now_time=datetime.datetime.now()
     start_time=now_time-datetime.timedelta(seconds=70)
     start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
     end_time=now_time.strftime('%Y-%m-%d %H:%M:%S')
 
+    #数据库配置
+    host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+    port=3306
+    user='qx_algo_readonly'
+    password = parse.quote_plus('qx@123456')
+
+    #读取故障结果库中code==119且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'
+    tablename='all_fault_info'
+    sql =  "select %s from %s where code=119 and 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 sn_list:
         if 'PK500' in sn:
             celltype=1 #6040三元电芯
@@ -37,7 +58,7 @@ def diag_cal(sn_list, df_diag_ram, df_bms_ram):
         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']
-        # print(df_bms)
+        print(df_bms)
 
         #电池诊断................................................................................................................................................................
         if not df_bms.empty:
@@ -47,47 +68,36 @@ def diag_cal(sn_list, df_diag_ram, df_bms_ram):
                 SafetyAlarm=CBMSSafetyAlarm.SafetyAlarm(sn,celltype,df_bms, df_bms_ram_sn)
                 df_diag_res, df_bms_res=SafetyAlarm.diag() 
 
-                #更新bms的ram数据 和 diag的Ram数据
+                #更新bms的ram数据
                 sn_index=df_bms_ram.loc[df_bms_ram['sn']==sn].index
                 df_bms_ram=df_bms_ram.drop(index=sn_index)
                 df_bms_ram=df_bms_ram.append(df_bms_res)
 
-                sn_index=df_diag_ram.loc[df_diag_ram['product_id']==sn].index
-                df_diag_ram=df_diag_ram.drop(index=sn_index)
-                df_diag_ram=df_diag_ram.append(df_diag_res)
-                df_diag_ram.reset_index(inplace=True,drop=True)     #重置索引
-
                 #当前热失控故障写入数据库
                 if not df_diag_res.empty:
                     with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\06BatSafetyAlarm\热失控.txt','a') as file:
                         file.write(str(tuple(df_diag_res.iloc[-1]))+'\n')
                 
-            #当前热失控已超过三天变为历史故障并写入数据库,并删除原有数据库中的当前故障和ram中的当前故障
-            elif (now_time-df_bms_ram_sn.iloc[-1]['time']).total_seconds()>3*24*3600:
-                df_diag_ram=df_diag_ram.drop(df_diag_ram['sn']==sn)    #删除ram中的当前故障
-                df_bms_ram_sn.iloc[-1]['end_time']=now_time
+            #当前热失控已超过一天变为历史故障并更改数据库
+            elif (now_time-df_diag_ram_sn.iloc[-1]['start_time']).total_seconds()>24*3600:
+                df_diag_ram_sn.iloc[-1]['end_time']=now_time
+                df_diag_ram_sn['Batpos']=1
                 with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\06BatSafetyAlarm\热失控.txt','a') as file:
                         file.write(str(tuple(df_diag_res.iloc[-1]))+'\n')
 
-
-
         #故障处理........................................................................................................................................................
-
         end=time.time()
         print(end-start)
-        # print(df_soh)
-
 #...................................................主进程...........................................................................................................
 def mainprocess():
     global SNnums
-    global df_diag_ram
     global df_bms_ram
     process = 2
     pool = multiprocessing.Pool(processes = process)
 
     for i in range(process):
         sn_list = SNnums[i]
-        pool.apply_async(diag_cal, (sn_list,df_diag_ram,df_bms_ram))
+        pool.apply_async(diag_cal, (sn_list,df_bms_ram))
 
     pool.close()
     pool.join()
@@ -110,14 +120,12 @@ if __name__ == "__main__":
     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=['PK50201A000002201']
+    # SNnums=[[],['PK504B00100004161']]
     
     mylog=log.Mylog('log_diag.txt','error')
     mylog.logcfg()
-
-    #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取...................................
-    result=pd.read_excel(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\06BatSafetyAlarm\result.xlsx')
-    df_diag_ram=result[(result['end_time']=='0000-00-00 00:00:00') & (result['code']==119)]
+    
+    #参数初始化
     df_bms_ram=pd.DataFrame(columns=['time', 'sn', 'packvolt', 'cellvolt', 'celltemp'])
 
     #定时任务.......................................................................................................................................................................

+ 1 - 1
LIB/MIDDLE/CellStateEstimation/Common/V1_0_1/log.py

@@ -17,7 +17,7 @@ class Mylog:
                 Level=logging.WARNING
             else:
                 Level=logging.ERROR
-        logging.basicConfig(filename=r'D:\ZLWORK\code\data_analyze_platform\USER\liuzhongxiao\diagfault\\'+self.name, level=Level,format='%(asctime)s - %(levelname)s - %(message)s')
+        logging.basicConfig(filename=r'D:\Platform\platform_python\data_analyze_platform\USER\spf\101log\\'+self.name, level=Level,format='%(asctime)s - %(levelname)s - %(message)s')
 
 
     def logopt(self,*info):