|
@@ -0,0 +1,426 @@
|
|
|
|
+
|
|
|
|
+import datetime
|
|
|
|
+import pandas as pd
|
|
|
|
+import numpy as np
|
|
|
|
+from DataPreProcess import DataPreProcess
|
|
|
|
+import math
|
|
|
|
+from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import BatParam
|
|
|
|
+import requests
|
|
|
|
+import re
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def process(data_ori_temp,cellvolt_list,celltemp_name,sn):
|
|
|
|
+ data_ori_temp=data_ori_temp.drop(['GSM信号','故障等级','故障代码','开关状态','绝缘电阻','定位类型','速度[km/h]','有效位','外电压','总输出状态','上锁状态','加热状态','航向'],axis=1,errors='ignore')
|
|
|
|
+ if sn[:4]=='MGML':
|
|
|
|
+ for k in range(len(data_ori_temp)):
|
|
|
|
+ if data_ori_temp.loc[k,'经度']==0:
|
|
|
|
+ data_ori_temp.loc[k,'经度']=np.nan
|
|
|
|
+ if data_ori_temp.loc[k,'纬度']==0:
|
|
|
|
+ data_ori_temp.loc[k,'纬度']=np.nan
|
|
|
|
+ data_ori_temp=data_ori_temp.drop(['其他温度2','其他温度6'],axis=1)
|
|
|
|
+ celltemp_name.remove('其他温度2')
|
|
|
|
+ celltemp_name.remove('其他温度6')
|
|
|
|
+ data_ori_temp.fillna(method ='pad', inplace = True , axis = 0)
|
|
|
|
+ data_ori_delnone=data_ori_temp.fillna(method ='backfill', axis = 0)
|
|
|
|
+ if data_ori_delnone.loc[0,'经度'] is None:
|
|
|
|
+ data_ori_delnone['经度']=116.417
|
|
|
|
+ data_ori_delnone['纬度']=39.917
|
|
|
|
+ data_ori_delnone = data_ori_delnone.dropna(axis = 1)
|
|
|
|
+ for name_col in cellvolt_list:
|
|
|
|
+ data_ori_delnone = data_ori_delnone.drop(data_ori_delnone[(data_ori_delnone[name_col] < 2000)].index)
|
|
|
|
+ for name_te in celltemp_name:
|
|
|
|
+ data_ori_delnone = data_ori_delnone.drop(data_ori_delnone[(data_ori_delnone[name_te] < -20)].index)
|
|
|
|
+ df_data=data_ori_delnone.reset_index(drop = True)
|
|
|
|
+ return df_data
|
|
|
|
+
|
|
|
|
+def city(df_sts_chrg,gpscity):
|
|
|
|
+ listcity=[]
|
|
|
|
+ data_sta=df_sts_chrg.reset_index(drop=True)
|
|
|
|
+ for i in range(len(data_sta)):
|
|
|
|
+ dist=[]
|
|
|
|
+ for j in range(len(gpscity)):
|
|
|
|
+ x1=data_sta.loc[i,'经度']
|
|
|
|
+ x2=gpscity.loc[j,'经度']
|
|
|
|
+ y1=data_sta.loc[i,'纬度']
|
|
|
|
+ y2=gpscity.loc[j,'纬度']
|
|
|
|
+ distance=math.sqrt((x1-x2)**2+(y1-y2)**2)
|
|
|
|
+ dist.append(distance)
|
|
|
|
+ jmin=dist.index(np.min(dist))
|
|
|
|
+ city=gpscity.loc[jmin,'城市']
|
|
|
|
+ listcity.append(city)
|
|
|
|
+ data_sta['city']=listcity
|
|
|
|
+ return data_sta
|
|
|
|
+
|
|
|
|
+def gpstemp_new(data_sta):
|
|
|
|
+ headers = {
|
|
|
|
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36',
|
|
|
|
+ }
|
|
|
|
+ if data_sta.loc[0,'city'][:2]=='北京':
|
|
|
|
+ response = requests.get('http://www.weather.com.cn/html/weather/101010100.shtml',headers=headers)
|
|
|
|
+ elif data_sta.loc[0,'city'][:2]=='苏州':
|
|
|
|
+ response = requests.get('http://www.weather.com.cn/html/weather/101190401.shtml',headers=headers)
|
|
|
|
+ response.encoding = response.apparent_encoding
|
|
|
|
+ # 时间,需要反转一下,因为最后一条数据对应第一个
|
|
|
|
+ x_time = re.findall('"od21":"(.*?)"',response.text)
|
|
|
|
+ x_time.reverse()
|
|
|
|
+ # 温度
|
|
|
|
+ temp = re.findall('"od22":"(.*?)"',response.text)
|
|
|
|
+ temp.reverse()
|
|
|
|
+ data_sta['气温']=''
|
|
|
|
+ for i in range(len(data_sta)):
|
|
|
|
+ for time in x_time:
|
|
|
|
+ if str(data_sta.loc[i,'时间戳'])[11:13]==time:
|
|
|
|
+ k=x_time.index(time)
|
|
|
|
+ if temp[k]!='':
|
|
|
|
+ temp0=float(temp[k])
|
|
|
|
+ data_sta.loc[i,'气温']=temp0
|
|
|
|
+ data_sta['气温'].fillna(method='ffill')
|
|
|
|
+ print(data_sta['气温'])
|
|
|
|
+ return data_sta
|
|
|
|
+
|
|
|
|
+def defcelltype(sn):
|
|
|
|
+ if 'PK500' in sn:
|
|
|
|
+ celltype=1 #6040三元电芯
|
|
|
|
+ elif 'PK502' in sn:
|
|
|
|
+ celltype=2 #4840三元电芯
|
|
|
|
+ elif 'K504B' in sn:
|
|
|
|
+ celltype=99 #60ah林磷酸铁锂电芯
|
|
|
|
+ elif 'MGMLXN750' in sn:
|
|
|
|
+ celltype=3 #力信50ah三元电芯
|
|
|
|
+ elif 'MGMCLN750' in sn:
|
|
|
|
+ celltype=4 #CATL 50ah三元电芯
|
|
|
|
+ elif 'UD' in sn:
|
|
|
|
+ celltype=4 #CATL 50ah三元电芯
|
|
|
|
+ elif 'TJMCL' in sn:
|
|
|
|
+ celltype=100 #金茂电芯
|
|
|
|
+ else:
|
|
|
|
+ print('SN:{},未找到对应电池类型!!!'.format(sn))
|
|
|
|
+ return celltype
|
|
|
|
+
|
|
|
|
+def stat_chrg_st(df_splice_data,param):
|
|
|
|
+ cellvolt_list = [s for s in list(df_splice_data) if '单体电压' in s]
|
|
|
|
+ celltemp_name = [s for s in list(df_splice_data) if '温度' in s]
|
|
|
|
+ df_time_temp = pd.to_datetime(df_splice_data['时间戳'])
|
|
|
|
+ delta_time = round((df_time_temp.iloc[-1] - df_time_temp.iloc[0])/pd.Timedelta(1, 'hours'), 3)
|
|
|
|
+ df_soc_temp = df_splice_data['SOC[%]']
|
|
|
|
+ soc_st=df_soc_temp.iloc[0]
|
|
|
|
+ soc_end=df_soc_temp.iloc[-1]
|
|
|
|
+ delta_soc = round((df_soc_temp.iloc[-1] - df_soc_temp.iloc[0]), 3)
|
|
|
|
+ if delta_soc >= 3:
|
|
|
|
+ rate_chrg = round(delta_soc/(100*delta_time), 2) #电流的等效倍率
|
|
|
|
+ else:
|
|
|
|
+ rate_chrg = 0
|
|
|
|
+ if rate_chrg > 0.3:
|
|
|
|
+ stat_flg = 1#快充
|
|
|
|
+ elif rate_chrg > 0:
|
|
|
|
+ stat_flg = 2#慢充
|
|
|
|
+ else:
|
|
|
|
+ stat_flg = 0
|
|
|
|
+ if soc_end > 98:
|
|
|
|
+ full_chg_flg = 1#满充
|
|
|
|
+ else:
|
|
|
|
+ full_chg_flg = 0
|
|
|
|
+ listc=list(df_splice_data['总电流[A]'])
|
|
|
|
+ for k in listc:
|
|
|
|
+ if k>300:
|
|
|
|
+ listc.remove(k)
|
|
|
|
+ max_crnt = np.max(listc) #最大有效电流
|
|
|
|
+ rate_chrg2=round(max_crnt/param.Capacity,2)
|
|
|
|
+ df_volt = df_splice_data['总电压[V]']
|
|
|
|
+ df_volt_end = df_volt.iloc[-1] #截止电压
|
|
|
|
+ df_volt_st = df_volt.iloc[0] #起始电压
|
|
|
|
+ #delta_volt = round((df_volt.iloc[-1] - df_volt.iloc[0]), 3) #压变
|
|
|
|
+ df_diffvolt = df_splice_data['单体压差']
|
|
|
|
+ diffvolt_end = df_diffvolt .iloc[-1] #截止压差
|
|
|
|
+ diffvolt_st = df_diffvolt .iloc[0] #起始压差
|
|
|
|
+ #delta_diffvolt = round((df_diffvolt.iloc[-1] - df_diffvolt.iloc[0]), 3) #压差变化
|
|
|
|
+ df_tem_temp = df_splice_data[celltemp_name]
|
|
|
|
+ df_tem_max = df_tem_temp.max() #每列最大
|
|
|
|
+ df_tem_min = df_tem_temp.min() #每列最小
|
|
|
|
+ df_tem_mean = df_tem_temp.mean() #每列均值
|
|
|
|
+ tem_delt = max(df_tem_max - df_tem_min) #最大温变
|
|
|
|
+ tem_mean=round(np.mean(df_tem_mean),1) #平均温度
|
|
|
|
+ df_tem_max2 = df_tem_temp.max(axis=1) #每行最大
|
|
|
|
+ #temp_st_max=df_tem_max2.iloc[0] #起始最大温度
|
|
|
|
+ #temp_end_max=df_tem_max2.iloc[-1] #结束最大温度
|
|
|
|
+ df_tem_min2 = df_tem_temp.min(axis=1) #每行最小
|
|
|
|
+ #temp_st_min=df_tem_min2.iloc[0] #起始最小温度
|
|
|
|
+ #temp_end_min=df_tem_min2.iloc[-1] #结束最小温度
|
|
|
|
+ df_tem_mean = df_tem_temp.mean(axis=1) #每行平均
|
|
|
|
+ temp_st_mean=df_tem_mean.iloc[0] #起始平均温度
|
|
|
|
+ temp_end_mean=df_tem_mean.iloc[-1] #结束平均温度
|
|
|
|
+ difftem_max = max(df_tem_max2 - df_tem_min2) #最大温差
|
|
|
|
+ df_ovchrg_data = df_splice_data.loc[(df_splice_data['总电流[A]'] >= param.FullChrgSoc) & \
|
|
|
|
+ (df_splice_data['总电压[V]'] >= param.PackFullChrgVolt) & \
|
|
|
|
+ (df_splice_data['SOC[%]'] >= param.FullChrgSoc) & \
|
|
|
|
+ (df_splice_data[cellvolt_list].max(axis = 1) >= 1000*param.CellFullChrgVolt) & \
|
|
|
|
+ (df_splice_data['总电流[A]'] < 0) & (df_splice_data['总电压[V]'] <= param.CellVoltNums*5) & \
|
|
|
|
+ (df_splice_data['SOC[%]'] <= 200)]
|
|
|
|
+ if not df_ovchrg_data.empty:
|
|
|
|
+ ovchrg_flg = 1
|
|
|
|
+ df_ovchrg_data.reset_index(drop = True, inplace = True)
|
|
|
|
+ df_ovchrg_time = df_ovchrg_data['时间戳']
|
|
|
|
+ df_ovchrg_crnt = df_ovchrg_data['总电流[A]']
|
|
|
|
+ np_dff_time = np.diff(df_ovchrg_time)/pd.Timedelta(1, 'hours')
|
|
|
|
+ np_dff_time_new = np.append(np_dff_time, 0)
|
|
|
|
+ np_chrg_ah = np.multiply(np.array(np_dff_time_new),np.array(df_ovchrg_crnt))
|
|
|
|
+ ovchrg_prop = round(100*np_chrg_ah.sum()/param.Capacity, 3)
|
|
|
|
+ else:
|
|
|
|
+ ovchrg_flg = 0
|
|
|
|
+ ovchrg_prop = 0
|
|
|
|
+ df_sts_chrg_temp = pd.DataFrame({"sn":[df_splice_data.loc[0,'sn']], "time_st":[df_time_temp.iloc[0]], "time_end":[df_time_temp.iloc[-1]], "status":[df_splice_data.loc[0,'data_status']],"delta_time":[delta_time],
|
|
|
|
+ "soc_st":[soc_st], "soc_end":[soc_end], "volt_st":df_volt_st,"volt_end":df_volt_end,"diffvolt_st":[diffvolt_st],"diffvolt_end":[diffvolt_end],"temp_max":[max(df_tem_max)],
|
|
|
|
+ "temp_min":[min(df_tem_min)], "temp_incr":[tem_delt],"temp_mean":[tem_mean],"temp_st_mean":[temp_st_mean],"temp_end_mean":[temp_end_mean],"difftem_max":[difftem_max],
|
|
|
|
+ "meancrnt":[rate_chrg], "max_meancrnt":[rate_chrg2],"sts_flg":[stat_flg], "full_chrg_flg":[full_chg_flg],"ovchrg_flg":[ovchrg_flg],"ovchrg_prop":[ovchrg_prop],
|
|
|
|
+ "gps_lon":[round(df_splice_data.loc[0, '经度'], 3)], "gps_lat":[round(df_splice_data.loc[0, '纬度'], 3)],"city":[df_splice_data.loc[0,'city']],"airtemp_st":[df_splice_data.loc[0,'气温']],
|
|
|
|
+ "airtemp_end":[df_splice_data.loc[len(df_splice_data)-1,'气温']]})
|
|
|
|
+ return df_sts_chrg_temp
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def gpstemp(data_sta2,temp):
|
|
|
|
+ data_sta=data_sta2.copy()
|
|
|
|
+ maxtemp1=[]
|
|
|
|
+ mintemp1=[]
|
|
|
|
+ maxtemp2=[]
|
|
|
|
+ mintemp2=[]
|
|
|
|
+ for k in range(len(data_sta)):
|
|
|
|
+ city=data_sta.loc[k,'city']
|
|
|
|
+ date1=str(data_sta.loc[k,'time_st'])[:10]
|
|
|
|
+ date2=str(data_sta.loc[k,'time_end'])[:10]
|
|
|
|
+ for l in range(len(temp)):
|
|
|
|
+ if (date1==temp.loc[l,'日期'][:10]) & (city==temp.loc[l,'城市']):
|
|
|
|
+ t1=float(temp.loc[l,'最高气温'][:-1])
|
|
|
|
+ t2=float(temp.loc[l,'最低气温'][:-1])
|
|
|
|
+ maxtemp1.append(t1)
|
|
|
|
+ mintemp1.append(t2)
|
|
|
|
+ if (date2==temp.loc[l,'日期'][:10]) & (city==temp.loc[l,'城市']):
|
|
|
|
+ t3=float(temp.loc[l,'最高气温'][:-1])
|
|
|
|
+ t4=float(temp.loc[l,'最低气温'][:-1])
|
|
|
|
+ maxtemp2.append(t3)
|
|
|
|
+ mintemp2.append(t4)
|
|
|
|
+
|
|
|
|
+ data_sta['开始最高气温']=maxtemp1
|
|
|
|
+ data_sta['开始最低气温']=mintemp1
|
|
|
|
+ data_sta['结束最高气温']=maxtemp2
|
|
|
|
+ data_sta['结束最低气温']=mintemp2
|
|
|
|
+ return data_sta
|
|
|
|
+
|
|
|
|
+def gpstemp2(data_sta3):
|
|
|
|
+ data_sta=data_sta3.copy()
|
|
|
|
+ temp11=[]
|
|
|
|
+ temp22=[]
|
|
|
|
+ for k in range(len(data_sta)):
|
|
|
|
+ time1=str(data_sta.loc[k,'time_st'])[11:13]
|
|
|
|
+ time2=str(data_sta.loc[k,'time_end'])[11:13]
|
|
|
|
+ if time1 in ['00','01','02','03','04','05']:
|
|
|
|
+ temp11.append(data_sta.loc[k,'开始最低气温'])
|
|
|
|
+ elif time1 in ['06','23','07','22']:
|
|
|
|
+ temp11.append(min(data_sta.loc[k,'开始最低气温']+2,data_sta.loc[k,'开始最高气温']))
|
|
|
|
+ elif time1 in ['08','09','21','20']:
|
|
|
|
+ temp11.append(min(data_sta.loc[k,'开始最低气温']+5,data_sta.loc[k,'开始最高气温']))
|
|
|
|
+ elif time1 in ['10','11','19','18']:
|
|
|
|
+ temp11.append(min(data_sta.loc[k,'开始最低气温']+9,data_sta.loc[k,'开始最高气温']))
|
|
|
|
+ else:
|
|
|
|
+ temp11.append(data_sta.loc[k,'开始最高气温'])
|
|
|
|
+ if time2 in ['00','01','02','03','04','05']:
|
|
|
|
+ temp22.append(data_sta.loc[k,'结束最低气温'])
|
|
|
|
+ elif time2 in ['06','23','07','22']:
|
|
|
|
+ temp22.append(min(data_sta.loc[k,'开始最低气温']+2,data_sta.loc[k,'开始最高气温']))
|
|
|
|
+ elif time2 in ['08','09','21','20']:
|
|
|
|
+ temp22.append(min(data_sta.loc[k,'开始最低气温']+5,data_sta.loc[k,'开始最高气温']))
|
|
|
|
+ elif time2 in ['10','11','19','18']:
|
|
|
|
+ temp22.append(min(data_sta.loc[k,'开始最低气温']+9,data_sta.loc[k,'开始最高气温']))
|
|
|
|
+ else:
|
|
|
|
+ temp22.append(data_sta.loc[k,'开始最高气温'])
|
|
|
|
+ data_sta['airtemp_st']=temp11
|
|
|
|
+ data_sta['airtemp_end']=temp22
|
|
|
|
+ return data_sta
|
|
|
|
+
|
|
|
|
+def newsplit(data_new):
|
|
|
|
+ data_split=pd.DataFrame()
|
|
|
|
+ splice_num = np.unique(data_new['data_split_by_status_time'])
|
|
|
|
+ for item in splice_num:
|
|
|
|
+ df_splice_data = data_new[data_new['data_split_by_status_time'] == item]
|
|
|
|
+ df_splice_data.reset_index(inplace = True, drop = True)
|
|
|
|
+ data_split=data_split.append(df_splice_data.loc[[0,len(df_splice_data)-1],:])
|
|
|
|
+ data_split=data_split.reset_index(drop = True)
|
|
|
|
+ data_split2=data_split.copy()
|
|
|
|
+ for k in range(1,len(data_split)):
|
|
|
|
+ if (data_split.loc[k,'data_split_by_status_time']==data_split.loc[k-1,'data_split_by_status_time']) & \
|
|
|
|
+ (data_split.loc[k,'data_status']=='charge') & \
|
|
|
|
+ (data_split.loc[k,'SOC[%]']==data_split.loc[k-1,'SOC[%]']):
|
|
|
|
+ data_split2=data_split2.drop([k-1,k])
|
|
|
|
+ if (data_split.loc[k,'data_split_by_status_time']==data_split.loc[k-1,'data_split_by_status_time']) & \
|
|
|
|
+ (data_split.loc[k,'data_status']=='drive') & \
|
|
|
|
+ (round(data_split.loc[k,'纬度'],2)==round(data_split.loc[k-1,'纬度'],2)) & \
|
|
|
|
+ (round(data_split.loc[k,'经度'],2)==round(data_split.loc[k-1,'经度'],2)) :
|
|
|
|
+ data_split2=data_split2.drop([k-1,k])
|
|
|
|
+ data_split2=data_split2.reset_index(drop = True)
|
|
|
|
+ data_split3=data_split2.copy()
|
|
|
|
+ for k in range(1,len(data_split2)):
|
|
|
|
+ if (data_split2.loc[k,'data_split_by_status_time']!=data_split2.loc[k-1,'data_split_by_status_time']) & \
|
|
|
|
+ (data_split2.loc[k,'data_status']==data_split2.loc[k-1,'data_status']) & \
|
|
|
|
+ ((data_split2.loc[k,'时间戳']-data_split2.loc[k-1,'时间戳']).total_seconds()/60<10):
|
|
|
|
+ data_split3.loc[k+1,'data_split_by_status_time']=data_split3.loc[k-1,'data_split_by_status_time']
|
|
|
|
+ data_split3=data_split3.drop([k-1,k])
|
|
|
|
+ data_split3=data_split3.reset_index(drop = True)
|
|
|
|
+ return data_split3
|
|
|
|
+
|
|
|
|
+def chrgst_time(data_split):
|
|
|
|
+ for k in range(1,len(data_split)):
|
|
|
|
+ if (data_split.loc[k,'data_status']=='charge') & (data_split.loc[k-1,'data_status']=='stand'):
|
|
|
|
+ delta_time_f=(data_split.loc[k-1,'时间戳']-data_split.loc[k-2,'时间戳']).total_seconds()/60
|
|
|
|
+ data_split.loc[k,'stand_time']=delta_time_f
|
|
|
|
+ if (data_split.loc[k,'data_status']=='charge') & (data_split.loc[k-1,'data_status']=='drive'):
|
|
|
|
+ delta_time_f=0
|
|
|
|
+ data_split.loc[k,'stand_time']=delta_time_f
|
|
|
|
+ if (data_split.loc[k,'data_status']=='stand') & (data_split.loc[k-1,'data_status']=='charge'):
|
|
|
|
+ delta_time_b=(data_split.loc[k+1,'时间戳']-data_split.loc[k,'时间戳']).total_seconds()/60
|
|
|
|
+ data_split.loc[k-1,'stand_time']=delta_time_b
|
|
|
|
+ if (data_split.loc[k,'data_status']=='drive') & (data_split.loc[k-1,'data_status']=='charge'):
|
|
|
|
+ delta_time_b=0
|
|
|
|
+ data_split.loc[k-1,'stand_time']=delta_time_b
|
|
|
|
+ return data_split
|
|
|
|
+
|
|
|
|
+def chrgdr(data_split):
|
|
|
|
+ chrg=pd.DataFrame()
|
|
|
|
+ dr=pd.DataFrame()
|
|
|
|
+ if len(data_split)>3:
|
|
|
|
+ if (data_split.loc[0,'data_status']=='charge') & (data_split.loc[2,'data_status']=='stand'):
|
|
|
|
+ chrg=chrg.append(data_split.iloc[:4])
|
|
|
|
+ elif (data_split.loc[0,'data_status']=='charge') & (data_split.loc[2,'data_status']=='drive'):
|
|
|
|
+ chrg=chrg.append(data_split.iloc[:2])
|
|
|
|
+
|
|
|
|
+ if (data_split.loc[len(data_split)-2,'data_status']=='charge') & (data_split.loc[len(data_split)-3,'data_status']=='stand'):
|
|
|
|
+ chrg=chrg.append(data_split.iloc[len(data_split)-4:])
|
|
|
|
+ elif (data_split.loc[len(data_split)-2,'data_status']=='charge') & (data_split.loc[len(data_split)-3,'data_status']=='drive'):
|
|
|
|
+ chrg=chrg.append(data_split.iloc[len(data_split)-2:])
|
|
|
|
+
|
|
|
|
+ if len(data_split)>5:
|
|
|
|
+ for k in range(2,len(data_split)-2):
|
|
|
|
+ if (data_split.loc[k,'data_status']=='charge') & (data_split.loc[k-1,'data_status']=='stand') & (data_split.loc[k+2,'data_status']=='stand'):
|
|
|
|
+ chrg=chrg.append(data_split.iloc[k-2:k+4])
|
|
|
|
+ elif (data_split.loc[k,'data_status']=='charge') & (data_split.loc[k-1,'data_status']=='drive') & (data_split.loc[k+2,'data_status']=='stand'):
|
|
|
|
+ chrg=chrg.append(data_split.iloc[k:k+4])
|
|
|
|
+ elif (data_split.loc[k,'data_status']=='charge') & (data_split.loc[k-1,'data_status']=='drive') & (data_split.loc[k+2,'data_status']=='drive'):
|
|
|
|
+ chrg=chrg.append(data_split.iloc[k:k+2])
|
|
|
|
+ elif (data_split.loc[k,'data_status']=='charge') & (data_split.loc[k-1,'data_status']=='stand') & (data_split.loc[k+2,'data_status']=='drive'):
|
|
|
|
+ chrg=chrg.append(data_split.iloc[k-2:k+2])
|
|
|
|
+ else:
|
|
|
|
+ if data_split.loc[0,'data_status'] in ['charge','stand']:
|
|
|
|
+ chrg=chrg.append(data_split.iloc[:2])
|
|
|
|
+
|
|
|
|
+ return chrg
|
|
|
|
+
|
|
|
|
+def makedf_chrgdr(df_splice_chrg,data_new):
|
|
|
|
+ time1=df_splice_chrg.loc[0,'时间戳']
|
|
|
|
+ time2=df_splice_chrg.loc[1,'时间戳']
|
|
|
|
+ status=df_splice_chrg.loc[0,'data_status']
|
|
|
|
+ split=df_splice_chrg.loc[0,'data_split_by_status_time']
|
|
|
|
+ index1=data_new[(data_new['时间戳']==time1) & (data_new['data_status']==status)].index.tolist()[0]
|
|
|
|
+ index2=data_new[(data_new['时间戳']==time2) & (data_new['data_status']==status)].index.tolist()[-1]
|
|
|
|
+ df_chrg=data_new.iloc[index1:index2+1]
|
|
|
|
+ df_chrg['data_split_by_status_time']=split
|
|
|
|
+ df_chrg.reset_index(drop=True,inplace=True)
|
|
|
|
+ return df_chrg
|
|
|
|
+
|
|
|
|
+def change_new(df_sts_chrg,chrg_last):
|
|
|
|
+ time_last=chrg_last['time_end']
|
|
|
|
+ time_first=df_sts_chrg.loc[0,'time_st']
|
|
|
|
+ time_last=datetime.datetime.strptime(time_last,'%Y-%m-%d %H:%M:%S')
|
|
|
|
+ if (chrg_last['status']==df_sts_chrg.loc[0,'status']) & ((time_first-time_last).total_seconds()/60<10) & \
|
|
|
|
+ (round(chrg_last['gps_lat'],2)==round(df_sts_chrg.loc[0,'gps_lat'],2)) & \
|
|
|
|
+ (round(chrg_last['gps_lon'],2)==round(df_sts_chrg.loc[0,'gps_lon'],2)) :
|
|
|
|
+ chrg_last['time_end']=df_sts_chrg.loc[0,'time_end']
|
|
|
|
+ chrg_last['delta_time']=chrg_last['delta_time']+df_sts_chrg.loc[0,'delta_time']
|
|
|
|
+ chrg_last['soc_end']=df_sts_chrg.loc[0,'soc_end']
|
|
|
|
+ chrg_last['volt_end']=df_sts_chrg.loc[0,'volt_end']
|
|
|
|
+ chrg_last['diffvolt_end']=df_sts_chrg.loc[0,'diffvolt_end']
|
|
|
|
+ chrg_last['temp_max']=np.max([df_sts_chrg.loc[0,'temp_max'],chrg_last['temp_max']])
|
|
|
|
+ chrg_last['temp_min']=np.min([df_sts_chrg.loc[0,'temp_min'],chrg_last['temp_min']])
|
|
|
|
+ chrg_last['temp_incr']=df_sts_chrg.loc[0,'temp_incr']+chrg_last['temp_incr']
|
|
|
|
+ chrg_last['temp_mean']=round(np.mean([df_sts_chrg.loc[0,'temp_mean'],chrg_last['temp_mean']]),1)
|
|
|
|
+ #chrg_last['temp_end_max']=df_sts_chrg.loc[0,'temp_end_max']
|
|
|
|
+ #chrg_last['temp_end_min']=df_sts_chrg.loc[0,'temp_end_min']
|
|
|
|
+ chrg_last['temp_end_mean']=df_sts_chrg.loc[0,'temp_end_mean']
|
|
|
|
+ chrg_last['difftem_max']=np.max([df_sts_chrg.loc[0,'difftem_max'],chrg_last['difftem_max']])
|
|
|
|
+ delta_soc=chrg_last['soc_end']-chrg_last['soc_st']
|
|
|
|
+ if delta_soc >= 3:
|
|
|
|
+ rate_chrg =round(delta_soc/(100*chrg_last['delta_time']), 2) #电流的等效倍率
|
|
|
|
+ else:
|
|
|
|
+ rate_chrg = 0
|
|
|
|
+ if rate_chrg > 0.3:
|
|
|
|
+ stat_flg = 1#快充
|
|
|
|
+ elif rate_chrg > 0:
|
|
|
|
+ stat_flg = 2#慢充
|
|
|
|
+ else:
|
|
|
|
+ stat_flg = 0
|
|
|
|
+ if chrg_last['soc_end'] > 98:
|
|
|
|
+ full_chg_flg = 1#满充
|
|
|
|
+ else:
|
|
|
|
+ full_chg_flg = 0
|
|
|
|
+ chrg_last['meancrnt']= rate_chrg
|
|
|
|
+ chrg_last['max_meancrnt']=np.max([df_sts_chrg.loc[0,'max_meancrnt'],chrg_last['max_meancrnt']])
|
|
|
|
+ chrg_last['sts_flg']= stat_flg
|
|
|
|
+ chrg_last['full_chrg_flg']= full_chg_flg
|
|
|
|
+ chrg_last['ovchrg_flg']= np.max([df_sts_chrg.loc[0,'ovchrg_flg'],chrg_last['ovchrg_flg']])
|
|
|
|
+ chrg_last['ovchrg_prop']=df_sts_chrg.loc[0,'ovchrg_prop']+chrg_last['ovchrg_prop']
|
|
|
|
+ chrg_last['standtime_b']=df_sts_chrg.loc[0,'standtime_b']
|
|
|
|
+ chrg_last['airtemp_end']=df_sts_chrg.loc[0,'airtemp_end']
|
|
|
|
+ chrg_last=pd.DataFrame(chrg_last).T
|
|
|
|
+ df_sts_chrg=df_sts_chrg.drop([0])
|
|
|
|
+
|
|
|
|
+ else:
|
|
|
|
+ chrg_last=pd.DataFrame()
|
|
|
|
+ return df_sts_chrg,chrg_last
|
|
|
|
+
|
|
|
|
+def sep_chrg_dr(df_merge,sn):
|
|
|
|
+ cellvolt_list = [s for s in list(df_merge) if '单体电压' in s]
|
|
|
|
+ celltemp_name = [s for s in list(df_merge) if '温度' in s]
|
|
|
|
+ df_data=process(df_merge,cellvolt_list,celltemp_name,sn)
|
|
|
|
+ celltype=defcelltype(sn)
|
|
|
|
+ param=BatParam.BatParam(celltype)
|
|
|
|
+ df_data['总电流[A]']=param.PackCrntDec*df_data['总电流[A]']
|
|
|
|
+ data_new=DataPreProcess.data_split_by_status(df_data,df_data)
|
|
|
|
+ data_new=DataPreProcess.data_split_by_time(data_new,data_new)
|
|
|
|
+ data_new=DataPreProcess.cal_stand_time(data_new,data_new)
|
|
|
|
+ data_new.reset_index(inplace = True, drop = True)
|
|
|
|
+ data_split=newsplit(data_new)
|
|
|
|
+ data_split=chrgst_time(data_split)
|
|
|
|
+ chrg=chrgdr(data_split)
|
|
|
|
+ return chrg,data_new,param
|
|
|
|
+
|
|
|
|
+def mkdf_chrg(chrg,data_new,param,gpscity):
|
|
|
|
+ splice_num= np.unique(chrg['data_split_by_status_time'])
|
|
|
|
+ df_sts_chrg=pd.DataFrame()
|
|
|
|
+ for item in splice_num:
|
|
|
|
+ df_splice_chrg = chrg[chrg['data_split_by_status_time'] == item]
|
|
|
|
+ df_splice_chrg.reset_index(inplace = True, drop = True)
|
|
|
|
+ df_chrg=makedf_chrgdr(df_splice_chrg,data_new)
|
|
|
|
+ data_sta=city(df_chrg,gpscity)
|
|
|
|
+ data_sta=data_sta.reset_index(drop=True)
|
|
|
|
+ data_sta2=gpstemp_new(data_sta)
|
|
|
|
+ df_sts_chrg_temp=stat_chrg_st(data_sta2,param)
|
|
|
|
+ if df_splice_chrg.loc[0,'data_status'] =='charge':
|
|
|
|
+ stand_dur_f=df_splice_chrg.loc[0,'stand_time']
|
|
|
|
+ stand_dur_b=df_splice_chrg.loc[1,'stand_time']
|
|
|
|
+ else:
|
|
|
|
+ stand_dur_f=0
|
|
|
|
+ stand_dur_b=0
|
|
|
|
+ df_sts_chrg_temp['standtime_f']=round(stand_dur_f,3)
|
|
|
|
+ df_sts_chrg_temp['standtime_b']=round(stand_dur_b,3)
|
|
|
|
+ df_sts_chrg=df_sts_chrg.append(df_sts_chrg_temp)
|
|
|
|
+ return df_sts_chrg
|
|
|
|
+
|
|
|
|
+def pro_output(df_merge,sn,gpscity,chrg_last):
|
|
|
|
+ new=pd.DataFrame()
|
|
|
|
+ change=pd.DataFrame()
|
|
|
|
+ if len(df_merge)>0:
|
|
|
|
+ chrg,data_new,param=sep_chrg_dr(df_merge,sn)
|
|
|
|
+ if len(chrg)>0:
|
|
|
|
+ data_sta=mkdf_chrg(chrg,data_new,param,gpscity)
|
|
|
|
+ new=data_sta.copy()
|
|
|
|
+ if len(chrg_last)>0:
|
|
|
|
+ new,change=change_new(data_sta,chrg_last)
|
|
|
|
+ return new,change
|