Browse Source

Merge remote-tracking branch 'origin/dev' into pro

lmstack 3 years ago
parent
commit
8eee3b8928

+ 437 - 0
LIB/MIDDLE/SaftyCenter/CellValueDiag/V1_0_0/SC_SamplingSafty.py

@@ -0,0 +1,437 @@
+import sys
+import numpy as np
+import pandas as pd
+import string
+import os
+from pandas import Series
+from matplotlib import pyplot as plt
+from pandas.core.frame import DataFrame
+from pandas.core.indexes.base import Index
+from LIB.BACKEND import DBManager
+import datetime
+import time
+import string
+
+
+class SamplingSafty:
+    def __init__(self):
+        pass
+    def main(sn,param,bms_info,df_Diag_Ram_in):
+        df_Diag_Ram_Update_inside=DataFrame(columns=['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice'])
+        df_Diag_Ram_Update_inside=df_Diag_Ram_Update_inside.append(df_Diag_Ram_in)
+        global QuitErrCount 
+        FltInfo=DataFrame(columns=['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice'])
+        VolStarkCount=[0 for i in range(param.CellVoltNums)]
+        VolCount=[0 for i in range(param.CellVoltNums)]
+        QuitErrCount=[0 for i in range(param.FaultCount)]
+
+        #--------------该电池的所有当前故障-------------
+
+
+
+        for i in range(0,len(bms_info)):
+            if i==0:
+                bms_infoP=bms_info.loc[i]
+            elif len(bms_info)>=1:
+                    bms_infoP=bms_info.loc[i-1]
+            df_Diag_Ram,VolStarkCount,VolCount=SamplingSafty.VoltSamplingDiag(sn,bms_info.loc[i],bms_infoP,param,VolStarkCount,VolCount,df_Diag_Ram_Update_inside)   
+            df_Diag_Ram=SamplingSafty.TempSamplingDiag(sn,bms_info.loc[i],bms_infoP,param,df_Diag_Ram)
+                # FltInfo=SamplingSafty.CrntSamplingDiag(sn,bms_info.loc[i],FltInfo,param)
+        return df_Diag_Ram
+
+
+
+    def VoltSamplingDiag(sn,bms_infoN,bms_infoP,param,VolStarkCount,VolCount,df_Diag_Ram):
+        InVMaxBatNo=[]
+        InVMinBatNo=[]
+        StackVolNo=[]
+        OutlierVolNo=[]
+        maxVolt=0
+        minVolt=5
+        ErrorFlg=0
+        TotalVol=0
+        #——————————————————————取最高最低电压————————————————————————————————
+        for t in range(0,param.CellVoltNums):
+            BatNo=['单体电压'+str(t+1)]
+            maxVol=max(maxVolt,float(bms_infoN[BatNo])/1000)
+            if maxVol>maxVolt:
+                MaxBatNo=t+1
+                maxVolt=maxVol
+            if float(bms_infoN[BatNo])/1000>param.CellOVlmt:
+                InVMaxBatNo.append(t+1)  
+            else:
+                pass
+            minVol=min(minVolt,float(bms_infoN[BatNo])/1000)
+            if minVol<minVolt:
+                MinBatNo=t+1
+                minVolt=minVol
+            if float(bms_infoN[BatNo])/1000<param.CellUVlmt:
+                InVMinBatNo.append(t+1)
+            else:
+                pass
+            TotalVol=TotalVol+float(bms_infoN[BatNo]/1000)
+        AvgVol=(TotalVol-maxVol-minVol)/float(param.CellVoltNums-2)
+
+
+        #—————————————————————————————电压无效和断线判断———————————————————————
+        if maxVol>param.CellOVlmt:
+            if minVol<param.CellUVlmt:
+                QuitErrCount[10]=0
+                if not 10 in df_Diag_Ram['code'].values.tolist():#如果故障发生当前故障中没有该故障,则压入该故障
+                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,10,3,'电池电压采样断线,最高电压为{:.2f}V,电池编号为{},最低电压为{:.2f}V,电池编号为{}'.format(maxVol,MaxBatNo,minVol,MinBatNo),'返厂维修']
+                    ErrorFlg=1            
+                else:#如果故障发生当前故障中有该故障,则不进行操作
+                    pass 
+            else:#如果没有故障,并且当前故障表中有该故障,则判断故障是否结束
+                QuitErrCount[50]=0
+                if 10 in df_Diag_Ram['code'].values.tolist():
+                    QuitErrCount[10]=QuitErrCount[10]+1
+                    if QuitErrCount[10]>6:
+                        end_time=datetime.datetime.now()
+                        end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                        df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==10].index,['end_time']]=end_time
+                    else:
+                        pass
+                else:
+                    pass
+                if not 50 in df_Diag_Ram['code'].values.tolist():
+                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,50,3,str(InVMaxBatNo)+'号电压大于{:.2f}V,采样无效'.format(param.CellOVlmt),'返厂维修']
+                    
+                    ErrorFlg=1
+                else:
+                    pass
+        elif minVol<param.CellUVlmt:
+            QuitErrCount[50]=0
+            if not 50 in df_Diag_Ram['code'].values.tolist():
+                df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,50,3,str(InVMinBatNo)+'号电压小于{:.2f}V,采样无效'.format(param.CellUVlmt),'返厂维修']
+                
+                ErrorFlg=1
+            else:
+                pass
+        else:
+            if 50 in df_Diag_Ram['code'].values.tolist():
+                QuitErrCount[50]=QuitErrCount[50]+1
+                if QuitErrCount[50]>6:
+                    end_time=datetime.datetime.now()
+                    end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                    df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==50].index,['end_time']]=end_time
+                    
+                else:
+                    pass
+            else:
+                pass
+       #——————————————————————————————————电压卡滞判断—————————————————————————
+        if ErrorFlg==0:
+            for t in range(0,param.CellVoltNums):
+                BatNo=['单体电压'+str(t+1)]
+                AvgVolGap=abs((float(bms_infoN[BatNo]/1000))-AvgVol)
+                if AvgVolGap>param.AvgVolGap and float(bms_infoN[BatNo]/1000)>param.BLVol and float(bms_infoN[BatNo]/1000)<param.CellFullChrgVolt and not 51 in df_Diag_Ram['code']:
+                    if abs(bms_infoN['总电流[A]'])<2:
+                        VolCount[t]=VolCount[t]+1
+                    else:
+                        VolCount[t]=0
+                    if VolCount[t]>10:
+                        OutlierVolNo.append(t+1)
+                    else:
+                        pass
+                if abs(float(bms_infoN[BatNo])-float(bms_infoP[BatNo]))<=0.0001 and not 52 in df_Diag_Ram['code']:
+                    if abs(float(bms_infoN['总电流[A]']))>=10 and not 'PK504' in sn:
+                        VolStarkCount[t]=VolStarkCount[t]+1
+                    elif abs(float(bms_infoN['总电流[A]']))>=15 and 'PK504' in sn:
+                        VolStarkCount[t]=VolStarkCount[t]+1
+                else:
+                    VolStarkCount[t]=0
+                if VolStarkCount[t]>10:
+                    StackVolNo.append(t+1)
+                else:
+                    pass
+            if len(OutlierVolNo)>0:
+                QuitErrCount[51]=0
+                if not 51 in df_Diag_Ram['code'].values.tolist():#如果故障发生当前故障中没有该故障,则压入该故障
+                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,51,2,str(OutlierVolNo)+'号电池电压离群','技术介入诊断']
+                    
+                    ErrorFlg=1            
+                else:#如果故障发生当前故障中有该故障,则不进行操作
+                    pass
+            else:
+                if 51 in df_Diag_Ram['code'].values.tolist():
+                    QuitErrCount[51]=QuitErrCount[51]+1
+                    if QuitErrCount[51]>6:
+                        end_time=datetime.datetime.now()
+                        end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                        df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==51].index,['end_time']]=end_time
+                        
+                    else:
+                        pass
+                else:
+                    pass
+            if len(StackVolNo)>0:
+                QuitErrCount[52]=0
+                if not 52 in df_Diag_Ram['code'].values.tolist():#如果故障发生当前故障中没有该故障,则压入该故障
+                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,52,2,str(StackVolNo)+'号电池电压卡滞','技术介入诊断']
+                    
+                    ErrorFlg=1            
+                else:#如果故障发生当前故障中有该故障,则不进行操作
+                    pass
+            else:
+                if 51 in df_Diag_Ram['code'].values.tolist():
+                    QuitErrCount[52]=QuitErrCount[52]+1
+                    if QuitErrCount[52]>6:
+                        end_time=datetime.datetime.now()
+                        end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                        df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==52].index,['end_time']]=end_time
+                        
+                    else:
+                        pass
+                else:
+                    pass
+        return df_Diag_Ram,VolStarkCount,VolCount
+    def TempSamplingDiag(sn,bms_infoN,bms_infoP,param,df_Diag_Ram):
+        #——————————————————————————————————CellTemp————————————————————————————————————
+        InVMaxBatNo=[]
+        InVMinBatNo=[]
+        OutlierTempNo=[]
+        maxCellTempt=-40
+        minCellTempt=55
+        ErrorFlg=0
+        TotalCellTemp=0
+        for t in range(0,param.CellTempNums):
+            BatNo=['单体温度'+str(t+1)]
+            maxCellTemp=max(maxCellTempt,float(bms_infoN[BatNo]))
+            if maxCellTemp>maxCellTempt:
+                MaxBatNo=t+1
+                maxCellTempt=maxCellTemp
+            if float(bms_infoN[BatNo])>param.PackOTlmt:
+                InVMaxBatNo.append(t+1)                   
+            else:
+                pass
+            minCellTemp=min(minCellTempt,float(bms_infoN[BatNo]))
+            if minCellTemp<minCellTempt:
+                MinBatNo=t+1
+                minCellTempt=minCellTemp
+            if float(bms_infoN[BatNo])<param.PackUTlmt:
+                InVMinBatNo.append(t+1)                   
+            else:
+                pass
+            TotalCellTemp=TotalCellTemp+float(bms_infoN[BatNo])
+        if param.CellTempNums>2:
+            AvgCellTemp=(TotalCellTemp-maxCellTemp-minCellTemp)/float(param.CellTempNums-2)
+        else:
+            AvgCellTemp=TotalCellTemp/float(param.CellTempNums)
+#——————————————————————————————————温度无效,离群和断线判断——————————————————————————————————
+        if maxCellTemp>param.PackOTlmt:
+            if minCellTemp<param.PackUTlmt:
+                QuitErrCount[53]=0
+                if not 53 in df_Diag_Ram['code'].values.tolist():#如果故障发生当前故障中没有该故障,则压入该故障
+                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,53,3,'电池温度采样断线,最高温度为{}℃,电池编号为{},最低温度为{}℃,电池编号为{}'.format(maxCellTemp,MaxBatNo,minCellTemp,MinBatNo),'返厂维修']
+                    ErrorFlg=1            
+                else:#如果故障发生当前故障中有该故障,则不进行操作
+                    pass 
+            else:#如果没有故障,并且当前故障表中有该故障,则判断故障是否结束
+                QuitErrCount[2]=0
+                if 53 in df_Diag_Ram['code'].values.tolist():
+                    QuitErrCount[53]=QuitErrCount[53]+1
+                    if QuitErrCount[53]>6:
+                        end_time=datetime.datetime.now()
+                        end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                        df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==53].index,['end_time']]=end_time
+                        
+                    else:
+                        pass
+                else:
+                    pass
+                if not 2 in df_Diag_Ram['code'].values.tolist():
+                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,2,3,str(InVMaxBatNo)+'号温度大于{}℃,采样无效'.format(param.PackOTlmt),'返厂维修']
+                    
+                    ErrorFlg=1
+                else:
+                    pass
+        elif minCellTemp<param.PackUTlmt:
+            QuitErrCount[2]=0
+            if not 2 in df_Diag_Ram['code'].values.tolist():
+                df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,2,3,str(InVMinBatNo)+'号温度小于{}℃,采样无效'.format(param.PackUTlmt),'返厂维修']
+                
+                ErrorFlg=1
+            else:
+                pass
+        else:
+            if 2 in df_Diag_Ram['code'].values.tolist():
+                QuitErrCount[2]=QuitErrCount[2]+1
+                if QuitErrCount[2]>6:
+                    end_time=datetime.datetime.now()
+                    end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                    df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==2].index,['end_time']]=end_time
+                    
+                else:
+                    pass
+            else:
+                pass
+        if ErrorFlg==0:
+            if param.CellTempNums>2:            
+                for t in range(0,param.CellTempNums):
+                    BatNo=['单体温度'+str(t+1)]
+                    AvgCellTempGap=abs((float(bms_infoN[BatNo]))-AvgCellTemp)
+                    if AvgCellTempGap>param.AvgCellTempGap and float(bms_infoN[BatNo])>param.PackUTlmt and float(bms_infoN[BatNo])<param.PackOTlmt and not 8 in df_Diag_Ram['code']:
+                        OutlierTempNo.append(t+1)
+            else:
+                AvgCellTempGap=maxCellTemp-minCellTemp
+                if AvgCellTempGap>param.AvgCellTempGap and minCellTemp>param.PackUTlmt and maxCellTemp<param.PackOTlmt and not 8 in df_Diag_Ram['code']:
+                    OutlierTempNo=[1,2]
+            if len(OutlierTempNo)>0:
+                QuitErrCount[8]=0
+                if not 8 in df_Diag_Ram['code'].values.tolist():#如果故障发生当前故障中没有该故障,则压入该故障
+                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,8,2,str(OutlierTempNo)+'号电池异常温度离群','技术介入诊断']
+                    
+                    ErrorFlg=1            
+                else:#如果故障发生当前故障中有该故障,则不进行操作
+                    pass
+            else:
+                if 8 in df_Diag_Ram['code'].values.tolist():
+                    QuitErrCount[8]=QuitErrCount[8]+1
+                    if QuitErrCount[8]>6:
+                        end_time=datetime.datetime.now()
+                        end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                        df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==8].index,['end_time']]=end_time
+                        
+                        #df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['sn']==sn and df_Diag_Ram['code']==8].index,['end_time']]=end_time
+                    else:
+                        pass
+                else:
+                    pass
+        #——————————————————————————————————OtherTemp————————————————————————————————————
+        InVMaxOtherTempBatNo=[]
+        InVMinOtherTempBatNo=[]
+        OutlierOtherTempNo=[]
+        maxOtherTempt=-40
+        minOtherTempt=91
+        ErrorFlg=0
+        TotalOtherTemp=0
+        if param.OtherTempNums>0:
+            for t in range(0,param.OtherTempNums):
+                BatNo=['其他温度'+str(t+1)]
+                maxOtherTemp=max(maxOtherTempt,float(bms_infoN[BatNo]))
+                if maxOtherTemp>maxOtherTempt:
+                    MaxBatNo=t+1
+                    maxOtherTempt=maxOtherTemp
+                if float(bms_infoN[BatNo])>param.OtherOTlmt:
+                    InVMaxOtherTempBatNo.append(t+1)                   
+                else:
+                    pass
+                minOtherTemp=min(minOtherTempt,float(bms_infoN[BatNo]))
+                if minOtherTemp<minOtherTempt:
+                    MinBatNo=t+1
+                    minOtherTempt=minOtherTemp
+                if float(bms_infoN[BatNo])<param.OtherUTlmt:
+                    InVMinOtherTempBatNo.append(t+1)                   
+                else:
+                    pass
+                TotalOtherTemp=TotalOtherTemp+float(bms_infoN[BatNo])
+            if param.OtherTempNums>2:
+                AvgOtherTemp=(TotalOtherTemp-maxOtherTemp-minOtherTemp)/float(param.OtherTempNums-2)
+            else:
+                AvgOtherTemp=TotalOtherTemp/float(param.OtherTempNums)
+    #——————————————————————————————————其他温度无效,离群和断线判断——————————————————————————————————
+            if maxOtherTemp>param.OtherOTlmt:
+                if minOtherTemp<param.OtherUTlmt:
+                    QuitErrCount[54]=0
+                    if not 54 in df_Diag_Ram['code'].values.tolist():#如果故障发生当前故障中没有该故障,则压入该故障
+                        df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,54,3,'其他温度采样断线,最高温度为{}℃,传感器编号为{},最低温度为{}℃,传感器编号为{}'.format(maxOtherTemp,MaxBatNo,minOtherTemp,MinBatNo),'返厂维修']
+                        
+                        ErrorFlg=1            
+                    else:#如果故障发生当前故障中有该故障,则不进行操作
+                        pass 
+                else:#如果没有故障,并且当前故障表中有该故障,则判断故障是否结束
+                    QuitErrCount[55]=0
+                    if 54 in df_Diag_Ram['code'].values.tolist():
+                        QuitErrCount[54]=QuitErrCount[54]+1
+                        if QuitErrCount[54]>6:
+                            end_time=datetime.datetime.now()
+                            end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                            df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==54].index,['end_time']]=end_time
+                           
+                        else:
+                            pass
+                    else:
+                        pass
+                    if not 55 in df_Diag_Ram['code'].values.tolist():
+                        df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,55,3,str(InVMaxBatNo)+'号传感器温度大于{}℃,采样无效'.format(param.OtherOTlmt),'联系用户核实电池情况,并返厂维修']
+                        
+                        ErrorFlg=1
+                    else:
+                        pass
+            elif minOtherTemp<param.OtherUTlmt:
+                QuitErrCount[55]=0
+                if not 55 in df_Diag_Ram['code'].values.tolist():
+                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,55,3,str(InVMinBatNo)+'号传感器温度小于{}℃,采样无效'.format(param.OtherUTlmt),'返厂维修']
+                    
+                    ErrorFlg=1
+                else:
+                    pass
+            else:
+                if 55 in df_Diag_Ram['code'].values.tolist():
+                    QuitErrCount[55]=QuitErrCount[55]+1
+                    if QuitErrCount[55]>6:
+                        end_time=datetime.datetime.now()
+                        end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                        df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==55].index,['end_time']]=end_time
+                        
+                    else:
+                        pass
+                else:
+                    pass
+            if ErrorFlg==0 and param.OtherTempNums>0:
+                if param.OtherTempNums>2:            
+                    for t in range(0,param.OtherTempNums):
+                        BatNo=['其他温度'+str(t+1)]
+                        AvgOtherTempGap=abs((float(bms_infoN[BatNo]))-AvgOtherTemp)
+                        if AvgOtherTempGap>param.AvgOtherTempGap and float(bms_infoN[BatNo])>param.OtherUTlmt and float(bms_infoN[BatNo])<param.OtherOTlmt and not 8 in df_Diag_Ram['code']:
+                            OutlierTempNo.append(t+1)
+                else:
+                    AvgOtherTempGap=maxOtherTemp-minOtherTemp
+                    if AvgOtherTempGap>param.AvgOtherTempGap and minOtherTemp>param.OtherUTlmt and maxOtherTemp<param.OtherOTlmt and not 8 in df_Diag_Ram['code']:
+                        OutlierTempNo=[1,2]
+                if len(OutlierTempNo)>0:
+                    QuitErrCount[56]=0
+                    if not 56 in df_Diag_Ram['code'].values.tolist():#如果故障发生当前故障中没有该故障,则压入该故障
+                        df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,56,2,str(OutlierTempNo)+'号传感器温度异常离群','技术介入诊断']
+                        
+                        ErrorFlg=1            
+                    else:#如果故障发生当前故障中有该故障,则不进行操作
+                        pass
+                else:
+                    if 56 in df_Diag_Ram['code'].values.tolist():
+                            QuitErrCount[56]=QuitErrCount[56]+1
+                            if QuitErrCount[56]>6:
+                                end_time=datetime.datetime.now()
+                                end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                                df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==56].index,['end_time']]=end_time
+                                
+            if (maxOtherTemp-maxCellTemp)>param.AvgOtherTempGap and  maxOtherTemp<param.OtherOTlmt and maxCellTemp<param.PackOTlmt:
+                QuitErrCount[56]=0
+                if not 56 in df_Diag_Ram['code'].values.tolist():
+                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,56,2,str(OutlierTempNo)+'号传感器温度异常离群','技术立即介入诊断']
+                    
+                    ErrorFlg=1
+            else:
+                if 56 in df_Diag_Ram['code'].values.tolist():
+                        QuitErrCount[56]=QuitErrCount[56]+1
+                        if QuitErrCount[56]>6:
+                            end_time=datetime.datetime.now()
+                            end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                            df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==56].index,['end_time']]=end_time
+                            
+            if (maxCellTemp-maxOtherTemp)>param.AvgOtherTempGap and  maxOtherTemp<param.OtherOTlmt and maxCellTemp<param.PackOTlmt and not 8 in df_Diag_Ram['code']:
+                QuitErrCount[8]=0
+                if not 8 in df_Diag_Ram['code'].values.tolist():
+                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],0,sn,8,2,str(OutlierTempNo)+'号电芯温度异常离群','技术立即介入诊断']
+                    
+                    ErrorFlg=1
+            else:
+                if 8 in df_Diag_Ram['code'].values.tolist():
+                        QuitErrCount[8]=QuitErrCount[8]+1
+                        if QuitErrCount[8]>6:
+                            end_time=datetime.datetime.now()
+                            end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+                            df_Diag_Ram.loc[df_Diag_Ram[df_Diag_Ram['code']==8].index,['end_time']]=end_time                   
+        return df_Diag_Ram
+   

+ 4 - 0
LIB/MIDDLE/SaftyCenter/CellValueDiag/V1_0_0/SC故障表单.csv

@@ -0,0 +1,4 @@
+start_time,end_time,product_id,code,level,info,advice
+2021-10-17 22:56:07,0,MGMLXN750N2189014,50,3,"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]号电压小于2.00V,采样无效",返厂维修
+2021-10-17 22:56:07,0,MGMLXN750N2189014,2,3,"[1, 2, 3, 4]号温度小于-20℃,采样无效",返厂维修
+2021-10-17 22:56:07,0,MGMLXN750N2189014,55,3,"[1, 2, 3, 4]号传感器温度小于-20℃,采样无效",返厂维修

+ 194 - 0
LIB/MIDDLE/SaftyCenter/CellValueDiag/main.py

@@ -0,0 +1,194 @@
+import CBMSBatDiag
+import QX_BatteryParam
+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 import DBDownload
+from LIB.MIDDLE.CellStateEstimation.Common import log
+from pandas.core.frame import DataFrame
+import datacompy
+
+
+
+#...................................电池包电芯安全诊断函数......................................................................................................................
+def diag_cal():
+    global SNnums
+    global df_Diag_Ram
+
+    start=time.time()
+    end_time=datetime.datetime.now()
+    start_time=end_time-datetime.timedelta(seconds=120)
+    start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
+    end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+
+    for sn in SNnums:
+        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)     
+        # sn='PK50201A000002039'
+        # celltype=2
+        # start_time='2021-05-02 09:12:26'
+        # end_time='2021-06-03 19:12:26'
+        # # df_bms= pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\98Download\\'+'BMS_'+sn+'.csv',encoding='GB18030')
+
+        #读取原始数据库数据........................................................................................................................................................
+        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']
+        # df_bms.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\99Result\\''BMS_'+sn+'.csv',encoding='GB18030')
+
+        #读取结果数据库数据........................................................................................................................................................
+        host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+        port=3306
+        db='qx_cas'
+        user='qx_read'
+        password='Qx@123456'
+        mode=1
+        tablename1='cellstateestimation_soh'
+        tablename2='cellstateestimation_uniform_socvoltdiff'
+        tablename3='cellstateestimation_soc'
+        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)
+            # df_soc=DBRead.getdata('time','sn','packsoc', tablename=tablename3, sn=sn)
+
+        #电池诊断................................................................................................................................................................
+        #BatDiag=CBMSBatDiag.BatDiag(sn,celltype,df_bms, df_soh, df_uniform)
+        #df_res=BatDiag.diag()
+        #df_Diag_Ram_old=df_Diag_Ram
+        df_Diag_Ram_Update=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'])
+        if not df_bms.empty:
+            CellFltInfo=df_Diag_Ram[df_Diag_Ram['product_id']==sn]
+            df_Diag_Ram_Update=SamplingSafty.main(sn,param,df_bms,CellFltInfo)       
+        if not df_Diag_Ram_Update.empty:
+            sn_index=df_Diag_Ram[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_Ram_Update)
+            df_Diag_Ram.reset_index(inplace=True,drop=True)
+
+        Diag_Ram_Dif=datacompy.Compare(df_Diag_Ram_Update,CellFltInfo,join_columns=['product_id','end_time','code'])
+        Diag_Ram_Dif=Diag_Ram_Dif.df1_unq_rows    
+        if len(Diag_Ram_Dif)>0:
+            Diag_Ram_Dif_New=Diag_Ram_Dif[Diag_Ram_Dif['end_time']==0]
+            Diag_Ram_Dif_Finish=df_Diag_Ram[df_Diag_Ram['end_time']!=0]
+            if len(Diag_Ram_Dif_New)>0:
+                result=pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\sxq\SaftyCenter_CODE_V1_1\result.csv',encoding='gbk')
+                result=result.append(Diag_Ram_Dif_New)
+                result.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\sxq\SaftyCenter_CODE_V1_1\result.csv',index=False,encoding='GB18030')
+            if len(Diag_Ram_Dif_Finish)>0:
+                result=pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\sxq\SaftyCenter_CODE_V1_1\result.csv',encoding='gbk')
+                Diag_Ram_Dif_Finish=Diag_Ram_Dif_Finish.reset_index(drop=True)
+                for i in range(0,len(Diag_Ram_Dif_Finish)):
+                    result.loc[result[result[result['product_id']==Diag_Ram_Dif_Finish.loc[i,'product_id']]['code']==Diag_Ram_Dif_Finish.loc[i,'code']].index,'end_time']=Diag_Ram_Dif_Finish.loc[i,'end_time']
+                result.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\sxq\SaftyCenter_CODE_V1_1\result.csv',index=False,encoding='GB18030')
+        end=time.time()
+        print(end-start)
+        # print(df_soh)
+            
+#...................................电池包电芯安全诊断函数......................................................................................................................
+def shortdiag_cal():
+    global SNnums
+    global df_Diag_Ram
+    start=time.time()
+    end_time=datetime.datetime.now()
+    start_time=end_time-datetime.timedelta(days=30)
+    start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
+    end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
+
+    for sn in SNnums:
+        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()
+
+        #读取结果数据库数据........................................................................................................................................................
+        host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+        port=3306
+        db='qx_cas'
+        user='qx_read'
+        password='Qx@123456'
+        mode=2
+        tablename1='cellstateestimation_intershort'
+        DBRead=DBDownload.DBDownload(host, port, db, user, password, mode)  #mode==1取数据库最后一行数据
+        with DBRead as DBRead:
+            df_short=DBRead.getdata('time_sp','sn','short_current', tablename=tablename1, sn=sn, timename='time_sp', st=start_time, sp=end_time)  
+        
+        #电池诊断................................................................................................................................................................
+        ShortDiag=CBMSBatDiag.ShortDiag(sn,celltype, df_short)
+        df_res=ShortDiag.shortdiag()
+        # df_res.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\99Result\\'+'CBMS_diag_'+sn+'.csv',encoding='GB18030')
+        
+        print(df_res)
+
+        end=time.time()
+        print(end-start)
+        # print(df_soh)
+        
+
+#...............................................主函数.......................................................................................................................
+if __name__ == "__main__":
+
+    excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\sxq\SaftyCenter_CODE_V1_1\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_6040 + SNnums_4840 + SNnums_U7255+ SNnums_6060
+    #SNnums=['MGMCLN750N215I005','PK504B10100004341','PK504B00100004172','MGMLXN750N2189014']
+    #SNnums=['MGMLXN750N2189014']
+    
+    mylog=log.Mylog('log_diag.txt','error')
+    mylog.logcfg()
+    #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................
+    result=pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\sxq\SaftyCenter_CODE_V1_1\result.csv',encoding='gbk')
+    
+    df_Diag_Ram=result[result['end_time']==0]
+    print('----------------输入--------')
+    print(df_Diag_Ram)
+    #定时任务.......................................................................................................................................................................
+    scheduler = BlockingScheduler()
+    scheduler.add_job(diag_cal, 'interval', seconds=120, id='diag_job')
+    scheduler.add_job(shortdiag_cal, 'interval', days=7, id='shortdiag_job')
+
+    try:  
+        scheduler.start()
+    except Exception as e:
+        scheduler.shutdown()
+        print(repr(e))
+        mylog.logopt(e)