Browse Source

内短路测试

qingfeng 1 year ago
parent
commit
5c992bb6c6

+ 18 - 28
LIB/MIDDLE/CellStateEstimation/BatSafetyWarning/V1_0_1/CBMSSafetyWarning.py

@@ -127,56 +127,46 @@ class SafetyWarning:
                 #获取压降最大电芯的最近一次压降值
                 try:
                     deltvolt_last = eval(df_short1.iloc[-1]['short_current'])
-                    deltvolt_last_list = list(deltvolt_last[i])
+                    deltvolt_last = np.array(deltvolt_last[i])
                 except:
-                    deltvolt_last_list = [0]*self.param.CellVoltNums
+                    deltvolt_last = np.array([0]*self.param.CellVoltNums)
                 
                 # 故障判断:1.压降累计最大>6mV,次大<3mV,2.最近一次对应电芯的压降>3mV,且离群
-                if min(deltvolt_rst)<-6:
+                if min(deltvolt_rst)<-10:
+                    deltvolt_count = np.sum(deltvolt_rst < -10)
+                    deltvolt_index = np.where(deltvolt_rst < -10)
+                    deltvolt_last1 = deltvolt_last[deltvolt_index]
+                    if deltvolt_count < 4 and min(deltvolt_last1) < -6:
+                        cellshortfault1=1
+                        cellshort_num= list(np.where(deltvolt_last<-6)[0]+1)
+                        break
+                elif min(deltvolt_rst)<-6:
                     deltvolt_rst1=list(deltvolt_rst)
                     deltvolt_min_index = deltvolt_rst1.index(min(deltvolt_rst))
-                    deltvolt_last_list1 = deltvolt_last_list.copy()
-                    deltvolt_last_list1.pop(deltvolt_min_index)
+                    deltvolt_last_list = list(deltvolt_last)
+                    deltvolt_last_list.pop(deltvolt_min_index)
                     deltvolt_rst1.remove(min(deltvolt_rst))
-                    if min(deltvolt_rst1)>-3 and deltvolt_last_list[deltvolt_min_index]<-3 and min(deltvolt_last_list1)>-2.5:
+                    if min(deltvolt_rst1)>-3 and deltvolt_last_list[deltvolt_min_index]<-3 and min(deltvolt_last_list)>-2.5:
                         cellshortfault1=1
                         cellshort_num=deltvolt_min_index+1
                         break
-                # elif min(deltvolt_rst)<-6:
-                #     deltvolt_rst1=list(deltvolt_rst)
-                #     deltvolt_rst1.remove(min(deltvolt_rst))
-                #     if min(deltvolt_rst1)>-3:
-                #         cellshortfault1=1
-                #         cellshort_num=list(deltvolt_rst).index(min(deltvolt_rst))+1
                 else:
                     cellshortfault1=0
             
         #漏电流热失控预警确认.......................................................................................
         if not 'C490' in list(self.df_warning_ram['code']):  #当前故障中没有该故障,则判断是否发生该故障
-            if cellshortfault==1:
+            if cellshortfault1:
                 faultcode='C490'
                 faultlv=4
-                faultinfo='电芯{}发生内短路'.format([cellshort_num])
+                faultinfo='电芯{}发生内短路00'.format(cellshort_num)
                 faultadvice='请立刻召回电池包,更换模组'
                 df_res_new.loc[0]=[time_now, end_time, self.sn, faultcode, faultlv, faultinfo, faultadvice]
-            else:
-                pass
-        else:
-            if cellshortfault==1 or cellshortfault1==1:
-                pass
-            else:
-                df_res_chg=self.df_warning_ram
-                df_res_chg.loc[df_res_chg[df_res_chg['code']=='C490'].index, 'end_time'] = time_now
-        
-        if not 'C490' in list(self.df_warning_ram['code']):  #当前故障中没有该故障,则判断是否发生该故障
-            if cellshortfault1==1:
+            elif cellshortfault==1:
                 faultcode='C490'
                 faultlv=4
-                faultinfo='电芯{}发生内短路00'.format([cellshort_num])
+                faultinfo='电芯{}发生内短路'.format([cellshort_num])
                 faultadvice='请立刻召回电池包,更换模组'
                 df_res_new.loc[0]=[time_now, end_time, self.sn, faultcode, faultlv, faultinfo, faultadvice]
-            else:
-                pass
         else:
             if cellshortfault==1 or cellshortfault1==1:
                 pass

+ 23 - 31
LIB/MIDDLE/CellStateEstimation/BatSafetyWarning/main.py

@@ -20,13 +20,13 @@ def saftywarning_cal():
     global df_lfp_ram
     global df_lfp_ram1
     global df_chrgvolt_ram
+    global now_time
 
     pd.set_option('display.width', 300) # 设置字符显示宽度
     pd.set_option('display.max_rows', None) # 设置显示最大行
     pd.set_option('display.max_columns', None) # 设置显示最大列,None为显示所有列
     
     # start=time.time()
-    now_time=datetime.datetime.now()
     start_time=now_time-datetime.timedelta(hours=6)
     start_time1=now_time-datetime.timedelta(days=7)
     start_time2=now_time-datetime.timedelta(days=3)
@@ -36,6 +36,7 @@ def saftywarning_cal():
     start_time2=start_time2.strftime('%Y-%m-%d %H:%M:%S')
     start_time3=start_time3.strftime('%Y-%m-%d %H:%M:%S')
     end_time=now_time.strftime('%Y-%m-%d %H:%M:%S')
+    now_time=now_time+datetime.timedelta(hours=6)
 
 
     #数据库配置
@@ -50,7 +51,7 @@ def saftywarning_cal():
     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=110 and end_time='0000-00-00 00:00:00'" %(param,tablename)
+    sql =  "select %s from %s where code='C490' and end_time='0000-00-00 00:00:00'" %(param,tablename)
     cursor.execute(sql)
     res = cursor.fetchall()
     df_fault_ram= pd.DataFrame(res,columns=param.split(','))
@@ -166,7 +167,7 @@ def saftywarning_cal():
         tablename4='outlier_voltchangeratio'   #电压离群表单
         DBRead=DBDownload.DBDownload(host, port, db, user, password,mode)
         with DBRead as DBRead:
-            df_short=DBRead.getdata('time_sp,sn,method,short_current', tablename=tablename1, sn=sn, timename='time_sp', st=start_time1, sp=end_time)
+            df_short=DBRead.getdata('time_st,time_sp,sn,method,short_current', tablename=tablename1, sn=sn, timename='time_sp', st=start_time1, sp=end_time)
             df_uniform=DBRead.getdata('time,sn,cellsoc_diff,cellvolt_diff,cellmin_num,cellmax_num,cellvolt_rank', tablename=tablename3, sn=sn, timename='time', st=start_time2, sp=end_time)
             df_voltsigma=DBRead.getdata('time,sn,VolOl_Uni,VolChng_Uni', tablename=tablename4, sn=sn, timename='time', st=start_time3, sp=end_time)
 
@@ -175,40 +176,31 @@ def saftywarning_cal():
         
         #热安全预警
         if df_fault_ram_sn.empty:
-            BatWarning=CBMSSafetyWarning.SafetyWarning(sn,celltype,df_short,df_uniform,df_voltsigma,df_soh)
-            df_warning_res=BatWarning.diag()
+            BatWarning=CBMSSafetyWarning.SafetyWarning(sn,celltype,df_short,df_uniform,df_soh,df_fault_ram_sn)
+            df_res_new, df_res_chg=BatWarning.diag()
             #当前热失控故障写入数据库
-            if not df_warning_res.empty:
-                with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\热失控预警.txt','a',encoding="utf-8") as file:
-                    file.write(str(tuple(df_warning_res.iloc[-1]))+'\n')
+            if not df_res_new.empty:
+                with open(r'热失控预警.txt','a',encoding="utf-8") as file:
+                    file.write(str(tuple(df_res_new.iloc[-1]))+'\n')
+            if not df_res_chg.empty:
+                with open(r'热失控预警.txt','a',encoding="utf-8") as file:
+                    file.write(str(tuple(df_res_chg.iloc[-1]))+'\n')
         
-        else:
-            fault_time=datetime.datetime.strptime(df_fault_ram_sn.iloc[-1]['start_time'], '%Y-%m-%d %H:%M:%S')
-            if (now_time-fault_time).total_seconds()>3*24*3600:   #df_warning_end历史故障筛选并更改数据库故障结束时间
-                df_fault_ram_sn['end_time']=end_time
-                df_fault_ram_sn['Batpos']=1
-                with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\热失控预警.txt','a',encoding="utf-8") as file:
-                    file.write(str(tuple(df_warning_res.iloc[-1]))+'\n')
+        # else:
+        #     fault_time=datetime.datetime.strptime(df_fault_ram_sn.iloc[-1]['start_time'], '%Y-%m-%d %H:%M:%S')
+        #     if (now_time-fault_time).total_seconds()>3*24*3600:   #df_warning_end历史故障筛选并更改数据库故障结束时间
+        #         df_fault_ram_sn['end_time']=end_time
+        #         df_fault_ram_sn['Batpos']=1
+        #         with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\热失控预警.txt','a',encoding="utf-8") as file:
+        #             file.write(str(tuple(df_res_new.iloc[-1]))+'\n')
 
 
 #...............................................主函数起定时作用.......................................................................................................................
 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=['PK50001A100000577']
+    SNnums=['PK50201A000002052']
+    now_time='2022-11-22 14:00:00'
+    now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
     
     # mylog=log.Mylog('log_warning.txt','error')
     # mylog.logcfg()
@@ -225,7 +217,7 @@ if __name__ == "__main__":
 
     #定时任务.......................................................................................................................................................................
     scheduler = BlockingScheduler()
-    scheduler.add_job(saftywarning_cal, 'interval', seconds=6)
+    scheduler.add_job(saftywarning_cal, 'interval', seconds=10)
 
     try:  
         scheduler.start()

+ 16 - 17
USER/test.ipynb

@@ -260,36 +260,35 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": 62,
    "metadata": {},
    "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "0b1001\n",
-      "0b100\n"
-     ]
-    },
     {
      "data": {
       "text/plain": [
-       "0"
+       "array([-15.2,  -1.6,  -1.4])"
       ]
      },
-     "execution_count": 1,
+     "execution_count": 62,
      "metadata": {},
      "output_type": "execute_result"
     }
    ],
    "source": [
-    "a=9\n",
-    "print(bin(a))\n",
-    "b=a>>1\n",
-    "print(bin(b))\n",
-    "b & 1\n",
-    "0%9"
+    "import numpy as np\n",
+    "a = np.array([-1, -15.2, 1.9, -1.6, 1.3, -1.4, 1.3, 0.8, 1.4, 1.9, -0.2, 1.0, 4.8, 0.5])\n",
+    "m = np.mean(a)\n",
+    "s = np.std(a)\n",
+    "b = np.where(a<-1)\n",
+    "a[b[0]]\n"
    ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
   }
  ],
  "metadata": {