Преглед на файлове

Merge branch 'dev' of http://git.fast-fun.cn:92/lmstack/data_analyze_platform into dev

lmstack преди 3 години
родител
ревизия
b53dba7c79

+ 11 - 9
LIB/MIDDLE/DeltSoc/LFPDeltSoc20210804.py

@@ -40,7 +40,6 @@ def cal_deltsoc(sn, end_time, start_time):
     # 筛选充电数据
     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)
@@ -52,10 +51,9 @@ def cal_deltsoc(sn, end_time, start_time):
             ChgEnd.append(len(time)-1)
 
     # 筛选充电起始Soc<46%,电芯温度>15℃的数据
+    ChgStartValid = []
+    ChgEndValid = []
     if ChgStart:
-        ChgStartValid = []
-        ChgEndValid = []
-
         for i in range(min(len(ChgStart),len(ChgEnd))):
             # 获取最小温度值
             celltemp = []
@@ -64,7 +62,7 @@ def cal_deltsoc(sn, end_time, start_time):
                 temp = df_bms['单体温度' + s]
                 celltemp.append(temp[ChgEnd[i]])
 
-            if SOC[ChgStart[i]] < 46 and SOC[ChgEnd[i]]>80 and min(celltemp) > 10:
+            if SOC[ChgStart[i]] < 46 and SOC[ChgEnd[i]]>85 and min(celltemp) > 10 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])
@@ -106,7 +104,7 @@ def cal_deltsoc(sn, end_time, start_time):
                                 'DVDQ': DVDQ,
                                 'AhSOC': soc1})
 
-        df_Data1 = df_Data1[(df_Data1['SOC'] > 50) & (df_Data1['SOC'] < 75)]
+        df_Data1 = df_Data1[(df_Data1['SOC'] > 50) & (df_Data1['SOC'] < 80)]
         # 寻找峰值点,且峰值点个数>3
         if len(df_Data1['DVDQ'])>2:
             PeakIndex = df_Data1['DVDQ'].idxmax()
@@ -140,12 +138,16 @@ def cal_deltsoc(sn, end_time, start_time):
                     DetaSoc1.append(a)  # 计算到达峰值点的累计Soc
             if DetaSoc1:
                 DetaSoc2.append(max(DetaSoc1) - min(DetaSoc1))
-                DetaSoc_time.append(time[ChgStartValid[i]])
-                DetaSoc_SN.append(SNnum)
+
+        DetaSocMean = np.mean(DetaSoc2)
+        DetaSoc.append(DetaSocMean)
+        DetaSoc_SN.append(SNnum)
+        DetaSoc_time.append(time[ChgStartValid[-1]])
+
 
         result_DetaSoc={'time':DetaSoc_time,
                         'SN号':DetaSoc_SN,
-                        'Soc差':DetaSoc2}
+                        'Soc差':DetaSoc}
         Result_DetaSoc=pd.DataFrame(result_DetaSoc)
         return Result_DetaSoc
     return pd.DataFrame()

+ 160 - 0
LIB/MIDDLE/LeakCurrent/LFPLeakCurrent20210812.py

@@ -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()

+ 23 - 0
LIB/MIDDLE/LeakCurrent/LeakCurrent表头及数据类型.xlsx

@@ -0,0 +1,23 @@
+ąí͡	ĂűłĆ	ĘýžÝŔŕĐÍ
+time	time	timestamps
+SN	sn	str
+cell1	cell1	float64
+cell2	cell2	float64
+cell3	cell3	float64
+cell4	cell4	float64
+cell5	cell5	float64
+cell6	cell6	float64
+cell7	cell7	float64
+cell8	cell8	float64
+cell9	cell9	float64
+cell10	cell10	float64
+cell11	cell11	float64
+cell12	cell12	float64
+cell13	cell13	float64
+cell14	cell14	float64
+cell15	cell15	float64
+cell16	cell16	float64
+cell17	cell17	float64
+cell18	cell18	float64
+cell19	cell19	float64
+cell20	cell20	float64

+ 27 - 0
LIB/MIDDLE/LeakCurrent/main.py

@@ -0,0 +1,27 @@
+#coding=utf-8
+import os
+import datetime
+import pandas as pd
+from LIB.BACKEND import DBManager, Log
+from LIB.MIDDLE import SignalMonitor
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+import time, datetime
+import traceback
+import LFPLeakCurrent20210812 as LFPLeakCurrent
+
+from urllib import parse
+
+dbManager = DBManager.DBManager()
+if __name__ == "__main__":
+    SNdata_6060 = pd.read_excel('骑享资产梳理-20210621.xlsx', sheet_name='6060')
+    SNnums_6060=SNdata_6060['SN号']
+    now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+    now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
+    start_time=now_time-datetime.timedelta(days=31)
+    end_time=str(now_time)
+    start_time=str(start_time)
+
+    for sn in SNnums_6060.tolist():
+        res = LFPLeakCurrent.cal_LFPLeakCurrent(sn, end_time, start_time)
+        res.to_csv('BMS_LeakCurrent_'+sn+'.csv',encoding='GB18030')