Browse Source

软件debug,修复重复报故障问题,修复故障电池不显示问题

Eric412V 3 years ago
parent
commit
ff8f28e546

+ 8 - 8
LIB/MIDDLE/SaftyCenter/DataDiag_Static/CBMSBatDiag.py

@@ -137,12 +137,12 @@ class BatDiag:
                 delttime=(time2-time1).total_seconds()
                 if delttime>20:
                     temp2=np.array(self._celltemp_get(i))
-                    celltemp_rate=(max(temp2-temp1)*60)/delttime    #计算最大温升速率
+                    celltemp_rate=round((max(temp2-temp1)*60)/delttime,2)    #计算最大温升速率
                     temp1=temp2 #更新初始温度
                     time1=time2 #更新初始时间
-                    if celltemp_rate>self.param.CellTempRate:
-                        temprate_cnt=temprate_cnt+1
-                        if not 9 in list(self.df_diag_ram['code']):  #当前故障中没有该故障,则判断是否发生该故障
+                    if not 9 in list(self.df_diag_ram['code']):#当前故障中没有该故障,则判断是否发生该故障
+                        if celltemp_rate>self.param.CellTempRate:
+                            temprate_cnt=temprate_cnt+1
                             if temprate_cnt>2:  #温升故障进入
                                 time=self.bmstime[i]
                                 code=9
@@ -153,11 +153,11 @@ class BatDiag:
                             else:
                                 pass
                         else:   #ram当前故障中有该故障,则判断是否退出该故障
-                            if celltemp_rate<self.param.CellTempRate-1: #温升故障恢复
-                                time=self.bmstime[i]
-                                self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['code']==9].index, 'end_time'] = time
+                           pass
                     else:
-                        pass
+                        if celltemp_rate<self.param.CellTempRate-1: #温升故障恢复
+                            time=self.bmstime[i]
+                            self.df_diag_ram.loc[self.df_diag_ram[self.df_diag_ram['code']==9].index, 'end_time'] = time
                 else:
                     pass
             

+ 8 - 8
LIB/MIDDLE/SaftyCenter/DataDiag_Static/DataStatistics.py

@@ -14,8 +14,8 @@ class DataSta():
         SftyPlt_Data_Total=len(df_fltinfo)#总报警数
         CS_Warning_Total_Finish=df_fltinfo[df_fltinfo['batpos']==1]
         CS_Warning_Total_Finish_Count=len(CS_Warning_Total_Finish) #平台报警总运维数
-        SftyPlt_Data_day=len(df_fltinfo[df_fltinfo['start_time']>=start_time])#周总报警数
-        CS_Warning_day_Finish=CS_Warning_Total_Finish[CS_Warning_Total_Finish['start_time']>=start_time]#周运维数
+        SftyPlt_Data_day=len(df_fltinfo[df_fltinfo['start_time']>=start_time])#日、周总报警数
+        CS_Warning_day_Finish=CS_Warning_Total_Finish[CS_Warning_Total_Finish['start_time']>=start_time]#日/周运维数
         CS_Warning_day_Finish_Count=len(CS_Warning_day_Finish)
         SftyPlt_EmgcyData_day=df_fltinfo[df_fltinfo['start_time']>=start_time] #紧急报警数
         SftyPlt_EmgcyData_day=SftyPlt_EmgcyData_day[SftyPlt_EmgcyData_day['level']>3]
@@ -119,13 +119,13 @@ class DataSta():
         TotalRunHour=int(deltatime['runningdate'].sum())
         return MaxAccumAh,TotalAccumAh,MaxCycle,MaxRunningHour,TotalRunHour
 
-    def FltBatPosition(df_last_pos,df_Diag_Ram):
-        print(df_Diag_Ram)
+    def FltBatPosition(df_last_pos,df_fltinfo):
+        df_Diag_Ram=df_fltinfo[df_fltinfo['batpos']==0].drop_duplicates(subset=['product_id'],keep=False)
         all_location_info=DataFrame(columns=['factory','product_id','lat','lon'])
         df_last_pos.rename(columns={'devcode':'product_id'},inplace=True)
-        df_Diag_Ram_Pos=pd.concat([df_Diag_Ram,df_last_pos]).drop_duplicates(subset=['product_id'],keep=False)
-        df_Diag_Ram_Pos=pd.concat([df_Diag_Ram_Pos,df_Diag_Ram_Pos.drop_duplicates(subset=['product_id'],keep=False)]).drop_duplicates(subset=['product_id'],keep=False)
-        df_Diag_Ram_Pos=df_Diag_Ram.drop_duplicates()
+        df_Diag_Ram_Pos_a=pd.concat([df_Diag_Ram,df_last_pos]).drop_duplicates(subset=['product_id'],keep='first')
+        df_Diag_Ram_Pos_b=pd.concat([df_Diag_Ram,df_last_pos]).drop_duplicates(subset=['product_id'],keep=False)
+        df_Diag_Ram_Pos=df_Diag_Ram_Pos_a.append(df_Diag_Ram_Pos_b).drop_duplicates(subset=['product_id'],keep=False)
         df_Diag_Ram_Pos=df_Diag_Ram_Pos.reset_index(drop=True)
         for i in range(0,len(df_Diag_Ram_Pos)):
             df_last_pos_list=df_last_pos['product_id'].values.tolist()
@@ -134,5 +134,5 @@ class DataSta():
                 all_location_info.loc[i,'lat']=pos_la_temp.loc[0,'latitude']
                 all_location_info.loc[i,'lon']=pos_la_temp.loc[0,'longitude']
                 all_location_info.loc[i,'factory']='骑享'
-                all_location_info.loc[i,'product_id']=df_Diag_Ram.loc[i,'product_id']
+                all_location_info.loc[i,'product_id']=df_Diag_Ram_Pos.loc[i,'product_id']
         return all_location_info

+ 10 - 14
LIB/MIDDLE/SaftyCenter/DataDiag_Static/DiagDataMerge.py

@@ -3,31 +3,27 @@ import datacompy
 
 
 class DiagDataMerge():
-    def DetaMerge(df_Diag_Ram_sn,df_Diag_Batdiag_update_xq,df_Diag_Batdiag_update,df_OprtnSta,df_Diag_Ram_sn_else):
+    def DetaMerge(df_Diag_Ram_sn,df_Diag_Batdiag_update,df_OprtnSta,df_Diag_Ram_sn_else):
         df_Diag_Ram_add = pd.DataFrame()
         df_Diag_Ram_Update_change = pd.DataFrame()
-        df_Diag_Cal_Update_add = pd.concat([df_Diag_Batdiag_update_xq,df_Diag_Batdiag_update])#重新计算的该SN下的故障
-        df_Diag_Cal_Update = df_Diag_Cal_Update_add.drop_duplicates(subset=['product_id','start_time','end_time','code','info'], keep='first', inplace=False, ignore_index=False)#去除相同故障
+        
         df_Diag_Cal_finish = pd.DataFrame(columns=['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice','Batpos'])
         df_Diag_Cal_unfinish = pd.DataFrame(columns=['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice','Batpos'])
-        if not df_Diag_Cal_Update.empty:
+        if not df_Diag_Batdiag_update.empty:
             #------------------------------合并两者故障,并将同一sn号下的车辆故障放一起----------------------------------------------
-            df_Diag_Cal_finish = df_Diag_Cal_Update[df_Diag_Cal_Update['end_time'] != '0000-00-00 00:00:00']
-            df_Diag_Cal_unfinish = df_Diag_Cal_Update[df_Diag_Cal_Update['end_time'] == '0000-00-00 00:00:00']
-            df_Diag_Cal_finish['Batpos'] = 1
+            df_Diag_Cal_finish = df_Diag_Batdiag_update[df_Diag_Batdiag_update['end_time'] != '0000-00-00 00:00:00']
+            df_Diag_Cal_unfinish = df_Diag_Batdiag_update[df_Diag_Batdiag_update['end_time'] == '0000-00-00 00:00:00']
+            df_Diag_Cal_finish['Batpos'] = [1]*len(df_Diag_Cal_finish)
             if len(df_OprtnSta):
-                print(df_OprtnSta)
                 if df_OprtnSta.loc[0,'status'] !=1:#0禁用 1正常 2故障 3返修 4 损毁 5丢失已赔偿,6丢失未赔偿
-                    df_Diag_Cal_unfinish['Batpos'] = 1
-                    
+                    df_Diag_Cal_unfinish['Batpos'] = [1]*len(df_Diag_Cal_unfinish)
                 else:
-                    df_Diag_Cal_unfinish['Batpos'] = 0
-                
+                    df_Diag_Cal_unfinish['Batpos'] = [0]*len(df_Diag_Cal_unfinish)
+                    
+                    
         df_Diag_Cal_Update=pd.concat([df_Diag_Cal_finish,df_Diag_Cal_unfinish])    
         df_Diag_Ram_add = pd.concat([df_Diag_Cal_Update,df_Diag_Ram_sn,df_Diag_Ram_sn]).drop_duplicates(subset=['start_time','code'],keep=False)#此次判断中新增故障
         df_Diag_Ram_Update_old = pd.concat([df_Diag_Cal_Update,df_Diag_Ram_add,df_Diag_Ram_add]).drop_duplicates(subset=['start_time','code'],keep=False)#此次判断中新增故障
         df_Diag_Ram_Update_change = pd.concat([df_Diag_Ram_Update_old,df_Diag_Ram_sn,df_Diag_Ram_sn]).drop_duplicates(subset=['start_time','code','Batpos'],keep=False)#此次判断中新增故障
         df_Diag_Ram = pd.concat([df_Diag_Ram_sn_else,df_Diag_Cal_unfinish])    
-        
-        
         return df_Diag_Ram,df_Diag_Ram_add,df_Diag_Ram_Update_change

+ 3 - 3
LIB/MIDDLE/SaftyCenter/DataDiag_Static/SC_SamplingSafty.py

@@ -68,7 +68,7 @@ class SamplingSafty:
             if len(InVMinBatNo):
                 QuitErrCount[10]=0
                 if not 10 in df_Diag_Ram['code'].values.tolist():#如果故障发生当前故障中没有该故障,则压入该故障
-                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],'0000-00-00 00:00:00',sn,10,2,'电池电压采样断线,最高电压为{:.2f}V,电池编号为{},最低电压为{:.2f}V,电池编号为{}'.format(MaxVolt.values,InVMaxBatNo.values,MinVolt.values,InVMinBatNo.values),'返厂维修']
+                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],'0000-00-00 00:00:00',sn,10,2,'电池电压采样断线,最高电压为{:.2f}V,电池编号为{},最低电压为{:.2f}V,电池编号为{}'.format(MaxVolt,InVMaxBatNo.values,MinVolt,InVMinBatNo.values),'返厂维修']
                     ErrorFlg=1  
                 else:#如果故障发生当前故障中有该故障,则不进行操作
                     pass                 
@@ -177,7 +177,7 @@ class SamplingSafty:
             if len(InVMinTempBatNo):
                 QuitErrCount[53]=0
                 if not 53 in df_Diag_Ram['code'].values.tolist():#如果故障发生当前故障中没有该故障,则压入该故障
-                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],'0000-00-00 00:00:00',sn,53,2,'电池温度采样断线,最高温度为{}℃,电池编号为{},最低温度为{}℃,电池编号为{}'.format(maxCellTemp.values,InVMaxTempBatNo.values,minCellTemp.values,InVMinTempBatNo.values),'返厂维修']
+                    df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],'0000-00-00 00:00:00',sn,53,2,'电池温度采样断线,最高温度为{}℃,电池编号为{},最低温度为{}℃,电池编号为{}'.format(maxCellTemp,InVMaxTempBatNo.values,minCellTemp,InVMinTempBatNo.values),'返厂维修']
                     ErrorFlg=1 
                 else:#如果故障发生当前故障中有该故障,则不进行操作
                     pass                 
@@ -260,7 +260,7 @@ class SamplingSafty:
                 if len(InVMinOtherTempBatNo):
                     QuitErrCount[54]=0
                     if not 54 in df_Diag_Ram['code'].values.tolist():#如果故障发生当前故障中没有该故障,则压入该故障
-                        df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],'0000-00-00 00:00:00',sn,54,2,'其他温度采样断线,最高温度为{}℃,传感器编号为{},最低温度为{}℃,传感器编号为{}'.format(maxOtherTemp.values,InVMaxOtherTempBatNo.values,minOtherTemp.values,InVMinOtherTempBatNo.values),'返厂维修']
+                        df_Diag_Ram.loc[len(df_Diag_Ram)]=[bms_infoN['时间戳'],'0000-00-00 00:00:00',sn,54,2,'其他温度采样断线,最高温度为{}℃,传感器编号为{},最低温度为{}℃,传感器编号为{}'.format(maxOtherTemp,InVMaxOtherTempBatNo.values,minOtherTemp,InVMinOtherTempBatNo.values),'返厂维修']
                         ErrorFlg=1 
                     else:#如果故障发生当前故障中有该故障,则不进行操作
                         pass                 

+ 19 - 19
LIB/MIDDLE/SaftyCenter/DataDiag_Static/main.py

@@ -24,11 +24,11 @@ def diag_cal():
     #..................................设置时间..........................................................  
     start=time.time()
     end_time=datetime.datetime.now()
-    start_time=end_time-datetime.timedelta(days=1)#10分钟跑一次,一次取10分钟数据
+    start_time=end_time-datetime.timedelta(seconds=900)#10分钟跑一次,一次取10分钟数据
     start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
     end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
 
-
+    print('起',len(df_Diag_Ram))
     for sn in SNnums:#SN遍历
         print(sn)
         if 'PK500' in sn:
@@ -85,19 +85,20 @@ def diag_cal():
         #电池诊断.....................................................................................................................................................................
         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','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)
         #获取当前故障电池的历史故障信息↑↑↑↑↑↑↑↑↑↑↑.......................................................................................................................................
         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)#鹏飞计算
+            batDiag=CBMSBatDiag.BatDiag(sn,celltype,df_bms, df_soh, df_uniform, df_Diag_Batdiag_update_xq)#鹏飞计算
             df_Diag_Batdiag_update=batDiag.diag()
             # df_Diag_Batdiag_update=BatDiag.diag() 
         else:
             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_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,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)
     task_on=0
+    print('止',len(df_Diag_Ram))
 #.................................统计程序...............................
 def DaTa_Sta_Week_Task():
     task_on=1
@@ -117,11 +118,11 @@ def DaTa_Sta_Week_Task():
     #............................获取时间................................      
     end_time=datetime.datetime.now()
     # 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')
-    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):
         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)
@@ -131,7 +132,7 @@ def DaTa_Sta_Week_Task():
     all_period_fault_info.loc[0,'week']=toweek
     all_period_fault_info.loc[0,'solve_rate']=FltAlarmInfo.loc[0,'OprationManageRate']
     all_period_fault_info.fillna(0,inplace=False)
-    all_period_fault_info.to_excel('all_period_fault_info.xlsx')
+
     task_on=0
 def DaTa_Sta_Minutes_Task():
     task_on=1
@@ -182,7 +183,7 @@ def DaTa_Sta_Minutes_Task():
     FltAlarmInfo,Celltype=DataSta.SaftyWarningSta(df_fltinfo,start_time,end_time)
     SatftyCount=DataSta.SftyWrngClsfy(df_fltinfo)
     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','alarm_close_total','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']='骑享'
@@ -217,8 +218,6 @@ def DaTa_Sta_Minutes_Task():
     all_statistic_info.loc[0,'sample_safety_risk_count']=SatftyCount.loc[0,'SamplingSatyCount']
     all_statistic_info.loc[0,'controller_safety_risk_count']=SatftyCount.loc[0,'CtrlSaftyCodeCount']
     all_statistic_info.loc[0,'design_safety_risk_count']=SatftyCount.loc[0,'DsnSaftyCodeCount']
-    all_statistic_info.to_excel('all_statistic_info.xlsx')
-
     end=time.time()
     print(end-start)
     task_on=0
@@ -246,7 +245,7 @@ if __name__ == "__main__":
     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 = ['PK504B10100004365'] #SNnums_6040
+    #SNnums = ['MGMLXN750N218G006'] #SNnums_6040
     
     mylog=log.Mylog('log_diag.txt','error')
     mylog.logcfg()
@@ -262,19 +261,20 @@ if __name__ == "__main__":
     with DBRead as DBRead:
         df_Diag_Ram = DBRead.getdata('start_time','end_time','product_id','code','level','info','advice','Batpos',tablename=tablename2,factory='骑享',sn='',timename='',st='',sp='')
     # result=pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\01Screen_Problem\result.csv',encoding='gbk')
-    diag_cal()
-    DaTa_Sta_Minutes_Task()
-    DaTa_Sta_Week_Task()
 
     #定时任务.......................................................................................................................................................................
     scheduler = BlockingScheduler()
+    diag_cal()
+    DaTa_Sta_Minutes_Task()
+    DaTa_Sta_Week_Task()  
 
     if task_on==0:
         scheduler.add_job(DaTa_Sta_Week_Task, 'interval', days=7, id='Week_Task')
-        scheduler.add_job(diag_cal, 'interval', seconds=600, id='diag_job')
+        scheduler.add_job(diag_cal, 'interval', seconds=900, id='diag_job')
         scheduler.add_job(DaTa_Sta_Minutes_Task, 'interval', seconds=180, id='Hour_Task')
 
-    try:  
+    try:
+
         scheduler.start()
     except Exception as e:
         scheduler.shutdown()

+ 1 - 0
LIB/MIDDLE/SaftyCenter/Low_Soc_Alarm/main.py

@@ -80,6 +80,7 @@ mylog.logcfg()
 
 try:  
     low_soc_bat_list=Low_Soc_Alarm()
+    low_soc_bat_list.to_excel('low_soc_bat_list.xlsx')
 except Exception as e:
     print(repr(e))
     mylog.logopt(e)