|
@@ -0,0 +1,160 @@
|
|
|
|
+# 获取数据
|
|
|
|
+from LIB.BACKEND import DBManager
|
|
|
|
+
|
|
|
|
+import os
|
|
|
|
+import pandas as pd
|
|
|
|
+import numpy as np
|
|
|
|
+import bisect
|
|
|
|
+import datetime
|
|
|
|
+# import matplotlib.pyplot as plt
|
|
|
|
+
|
|
|
|
+#参数输入
|
|
|
|
+Capacity = 53.6
|
|
|
|
+PackFullChrgVolt=69.99
|
|
|
|
+CellFullChrgVolt=3.37
|
|
|
|
+CellVoltNums=20
|
|
|
|
+CellTempNums=4
|
|
|
|
+FullChrgSoc=98
|
|
|
|
+CellVoltPort=[3.357,3.358,3.359,3.36,3.361]
|
|
|
|
+PeakSoc=57
|
|
|
|
+# #40Ah-OCV
|
|
|
|
+# LookTab_SOC = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]
|
|
|
|
+# LookTab_OCV = [3.3159, 3.4502, 3.4904, 3.5277, 3.5590, 3.5888, 3.6146, 3.6312, 3.6467, 3.6642, 3.6865, 3.7171, 3.7617,
|
|
|
|
+# 3.8031, 3.8440, 3.8888, 3.9376, 3.9891, 4.0451, 4.1068, 4.1830]
|
|
|
|
+#55Ah-OCV
|
|
|
|
+LookTab_SOC = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
|
|
|
|
+LookTab_OCV = [3.1820, 3.2250, 3.2730, 3.2840, 3.2860, 3.2920, 3.3210, 3.3260, 3.3270, 3.3270, 3.3640]
|
|
|
|
+
|
|
|
|
+# 获取数据时间段
|
|
|
|
+def cal_LFPLeakCurrent(sn, end_time, start_time):
|
|
|
|
+ end_time = end_time
|
|
|
|
+ strat_time = start_time
|
|
|
|
+
|
|
|
|
+ sn = sn
|
|
|
|
+ st = strat_time
|
|
|
|
+ et = end_time
|
|
|
|
+
|
|
|
|
+ dbManager = DBManager.DBManager()
|
|
|
|
+ df_data = dbManager.get_data(sn=sn, start_time=st, end_time=et, data_groups=['bms'])
|
|
|
|
+ df_bms = df_data['bms']
|
|
|
|
+
|
|
|
|
+ #寻找电压最大值
|
|
|
|
+ packcrnt=df_bms['总电流[A]']
|
|
|
|
+ SOC=df_bms['SOC[%]']
|
|
|
|
+ bmsstat=df_bms['充电状态']
|
|
|
|
+ time= pd.to_datetime(df_bms['时间戳'], format='%Y-%m-%d %H:%M:%S')
|
|
|
|
+
|
|
|
|
+ #第一步:筛选充电数据
|
|
|
|
+ ChgStart=[]
|
|
|
|
+ ChgEnd=[]
|
|
|
|
+ for i in range(3, len(time) - 3):
|
|
|
|
+ if i==3 and bmsstat[i]==2 and bmsstat[i+1]==2 and bmsstat[i+2]==2:
|
|
|
|
+ ChgStart.append(i)
|
|
|
|
+ elif bmsstat[i-2]!=2 and bmsstat[i-1]!=2 and bmsstat[i]==2:
|
|
|
|
+ ChgStart.append(i)
|
|
|
|
+ elif bmsstat[i-1]==2 and bmsstat[i]!=2 and bmsstat[i+1]!=2:
|
|
|
|
+ ChgEnd.append(i)
|
|
|
|
+ elif i == (len(time) - 4) and bmsstat[len(bmsstat)-1] == 2 and bmsstat[len(bmsstat)-2] == 2:
|
|
|
|
+ ChgEnd.append(len(time)-1)
|
|
|
|
+
|
|
|
|
+ #第二步:筛选充电起始Soc<45%,且单体最小电压>3.37V的数据
|
|
|
|
+ ChgStartValid=[]
|
|
|
|
+ ChgEndValid=[]
|
|
|
|
+ if ChgStart:
|
|
|
|
+ for i in range(len(ChgEnd)):
|
|
|
|
+ #寻找最小电压值
|
|
|
|
+ cellvolt = []
|
|
|
|
+ for j in range(1, CellVoltNums+1):
|
|
|
|
+ s = str(j)
|
|
|
|
+ volt = df_bms['单体电压' + s]/1000
|
|
|
|
+ cellvolt.append(max(volt[ChgStart[i]:ChgEnd[i]]))
|
|
|
|
+ if min(cellvolt)>CellFullChrgVolt and SOC[ChgStart[i]]<40 and (ChgEnd[i]-ChgStart[i])>10:
|
|
|
|
+ if ((time[ChgEnd[i]]-time[ChgStart[i]]).total_seconds())/(ChgEnd[i]-ChgStart[i])<30:
|
|
|
|
+ ChgStartValid.append(ChgStart[i])
|
|
|
|
+ ChgEndValid.append(ChgEnd[i])
|
|
|
|
+
|
|
|
|
+ #第三步:计算充电每个单体到达3.368V的Ah差
|
|
|
|
+ #定义寻找电压3.368V的数据点
|
|
|
|
+ def data_search(data1,data2,data3,data4):
|
|
|
|
+ Soc=0
|
|
|
|
+ for m in range(1,len(data1)):
|
|
|
|
+ t=(data2[m]-data2[m-1]).total_seconds()
|
|
|
|
+ Soc=Soc-data3[m]*t/(3600*Capacity)
|
|
|
|
+ if data1[m]>data4:
|
|
|
|
+ DetaT=(data2[m]-data2[0]).total_seconds()
|
|
|
|
+ return Soc,m
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+ if ChgStartValid:
|
|
|
|
+ df_DetaTime=pd.DataFrame()
|
|
|
|
+ df_DetaTime1=pd.DataFrame()
|
|
|
|
+ df_detatime=pd.DataFrame()
|
|
|
|
+ for i in range(len(ChgStartValid)):
|
|
|
|
+ DetaSoc1=[]
|
|
|
|
+ DetaSoc2 = []
|
|
|
|
+ DetaSoc=[]
|
|
|
|
+ a=list(range(5))
|
|
|
|
+ b=list(range(5))
|
|
|
|
+ #计算1-10号电芯到达特定电压值得时间和SOC
|
|
|
|
+ for j in range(1, CellVoltNums-9):
|
|
|
|
+ s = str(j)
|
|
|
|
+ cellvolt = df_bms['单体电压' + s]/1000
|
|
|
|
+ cellvolt=list(cellvolt[ChgStartValid[i]:ChgEndValid[i]])
|
|
|
|
+ Time=list(time[ChgStartValid[i]:ChgEndValid[i]])
|
|
|
|
+ Packcrnt=list(packcrnt[ChgStartValid[i]:ChgEndValid[i]])
|
|
|
|
+ for k in range(len(CellVoltPort)):
|
|
|
|
+ a[k],b[k]=data_search(cellvolt,Time,Packcrnt,CellVoltPort[k])
|
|
|
|
+ DetaSoc1.append(np.mean(a)) #计算到达3.368V的时长
|
|
|
|
+ # DetaT.append((Time[b]-Time[0]).total_seconds())
|
|
|
|
+
|
|
|
|
+ #计算1-10号电芯到达特定电压值的平均Soc
|
|
|
|
+ Socmean1=(sum(DetaSoc1)-max(DetaSoc1)-min(DetaSoc1))/(len(DetaSoc1)-2)
|
|
|
|
+ # Tmean=np.mean(DetaT)
|
|
|
|
+
|
|
|
|
+ ##计算11-20号电芯到达特定电压值得时间和SOC
|
|
|
|
+ for j in range(11, CellVoltNums+1):
|
|
|
|
+ s = str(j)
|
|
|
|
+ cellvolt = df_bms['单体电压' + s]/1000
|
|
|
|
+ cellvolt=list(cellvolt[ChgStartValid[i]:ChgEndValid[i]])
|
|
|
|
+ Time=list(time[ChgStartValid[i]:ChgEndValid[i]])
|
|
|
|
+ Packcrnt=list(packcrnt[ChgStartValid[i]:ChgEndValid[i]])
|
|
|
|
+ for k in range(len(CellVoltPort)):
|
|
|
|
+ a[k],b[k]=data_search(cellvolt,Time,Packcrnt,CellVoltPort[k])
|
|
|
|
+ DetaSoc2.append(np.mean(a)) #计算到达3.368V的时长
|
|
|
|
+
|
|
|
|
+ #计算11-20号电芯到达特定电压值的平均Soc
|
|
|
|
+ Socmean2=(sum(DetaSoc2)-max(DetaSoc2)-min(DetaSoc2))/(len(DetaSoc2)-2)
|
|
|
|
+
|
|
|
|
+ #计算每个电芯的Soc差
|
|
|
|
+
|
|
|
|
+ DetaSoc3=DetaSoc1+DetaSoc2
|
|
|
|
+ for j in range(len(DetaSoc3)):
|
|
|
|
+ if j<10:
|
|
|
|
+ Socmean=Socmean1
|
|
|
|
+ else:
|
|
|
|
+ Socmean=Socmean2
|
|
|
|
+ DetaSoc.append(DetaSoc3[j]-Socmean)
|
|
|
|
+ # DetaSoc.append((DetaT[j]-Tmean)*9.5/(Capacity*3600))
|
|
|
|
+ df_DetaTime[time[ChgStartValid[i]]]=DetaSoc
|
|
|
|
+ #漏电流计算
|
|
|
|
+ column=[]
|
|
|
|
+ time1=[]
|
|
|
|
+ sn1=[]
|
|
|
|
+
|
|
|
|
+ for index, row in df_DetaTime.iteritems():
|
|
|
|
+ column.append(index) #提取列名称
|
|
|
|
+
|
|
|
|
+ for i in range(1,len(column)):#计算漏电流值
|
|
|
|
+ df_DetaTime1[column[i]] = df_DetaTime.apply(lambda x: (x[column[i-1]] - x[column[i]])*1000*Capacity*3600/((column[i]-column[i-1]).total_seconds()), axis=1)
|
|
|
|
+ time1.append(column[i])
|
|
|
|
+ sn1.append(sn)
|
|
|
|
+ df_detatime['time']=time1
|
|
|
|
+ df_detatime['sn']=sn1
|
|
|
|
+
|
|
|
|
+ for i in range(CellVoltNums):
|
|
|
|
+ cell=[]
|
|
|
|
+ for j in range(1,len(column)):
|
|
|
|
+ cell.append(df_DetaTime1[column[j]][i])
|
|
|
|
+ df_detatime['cell'+str(i+1)]=cell
|
|
|
|
+ return df_detatime
|
|
|
|
+ return pd.DataFrame()
|