qingfeng 2 years ago
parent
commit
851885918b
1 changed files with 41 additions and 33 deletions
  1. 41 33
      LIB/MIDDLE/CellStateEstimation/BatSafetyWarning/main.py

+ 41 - 33
LIB/MIDDLE/CellStateEstimation/BatSafetyWarning/main.py

@@ -4,11 +4,11 @@ from LIB.BACKEND import DBManager, Log
 from apscheduler.schedulers.blocking import BlockingScheduler
 from apscheduler.schedulers.blocking import BlockingScheduler
 import datetime
 import datetime
 from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload
 from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload
-from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
-import CBMSBatInterShort
-import CBMSBatUniform
-import VoltStray
-import CBMSSafetyWarning
+# from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
+from LIB.MIDDLE.CellStateEstimation.BatSafetyWarning.V1_0_1 import CBMSBatInterShort
+from LIB.MIDDLE.CellStateEstimation.BatSafetyWarning.V1_0_1 import CBMSBatUniform
+from LIB.MIDDLE.CellStateEstimation.BatSafetyWarning.V1_0_1 import VoltStray
+from LIB.MIDDLE.CellStateEstimation.BatSafetyWarning.V1_0_1 import CBMSSafetyWarning
 
 
 #电池热安全预警核心算法函数......................................................................................................................
 #电池热安全预警核心算法函数......................................................................................................................
 def saftywarning_cal():
 def saftywarning_cal():
@@ -19,6 +19,7 @@ def saftywarning_cal():
     global df_warning_ram3
     global df_warning_ram3
     global df_lfp_ram
     global df_lfp_ram
     global df_lfp_ram1
     global df_lfp_ram1
+    global df_chrgvolt_ram
 
 
     pd.set_option('display.width', 300) # 设置字符显示宽度
     pd.set_option('display.width', 300) # 设置字符显示宽度
     pd.set_option('display.max_rows', None) # 设置显示最大行
     pd.set_option('display.max_rows', None) # 设置显示最大行
@@ -94,10 +95,12 @@ def saftywarning_cal():
             df_warning_ram_sn1=df_warning_ram1[df_warning_ram1['sn']==sn]
             df_warning_ram_sn1=df_warning_ram1[df_warning_ram1['sn']==sn]
             df_warning_ram_sn2=df_warning_ram2[df_warning_ram2['sn']==sn]
             df_warning_ram_sn2=df_warning_ram2[df_warning_ram2['sn']==sn]
             df_warning_ram_sn3=df_warning_ram3[df_warning_ram3['sn']==sn]
             df_warning_ram_sn3=df_warning_ram3[df_warning_ram3['sn']==sn]
+            df_chrgvolt_ram_sn=df_chrgvolt_ram[df_chrgvolt_ram['sn']==sn]
             df_warning_ram_sn.reset_index(inplace=True,drop=True)     #重置索引
             df_warning_ram_sn.reset_index(inplace=True,drop=True)     #重置索引
             df_warning_ram_sn1.reset_index(inplace=True,drop=True)     #重置索引
             df_warning_ram_sn1.reset_index(inplace=True,drop=True)     #重置索引
             df_warning_ram_sn2.reset_index(inplace=True,drop=True)     #重置索引
             df_warning_ram_sn2.reset_index(inplace=True,drop=True)     #重置索引
             df_warning_ram_sn3.reset_index(inplace=True,drop=True)     #重置索引
             df_warning_ram_sn3.reset_index(inplace=True,drop=True)     #重置索引
+            df_chrgvolt_ram_sn.reset_index(inplace=True,drop=True)
             if celltype>50 and (not df_lfp_ram.empty):
             if celltype>50 and (not df_lfp_ram.empty):
                 df_lfp_ram_sn=df_lfp_ram[df_lfp_ram['sn']==sn]
                 df_lfp_ram_sn=df_lfp_ram[df_lfp_ram['sn']==sn]
                 df_lfp_ram_sn.reset_index(inplace=True,drop=True)     #重置索引
                 df_lfp_ram_sn.reset_index(inplace=True,drop=True)     #重置索引
@@ -112,36 +115,40 @@ def saftywarning_cal():
                 df_lfp_ram1=pd.DataFrame(columns=df_bms.columns.tolist()+['sn'])
                 df_lfp_ram1=pd.DataFrame(columns=df_bms.columns.tolist()+['sn'])
 
 
             #内短路计算..................................................................................................................................................
             #内短路计算..................................................................................................................................................
-            BatShort=CBMSBatInterShort.BatInterShort(sn,celltype,df_bms,df_soh,df_warning_ram_sn,df_warning_ram_sn1,df_warning_ram_sn2,df_warning_ram_sn3,df_lfp_ram_sn)
-            df_short_res, df_ram_res, df_ram_res1, df_ram_res2, df_ram_res3, df_ram_res4=BatShort.intershort() 
+            BatShort=CBMSBatInterShort.BatInterShort(sn,celltype,df_bms,df_soh,df_warning_ram_sn,df_warning_ram_sn1,df_warning_ram_sn2,df_warning_ram_sn3,df_lfp_ram_sn,df_chrgvolt_ram_sn)
+            df_short_res, df_ram_res, df_ram_res1, df_ram_res2, df_ram_res3, df_ram_res4, df_chrgvolt_ram_sn=BatShort.intershort() 
             if not df_short_res.empty:
             if not df_short_res.empty:
-                with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\内短路.txt','a') as file:
-                    file.write(str(df_short_res)+'\n')
+                pass
+                # with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\内短路.txt','a') as file:
+                #     file.write(str(df_short_res)+'\n')
             
             
             #静置电压排名..................................................................................................................................................
             #静置电压排名..................................................................................................................................................
             BatUniform=CBMSBatUniform.BatUniform(sn,celltype,df_bms,df_uniform,df_ram_res3,df_lfp_ram_sn1)
             BatUniform=CBMSBatUniform.BatUniform(sn,celltype,df_bms,df_uniform,df_ram_res3,df_lfp_ram_sn1)
             df_rank_res, df_ram_res3, df_ram_res5=BatUniform.batuniform()
             df_rank_res, df_ram_res3, df_ram_res5=BatUniform.batuniform()
             if not df_rank_res.empty:
             if not df_rank_res.empty:
                 df_uniform=df_rank_res
                 df_uniform=df_rank_res
-                with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\电压排名.txt','a') as file:
-                    file.write(str(df_rank_res)+'\n')
+                # with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\电压排名.txt','a') as file:
+                #     file.write(str(df_rank_res)+'\n')
             
             
             #电压离群.....................................................................................................................................................
             #电压离群.....................................................................................................................................................
             df_voltsigma=VoltStray.main(sn,df_bms,celltype)
             df_voltsigma=VoltStray.main(sn,df_bms,celltype)
             if not df_voltsigma.empty:
             if not df_voltsigma.empty:
-                with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\电压离群.txt','a') as file:
-                    file.write(str(df_voltsigma)+'\n')
+                pass
+                # with open(r'D:\Platform\platform_python\data_analyze_platform\USER\spf\01qixiang\07BatSafetyWarning\电压离群.txt','a') as file:
+                #     file.write(str(df_voltsigma)+'\n')
 
 
             #ram处理................................................................................................................
             #ram处理................................................................................................................
             df_warning_ram=df_warning_ram.drop(df_warning_ram[df_warning_ram.sn==sn].index)
             df_warning_ram=df_warning_ram.drop(df_warning_ram[df_warning_ram.sn==sn].index)
             df_warning_ram1=df_warning_ram1.drop(df_warning_ram1[df_warning_ram1.sn==sn].index)
             df_warning_ram1=df_warning_ram1.drop(df_warning_ram1[df_warning_ram1.sn==sn].index)
             df_warning_ram2=df_warning_ram2.drop(df_warning_ram2[df_warning_ram2.sn==sn].index)
             df_warning_ram2=df_warning_ram2.drop(df_warning_ram2[df_warning_ram2.sn==sn].index)
             df_warning_ram3=df_warning_ram3.drop(df_warning_ram3[df_warning_ram3.sn==sn].index)
             df_warning_ram3=df_warning_ram3.drop(df_warning_ram3[df_warning_ram3.sn==sn].index)
+            df_chrgvolt_ram=df_chrgvolt_ram.drop(df_chrgvolt_ram[df_chrgvolt_ram.sn==sn].index)
 
 
             df_warning_ram=pd.concat([df_warning_ram,df_ram_res],ignore_index=True)
             df_warning_ram=pd.concat([df_warning_ram,df_ram_res],ignore_index=True)
             df_warning_ram1=pd.concat([df_warning_ram1,df_ram_res1],ignore_index=True)
             df_warning_ram1=pd.concat([df_warning_ram1,df_ram_res1],ignore_index=True)
             df_warning_ram2=pd.concat([df_warning_ram2,df_ram_res2],ignore_index=True)
             df_warning_ram2=pd.concat([df_warning_ram2,df_ram_res2],ignore_index=True)
             df_warning_ram3=pd.concat([df_warning_ram3,df_ram_res3],ignore_index=True)
             df_warning_ram3=pd.concat([df_warning_ram3,df_ram_res3],ignore_index=True)
+            df_chrgvolt_ram=pd.concat([df_chrgvolt_ram,df_chrgvolt_ram_sn],ignore_index=True)
             
             
             if celltype>50:
             if celltype>50:
                 df_lfp_ram=df_lfp_ram.drop(df_lfp_ram[df_lfp_ram.sn==sn].index)
                 df_lfp_ram=df_lfp_ram.drop(df_lfp_ram[df_lfp_ram.sn==sn].index)
@@ -159,7 +166,7 @@ def saftywarning_cal():
         tablename4='outlier_voltchangeratio'   #电压离群表单
         tablename4='outlier_voltchangeratio'   #电压离群表单
         DBRead=DBDownload.DBDownload(host, port, db, user, password,mode)
         DBRead=DBDownload.DBDownload(host, port, db, user, password,mode)
         with DBRead as DBRead:
         with DBRead as DBRead:
-            df_short=DBRead.getdata('time_sp,sn,short_current', tablename=tablename1, sn=sn, timename='time_sp', st=start_time1, sp=end_time)
+            df_short=DBRead.getdata('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_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)
             df_voltsigma=DBRead.getdata('time,sn,VolOl_Uni,VolChng_Uni', tablename=tablename4, sn=sn, timename='time', st=start_time3, sp=end_time)
 
 
@@ -187,24 +194,24 @@ def saftywarning_cal():
 #...............................................主函数起定时作用.......................................................................................................................
 #...............................................主函数起定时作用.......................................................................................................................
 if __name__ == "__main__":
 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=['MGMCLN750N215I091']
+    # 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']
     
     
-    mylog=log.Mylog('log_warning.txt','error')
-    mylog.logcfg()
+    # mylog=log.Mylog('log_warning.txt','error')
+    # mylog.logcfg()
 
 
     #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取...................................
     #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取...................................
     df_warning_ram=pd.DataFrame(columns=['sn','time','deltsoc','cellsoc'])
     df_warning_ram=pd.DataFrame(columns=['sn','time','deltsoc','cellsoc'])
@@ -213,15 +220,16 @@ if __name__ == "__main__":
     df_warning_ram3=pd.DataFrame(columns=['sn','time3','standingtime','standingtime1','standingtime2'])
     df_warning_ram3=pd.DataFrame(columns=['sn','time3','standingtime','standingtime1','standingtime2'])
     df_lfp_ram=pd.DataFrame()
     df_lfp_ram=pd.DataFrame()
     df_lfp_ram1=pd.DataFrame()
     df_lfp_ram1=pd.DataFrame()
+    df_chrgvolt_ram=pd.DataFrame(columns=['sn','time','deltvolt','packcrnt_avg','temp_avg'])
 
 
 
 
     #定时任务.......................................................................................................................................................................
     #定时任务.......................................................................................................................................................................
     scheduler = BlockingScheduler()
     scheduler = BlockingScheduler()
-    scheduler.add_job(saftywarning_cal, 'interval', hours=6)
+    scheduler.add_job(saftywarning_cal, 'interval', seconds=6)
 
 
     try:  
     try:  
         scheduler.start()
         scheduler.start()
     except Exception as e:
     except Exception as e:
         scheduler.shutdown()
         scheduler.shutdown()
         print(repr(e))
         print(repr(e))
-        mylog.logopt(e)
+        # mylog.logopt(e)