ソースを参照

修复key error==0问题

Eric412V 2 年 前
コミット
9c100b8eb5

+ 26 - 25
LIB/MIDDLE/SaftyCenter/Low_Soc_Alarm/low_soc_alarm.py

@@ -7,29 +7,30 @@ import datetime,time
 
 class Low_soc_alarm():
     def low_soc_alarm(param,df_bms,low_soc_bat_list,sn,df_OprtnSta):
-        if len(df_bms) and df_OprtnSta.loc[0,'status'] !=3:#0禁用 1正常 2故障 3返修 4 损毁 5丢失已赔偿,6丢失未赔偿:
-            VoltageNum=['单体电压'+str(i) for i in range(1,param.CellVoltNums+1)]
-            df_bms[VoltageNum]=df_bms[VoltageNum]/1000
-            CellVol=df_bms[VoltageNum]
-            PackCrnt=df_bms['总电流[A]']
-            ZeroCrntCount=len(df_bms[abs(df_bms['总电流[A]'])<=1])
-            CrntCount=len(PackCrnt)-ZeroCrntCount
-            if CrntCount>0:
-                ZeroCrntRate=(ZeroCrntCount/len(PackCrnt))*100
-            else:
-                ZeroCrntRate=100
-            if ZeroCrntRate>99.85:#静置比大于99.85%
-                ZeroSoc_Volt=np.interp(0,param.LookTab_SOC,param.LookTab_OCV)
-                FiveSoc_Volt=np.interp(10,param.LookTab_SOC,param.LookTab_OCV)
-                CellVolMean=DataFrame()
-                CellVolMean=CellVol.mean()
-                CellVolMin_Index=CellVolMean.idxmin()
-                print(ZeroSoc_Volt)
-                CellLowVolZERO=df_bms[df_bms[CellVolMin_Index] < ZeroSoc_Volt]
-                CellLowVolFive=df_bms[df_bms[CellVolMin_Index] > FiveSoc_Volt]
-                CellLowVolZeroCrnt=CellLowVolZERO[abs(CellLowVolZERO['总电流[A]'])<1]
-                CellLowVolFiveCrnt=CellLowVolFive[abs(CellLowVolFive['总电流[A]'])<1]
-                if len(CellLowVolZeroCrnt)>3 and len(CellLowVolFiveCrnt)<3:
-                    CellLowVolZeroCrnt=CellLowVolZeroCrnt.reset_index(drop=True)
-                    low_soc_bat_list.loc[len(low_soc_bat_list)]=[sn,CellLowVolZeroCrnt.loc[len(CellLowVolZeroCrnt)-1,'时间戳'],3]
+        if len(df_bms) and len(df_OprtnSta):
+            if df_OprtnSta.loc[0,'status'] !=3:#0禁用 1正常 2故障 3返修 4 损毁 5丢失已赔偿,6丢失未赔偿:
+                VoltageNum=['单体电压'+str(i) for i in range(1,param.CellVoltNums+1)]
+                df_bms[VoltageNum]=df_bms[VoltageNum]/1000
+                CellVol=df_bms[VoltageNum]
+                PackCrnt=df_bms['总电流[A]']
+                ZeroCrntCount=len(df_bms[abs(df_bms['总电流[A]'])<=1])
+                CrntCount=len(PackCrnt)-ZeroCrntCount
+                if CrntCount>0:
+                    ZeroCrntRate=(ZeroCrntCount/len(PackCrnt))*100
+                else:
+                    ZeroCrntRate=100
+                if ZeroCrntRate>99.85:#静置比大于99.85%
+                    ZeroSoc_Volt=np.interp(0,param.LookTab_SOC,param.LookTab_OCV)
+                    FiveSoc_Volt=np.interp(10,param.LookTab_SOC,param.LookTab_OCV)
+                    CellVolMean=DataFrame()
+                    CellVolMean=CellVol.mean()
+                    CellVolMin_Index=CellVolMean.idxmin()
+                    print(ZeroSoc_Volt)
+                    CellLowVolZERO=df_bms[df_bms[CellVolMin_Index] < ZeroSoc_Volt]
+                    CellLowVolFive=df_bms[df_bms[CellVolMin_Index] > FiveSoc_Volt]
+                    CellLowVolZeroCrnt=CellLowVolZERO[abs(CellLowVolZERO['总电流[A]'])<1]
+                    CellLowVolFiveCrnt=CellLowVolFive[abs(CellLowVolFive['总电流[A]'])<1]
+                    if len(CellLowVolZeroCrnt)>3 and len(CellLowVolFiveCrnt)<3:
+                        CellLowVolZeroCrnt=CellLowVolZeroCrnt.reset_index(drop=True)
+                        low_soc_bat_list.loc[len(low_soc_bat_list)]=[sn,CellLowVolZeroCrnt.loc[len(CellLowVolZeroCrnt)-1,'时间戳'],3]
         return low_soc_bat_list

+ 42 - 19
LIB/MIDDLE/SaftyCenter/Low_Soc_Alarm/main.py

@@ -11,30 +11,52 @@ import datacompy
 from LIB.MIDDLE.SaftyCenter.Common import QX_BatteryParam
 from LIB.MIDDLE.SaftyCenter.Common import DBDownload as DBDw
 from low_soc_alarm import Low_soc_alarm
+import pymysql
+
+
+
 def Low_Soc_Alarm():
     end_time=datetime.datetime.now()
     start_time=end_time-datetime.timedelta(days=1)
     start_time=start_time.strftime('%Y-%m-%d %H:%M:%S')
     end_time=end_time.strftime('%Y-%m-%d %H:%M:%S')
     #-------------------------读取数据-------------------------------------------------------------------
-    excelpath=r'D:\ZLWORK\code\data_analyze_platform\USER\eric\SaftyCenter_CODE_V1\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
+    host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
+    port=3306
+    db='qixiang_oss'
+    user='qixiang_oss'
+    password='Qixiang2021'
+    conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
+    cursor = conn.cursor()
+    cursor.execute("select sn from app_device")
+    res = cursor.fetchall()
+    df_sn = pd.DataFrame(res, columns=['sn'])
+    df_sn = df_sn.reset_index(drop=True)
+    conn.close();
+    
+    
+    
+    
+    
+    # excelpath=r'D:\ZLWORK\code\data_analyze_platform\USER\eric\SaftyCenter_CODE_V1\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=['MGMCLN750N215I009']
+    #SNnums=df_sn
     #-------------------------执行循环----------------------------------------------------------------------
     low_soc_bat_list=DataFrame(columns=['sn','time','level'])
-    for sn in SNnums:#SN遍历
+    for sn in df_sn['sn']:#SN遍历
         print(sn)
         if 'PK500' in sn:
             celltype=1 #6040三元电芯
@@ -71,11 +93,12 @@ def Low_Soc_Alarm():
         
         #执行主程序-------------------------------------------------------------------------------------------
         low_soc_bat_list=Low_soc_alarm.low_soc_alarm(param,df_bms,low_soc_bat_list,sn,df_OprtnSta)
-
+        if len(low_soc_bat_list):
+            print(low_soc_bat_list)
 
     return low_soc_bat_list
-mylog=log.Mylog('log_diag.txt','error')
-mylog.logcfg()
+# mylog=log.Mylog('log_diag.txt','error')
+# mylog.logcfg()
 
 
 try:  
@@ -83,4 +106,4 @@ try:
     low_soc_bat_list.to_excel('low_soc_bat_list.xlsx')
 except Exception as e:
     print(repr(e))
-    mylog.logopt(e)
+    # mylog.logopt(e)