Browse Source

增加BMS故障报警的统计更新

Eric412V 3 years ago
parent
commit
475f464fe4

+ 59 - 4
LIB/MIDDLE/SaftyCenter/DataDiag_Static/SC_BMSUploadError.py

@@ -12,12 +12,67 @@ import datetime
 import time
 import string
 import re
+import math
 
-
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+from urllib import parse
+import pymysql
 
 class BMSReportError:
     def __init__(self):
-            pass
-    def main(sn,param,bms_info,df_Diag_Ram_in):
         pass
-    
+    def main(sn,bms_info,df_Diag_Ram_in,FactoryType,errorcode_map ):
+        df_Diag_Ram_BMS=df_Diag_Ram_in[df_Diag_Ram_in['code'].str.contains('B')].copy()
+        df_Diag_Ram_Cloud=df_Diag_Ram_in[df_Diag_Ram_in['code'].str.contains('C')].copy()
+        df_bms=bms_info[['时间戳','故障等级','故障代码']]
+        newCode=[]
+        for i in range (0,len(df_bms)):
+            #拆解故障码,PK专用
+            if FactoryType ==1:
+                code=df_bms.loc[i,'故障代码']
+                newCode=[]
+                if code>2:
+                    num=math.log(code)/math.log(2)
+                    power=int(num)
+                    nCode=int(math.pow(2,power))
+                    newCode.append(nCode)
+                    code=code-nCode
+                    while(code>0):
+                        num=float(math.log(code)/math.log(2))
+                        power=int(num)
+                        nCode=int(math.pow(2,power))
+                        newCode.append(nCode)
+                        code=code-nCode
+                else:
+                    newCode=newCode.append(nCode)
+            else:
+                newCode=df_bms.loc[i,'故障代码']
+                
+            # 数据库配置
+
+            if len(newCode):
+                for j in range(0,len(newCode)):
+                                
+                    
+                    code = newCode[j] # 终端故障码
+                    platform_code = errorcode_map[(errorcode_map['protocol']==FactoryType)&(errorcode_map['end_errorcode']==str(code))]['platform_errorcode']
+                    newCode[j]=platform_code.values[0]
+                    if pd.isnull(platform_code.values[0]):
+                        pass
+                    else:
+                        if not platform_code.values[0] in df_Diag_Ram_BMS['code'].values.tolist():
+                            df_Diag_Ram_BMS.loc[len(df_Diag_Ram_BMS)]=[df_bms.loc[i,'时间戳'],'0000-00-00 00:00:00',sn,platform_code.values[0],df_bms.loc[i,'故障等级'],'']
+                        else:
+                            pass
+        if len(df_Diag_Ram_BMS):
+            for k in range(0,len(df_Diag_Ram_BMS)):
+                if not df_Diag_Ram_BMS.loc[k,'code'] in newCode:
+                    end_time=datetime.datetime.now()
+                    end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                    df_Diag_Ram_BMS.loc[k,'end_time']=end_time
+                else:
+                    pass
+        df_Diag_Ram=df_Diag_Ram_BMS.append(df_Diag_Ram_Cloud)
+        df_Diag_Ram=df_Diag_Ram.reset_index(drop=True)
+        return df_Diag_Ram

+ 10 - 2
LIB/MIDDLE/SaftyCenter/DataDiag_Static/main.py

@@ -3,6 +3,7 @@ from SC_SamplingSafty import SamplingSafty
 from DataStatistics import DataSta
 from DiagDataMerge import DiagDataMerge
 from SC_CtrlSafty import CtrlSafty
+from SC_BMSUploadError import BMSReportError
 import datetime
 import pandas as pd
 from LIB.BACKEND import DBManager, Log
@@ -47,16 +48,22 @@ def diag_cal():
         print(sn)
         if 'PK500' in sn:
             celltype=1 #6040三元电芯
+            FactoryType=1
         elif 'PK502' in sn:
             celltype=2 #4840三元电芯
+            FactoryType=1
         elif 'K504B' in sn:
             celltype=99    #60ah林磷酸铁锂电芯
+            FactoryType=1
         elif 'MGMLXN750' in sn:
             celltype=3 #力信50ah三元电芯
+            FactoryType=3
         elif ('MGMCLN750' or 'UD') in sn: 
             celltype=4 #CATL 50ah三元电芯
+            FactoryType=2
         elif 'TJMCL'in sn:
             celltype=100 #CATL 50ah三元电芯
+            FactoryType=0
         else:
             print('SN:{},未找到对应电池类型!!!'.format(sn))
             continue
@@ -94,7 +101,7 @@ def diag_cal():
         DBRead=DBDw.DBDownload(host, port, db, user, password,mode)
         with DBRead as DBRead:
             df_OprtnSta=DBRead.getdata('qrcode','status', tablename=tablename1, sn=sn, timename='', st='', sp='',factory='')#取最后一条运营状态
-
+        errorcode_map=DataFrame()
 
 
 
@@ -109,7 +116,8 @@ def diag_cal():
         if not df_bms.empty:
             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)#鹏飞计算
+            batDiag2=CBMSBatDiag.BatDiag(sn,celltype,df_bms, df_soh, df_uniform, df_Diag_Batdiag_update_xq2)#鹏飞计算
+            batDiag=BMSReportError.main(sn,df_bms,batDiag2,FactoryType,errorcode_map)
             df_Diag_Batdiag_update=batDiag.diag()
             # df_Diag_Batdiag_update=BatDiag.diag() 
         else: