def charge_time(self, step = [0,30,60,120,180,240,300,360,420,480,540,600,660,720,780,840,900,1500]): [_, time_d, time_d_c, mode, _, _, _]=self.charge_ana() freq = hist_func_np.hist_con(time_d,step) re1=pd.DataFrame(freq[1]) re1.index=freq[0] re1.columns=['频数'] re2 = hist_func_np.box_hist(time_d,'充电时长[min]') freq = hist_func_np.hist_con(time_d_c,step) re3=pd.DataFrame(freq[1]) re3.index=freq[0] re3.columns=['频数'] re4 = hist_func_np.box_hist(time_d_c,'折算满充时长[min]') [a, b, c] = hist_func_np.hist_con_dis( time_d_c, step, mode,['mode2','mode3_2','mode3_1','DC'],show_hist=1) re5=pd.DataFrame(np.array(b).T) re5.index=a re5.columns=['mode2','mode3_2','mode3_1','DC'] re6=pd.DataFrame(np.array(c).T) re6.index = ['min','1%percentile','25%percentile','50%percentile','75%percentile','99%percentile','max','mean'] re6.columns = ['mode2','mode3_2','mode3_1','DC'] print(re1, re2, re3, re4, re5, re6) return re1, re2, re3, re4, re5, re6
def v_mode(self,step=[0,10,20,30,40,50,60,70,80,90,100,110,120,200],sampling=1/6): sql="SELECT cast(vehiclespeed,'Float32'), operationmode FROM "+ self.tb1 + self.con+ \ " AND cast(vehiclespeed,'Float32')>0 AND toSecond(uploadtime)<"+str(int(sampling*60)) print(sql) aus=pd.DataFrame(client.execute(sql)) v=np.array(aus[0]) mode=np.array(aus[1]) freq = hist_func_np.hist_con(v,step) re1 = pd.DataFrame(freq[1]) re1.index=freq[0] re1.columns=['频数'] re2 = hist_func_np.box_hist(v,'车速[km/h]') if self.pro_typ=="PHEV": [a,b,c] = hist_func_np.hist_con_dis(v,step,mode,['EV','PHEV',"FV"],show_hist=1) re3=pd.DataFrame(np.array(b).T) re3.index=a re3.columns=['EV','PHEV',"FV"] print(re3) re4=pd.DataFrame(np.array(c).T) re4.index=['min','1%percentile','25%percentile','50%percentile','75%percentile','99%percentile','max','mean'] re4.columns=['EV','PHEV',"FV"] print(re4) return re1,re2, re3, re4 else: return re1,re2
def E_motor_workingPoint(self,sampling=1/6): sql="WITH cast(emvolt,'Float32') * cast(emctlcut,'Float32')/1000 as el_pow " \ "SELECT cast(emspeed, 'Float32') as sp, cast(emtq,'Float32') as tq, " \ " multiIf(sp*tq*el_pow==0,0,emstat=='CONSUMING_POWER',sp*tq/9550/el_pow,emstat=='GENERATING_POWER',el_pow/sp/tq*9550,100) " \ " FROM "+self.tb1 + self.con + " AND emstat in ('CONSUMING_POWER','GENERATING_POWER' ) AND toSecond(uploadtime)<"+str(int(sampling*60)) aus=client.execute(sql) speed,torq,eff=[],[],[] for value in aus: if value[0]!=0 and value[1]!=0: speed.append(value[0]) torq.append(value[1]) if value[2]>0 and value[2]<1: eff.append(value[2]*100) l1=len(aus) l2=len(speed) l3=len(eff) print("-------E-Motor Working Point Analysis---------\r\n") print("原始抓取点数:"+str(l1)+"\r\n") print("去除转矩为零或转速为零之后工作点数:"+str(l2)+" 占比:"+str(round(l2/l1*100,2))+"%\r\n") print("效率值在合理范围数:"+str(l3)+" 占比:"+str(round(l3/l2*100,2))+"%\r\n") speed,torq,eff=np.array(speed),np.array(torq),np.array(eff) freq = hist_func_np.hist_con(eff,[0,20,40,50,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100]) re1=pd.DataFrame(freq[1]) re1.index=freq[0] re1.columns=['频数'] re2 = hist_func_np.box_hist(eff,'电机工作效率[%]') [a,b,c] = hist_func_np.hist_cros_2con(speed, range(-4000,13000,500), torq, range(-300,400,50)) re3=pd.DataFrame(c) re3.index=b re3.columns=a re3.to_csv('emotor.csv') re4 = hist_func_np.box_hist(speed,'电机转速[rpm]') re5 = hist_func_np.box_hist(torq,'电机转矩[Nm]') return re1, re2, re3, re4, re5
def charge_soc(self,step=range(0,120,10)): [_, _, _, _,charg_soc, _, _] = self.charge_ana() soc_s = charg_soc[0] soc_e = charg_soc[1] freq = hist_func_np.hist_con(soc_s,step) re1=pd.DataFrame(freq[1]) freq[0][-1]='100' re1.index=freq[0] re1.columns=['频数'] re2 = hist_func_np.box_hist(soc_s,'充电开始SOC[%]') freq = hist_func_np.hist_con(soc_e,step) re3=pd.DataFrame(freq[1]) freq[0][-1]='100' re3.index=freq[0] re3.columns=['频数'] re4 = hist_func_np.box_hist(soc_e,'充电结束SOC[%]') print(re1, re2, re3, re4) return re1, re2, re3, re4
def E_motor_temp(self,step=range(-10,120,5),sampling=1/6): sql="SELECT cast(emctltemp,'Int32'), cast(emtemp,'Int32') FROM "+self.tb1 + self.con + \ " AND emstat in ('CONSUMING_POWER','GENERATING_POWER' ) AND toSecond(uploadtime)<"+str(int(sampling*60)) aus=pd.DataFrame(client.execute(sql)) temp_motor=np.array(aus[1]) temp_LE=np.array(aus[0]) freq = hist_func_np.hist_con(temp_motor,step) re3=pd.DataFrame(freq[1]) re3.index=freq[0] re3.columns=['频数'] re4 = hist_func_np.box_hist(temp_motor,'电机温度[℃]') freq = hist_func_np.hist_con(temp_LE,step) re1=pd.DataFrame(freq[1]) re1.index=freq[0] re1.columns=['频数'] re2 = hist_func_np.box_hist(temp_LE,'LE温度[℃]') return re1,re2,re3,re4
def daily_mileage(self,step=range(0,500,20)): sql="WITH cast(accmiles,'Float32') AS mile " \ "SELECT max(mile)-min(mile) FROM " + self.tb1 + self.con+ \ " GROUP BY deviceid,toDate(uploadtime) " aus=pd.DataFrame(client.execute(sql)) mile=np.array(aus[0]) freq = hist_func_np.hist_con(mile,step) re1=pd.DataFrame(freq[1]) re1.index=freq[0] re1.columns=['频数'] re2 = hist_func_np.box_hist(mile,'每日行驶里程[km]') return re1,re2
def Meb_mileage(date_range): a = date_range[0] + " 00:00:00" b = date_range[1] + " 23:59:59" sql="SELECT deviceid, uploadtime, charg_s_c, socp, d_soc, acc FROM( " \ "SELECT deviceid, uploadtime, runningDifference(charg_s) as charg_s_c, socp, runningDifference(socp) as d_soc, cast(accmiles,'Float32') as acc " \ "FROM ( "\ "SELECT deviceid, uploadtime, if(chargingstatus=='NO_CHARGING',0,1) AS charg_s, " \ "accmiles, if(soc<0,0,soc) AS socp " \ "FROM ods.rtm_details_v2 " \ "WHERE deviceid like 'LSVUB%' AND uploadtime BETWEEN '"+a+"' AND '"+b+"' " \ "ORDER BY deviceid, uploadtime ) ORDER BY deviceid,uploadtime ) " \ "where charg_s_c IN (1,-1) ORDER BY deviceid,uploadtime " aus = client.execute(sql) #aus=[0 vin 1 时间 2充电变化标志位 3 soc 4 d_soc 5 mileage ] df = pd.DataFrame(aus) #df.to_csv('new.csv') all_drive = [] count_1 = 0 #基数多少次行驶前数据丢失 count_2 = 0 #计数行驶后数据丢失 count_12 = 0 #行驶前,行驶后均数据丢失 i = 1 while i < len(aus): if aus[i][0] == aus[i - 1][0] and aus[ i - 1][2] == -1 and aus[i][2] == 1: #i-1时刻是开始行驶,i是结束行驶时刻 start_d_soc = abs(aus[i - 1][4]) end_d_soc = abs(aus[i][4]) if start_d_soc > 5 or end_d_soc > 5: if start_d_soc > 5: count_1 += 1 if end_d_soc > 5: count_2 += 1 if start_d_soc > 5 and end_d_soc > 5: count_12 += 1 elif aus[i - 1][3] > aus[i][3] and aus[ i - 1][5] < aus[i][5]: # 行驶过程中SOC减少,里程增加 all_drive.append([ aus[i][0], aus[i - 1][1], aus[i][1], aus[i - 1][3], aus[i][3], aus[i - 1][5], aus[i][5] ]) #all_drive=[0vin,1time_start,2time_end,3soc_start,4soc_end,5mile_start,6mile_end] i += 2 else: i += 1 l1 = len(all_drive) + count_1 + count_2 - count_12 soc_r = [] mile_r = [] mile_r_c = [] Energy_consump = [] for i, a in enumerate(all_drive): soc_r.append(a[3] - a[4]) mile_r.append(a[6] - a[5]) l2 = len(all_drive) print("------mile perCharging analysis---------\r\n") print("原始行驶次数:" + str(l1) + "\r\n") print("充电前数据丢失次数:" + str(count_1) + "占比:" + str(round(count_1 / l1 * 100, 2)) + "%\r\n") print("充电后数据丢失次数:" + str(count_2) + "占比:" + str(round(count_2 / l1 * 100, 2)) + "%\r\n") print("充电前后数据均丢失次数:" + str(count_12) + "占比:" + str(round(count_12 / l1 * 100, 2)) + "%\r\n") print("处理后行驶次数:" + str(l2) + "\r\n") mile_r = np.array(mile_r) freq = hist_func_np.hist_con(mile_r, range(0, 800, 50)) re1 = pd.DataFrame(freq[1]) re1.index = freq[0] re1.columns = ['频数'] re2 = hist_func_np.box_hist(mile_r, '每次充电间隔里程[km]') charging_energy = 82 #ID4x 82kWh 冲入电量88kWh,来源CLTC充电测试平均值 for a in all_drive: #all_drive=[0vin,1time_start,2time_end,3soc_start,4soc_end,5mile_start,6mile_end] if (a[6] - a[5]) > 10 and (a[3] - a[4]) > 5: Energy_consump.append(charging_energy * (a[3] - a[4]) / (a[6] - a[5])) mile_r_c.append((a[6] - a[5]) / (a[3] - a[4]) * 100) mile_r_c = np.array(mile_r_c) Energy_consump = np.array(Energy_consump) freq = hist_func_np.hist_con(mile_r_c, range(0, 800, 50)) re3 = pd.DataFrame(freq[1]) re3.index = freq[0] re3.columns = ['频数'] re4 = hist_func_np.box_hist(mile_r_c, '折算纯电续驶里程[km]') freq = hist_func_np.hist_con(Energy_consump, [0, 13, 14, 15, 16, 17, 18, 19, 20, 50]) re5 = pd.DataFrame(freq[1]) re5.index = freq[0] re5.columns = ['频数'] re6 = hist_func_np.box_hist(Energy_consump, '折算电耗[kWh/100km]') return re1, re2, re3, re4, re5, re6
def percharge_mile(self, step=range(0,500,20)): sql="SELECT deviceid, uploadtime, charg_s_c, socp, d_soc, acc FROM( " \ "SELECT deviceid, uploadtime, runningDifference(charg_s) as charg_s_c, socp, runningDifference(socp) as d_soc, cast(accmiles,'Float32') as acc " \ "FROM (SELECT deviceid, uploadtime, if(chargingstatus=='NO_CHARGING',0,1) AS charg_s, accmiles, if(soc<0,0,soc) AS socp " \ "FROM " + self.tb1 + self.con+ " ORDER BY deviceid, uploadtime ) ORDER BY deviceid,uploadtime ) " \ "where charg_s_c IN (1,-1) ORDER BY deviceid,uploadtime " aus=client.execute(sql) #aus=[0 vin 1 时间 2充电变化标志位 3 soc 4 d_soc 5 mileage ] df=pd.DataFrame(aus) #df.to_csv('new.csv') all_drive=[] count_1=0#基数多少次行驶前数据丢失 count_2=0#计数行驶后数据丢失 count_12=0#行驶前,行驶后均数据丢失 i=1 while i<len(aus): if aus[i][0]==aus[i-1][0] and aus[i-1][2]==-1 and aus[i][2]==1:#i-1时刻是开始行驶,i是结束行驶时刻 start_d_soc=abs(aus[i-1][4]) end_d_soc=abs(aus[i][4]) if start_d_soc>5 or end_d_soc>5: if start_d_soc>5: count_1+=1 if end_d_soc>5: count_2+=1 if start_d_soc>5 and end_d_soc>5: count_12+=1 elif aus[i-1][3]>aus[i][3] and aus[i-1][5]<aus[i][5]:# 行驶过程中SOC减少,里程增加 all_drive.append([aus[i][0],aus[i-1][1],aus[i][1],aus[i-1][3],aus[i][3],aus[i-1][5],aus[i][5]]) #all_drive=[0vin,1time_start,2time_end,3soc_start,4soc_end,5mile_start,6mile_end] i+=2 else: i+=1 l1=len(all_drive)+count_1+count_2-count_12 soc_r=[] mile_r=[] mile_r_c=[] Energy_consump=[] for i,a in enumerate(all_drive): soc_r.append(a[3]-a[4]) mile_r.append(a[6]-a[5]) l2=len(mile_r_c) print("------mile perCharging analysis---------\r\n") print("原始行驶次数:"+str(l1)+"\r\n") print("充电前数据丢失次数:"+str(count_1)+"占比:"+str(round(count_1/l1*100,2))+"%\r\n") print("充电后数据丢失次数:"+str(count_2)+"占比:"+str(round(count_2/l1*100,2))+"%\r\n") print("充电前后数据均丢失次数:"+str(count_12)+"占比:"+str(round(count_12/l1*100,2))+"%\r\n") print("处理后行驶次数:"+str(l2)+"\r\n") mile_r=np.array(mile_r) freq = hist_func_np.hist_con(mile_r,step) re1=pd.DataFrame(freq[1]) re1.index=freq[0] re1.columns=['频数'] re2 = hist_func_np.box_hist(mile_r,'每次充电间隔里程[km]') if self.pro_typ=='BEV': charging_energy=37 #lavida BEV 实际SOC96~8% 冲入电量37kWh,来源NEDC充电测试平均值 for a in all_drive: if (a[6]-a[5])>10 and (a[3]-a[4])>5: Energy_consump.append(charging_energy*(a[3]-a[4])/(a[6]-a[5])) mile_r_c.append((a[6]-a[5])/(a[3]-a[4])*100) mile_r_c=np.array(mile_r_c) Energy_consump = np.array(Energy_consump) freq = hist_func_np.hist_con(mile_r_c,step) re3 = pd.DataFrame(freq[1]) re3.index = freq[0] re3.columns = ['频数'] re4 = hist_func_np.box_hist(mile_r_c,'折算纯电续驶里程[km]') freq = hist_func_np.hist_con(Energy_consump,np.arange(6,30,0.5)) re5=pd.DataFrame(freq[1]) re5.index=freq[0] re5.columns=['频数'] re6 = hist_func_np.box_hist(Energy_consump,'折算电耗[kWh/100km]') return re1, re2, re3, re4, re5, re6 else: return re1,re2