|
@@ -73,9 +73,12 @@ def gpstemp_new(data_sta):
|
|
|
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['气温'])
|
|
|
+ data_sta.loc[i,'气温']=temp0
|
|
|
+ else:
|
|
|
+ if k>0:
|
|
|
+ data_sta.loc[i,'气温']=data_sta.loc[i-1,'气温']
|
|
|
+ else:
|
|
|
+ data_sta.loc[i,'气温']=data_sta.loc[i+1,'气温']
|
|
|
return data_sta
|
|
|
|
|
|
def defcelltype(sn):
|
|
@@ -237,7 +240,7 @@ def gpstemp2(data_sta3):
|
|
|
data_sta['airtemp_end']=temp22
|
|
|
return data_sta
|
|
|
|
|
|
-def newsplit(data_new):
|
|
|
+def newsplit(data_new): #重新分段:根据时间差和经纬度
|
|
|
data_split=pd.DataFrame()
|
|
|
splice_num = np.unique(data_new['data_split_by_status_time'])
|
|
|
for item in splice_num:
|
|
@@ -267,7 +270,7 @@ def newsplit(data_new):
|
|
|
data_split3=data_split3.reset_index(drop = True)
|
|
|
return data_split3
|
|
|
|
|
|
-def chrgst_time(data_split):
|
|
|
+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
|
|
@@ -283,9 +286,8 @@ def chrgst_time(data_split):
|
|
|
data_split.loc[k-1,'stand_time']=delta_time_b
|
|
|
return data_split
|
|
|
|
|
|
-def chrgdr(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])
|
|
@@ -313,7 +315,7 @@ def chrgdr(data_split):
|
|
|
|
|
|
return chrg
|
|
|
|
|
|
-def makedf_chrgdr(df_splice_chrg,data_new):
|
|
|
+def makedf_chrgdr(df_splice_chrg,data_new): #每个status取所有时间戳的数据
|
|
|
time1=df_splice_chrg.loc[0,'时间戳']
|
|
|
time2=df_splice_chrg.loc[1,'时间戳']
|
|
|
status=df_splice_chrg.loc[0,'data_status']
|
|
@@ -326,6 +328,7 @@ def makedf_chrgdr(df_splice_chrg,data_new):
|
|
|
return df_chrg
|
|
|
|
|
|
def change_new(df_sts_chrg,chrg_last):
|
|
|
+ df_sts_chrg.reset_index(drop=True,inplace=True)
|
|
|
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')
|
|
@@ -375,7 +378,7 @@ def change_new(df_sts_chrg,chrg_last):
|
|
|
chrg_last=pd.DataFrame()
|
|
|
return df_sts_chrg,chrg_last
|
|
|
|
|
|
-def sep_chrg_dr(df_merge,sn):
|
|
|
+def sep_chrg_dr(df_merge,sn,gpscity):
|
|
|
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)
|
|
@@ -386,22 +389,24 @@ def sep_chrg_dr(df_merge,sn):
|
|
|
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_sta=city(data_new,gpscity)
|
|
|
+ data_sta=data_sta.reset_index(drop=True)
|
|
|
+ data_sta2=gpstemp_new(data_sta)
|
|
|
+ data_split=newsplit(data_sta2)
|
|
|
data_split=chrgst_time(data_split)
|
|
|
chrg=chrgdr(data_split)
|
|
|
- return chrg,data_new,param
|
|
|
+ return chrg,data_sta2,param
|
|
|
|
|
|
-def mkdf_chrg(chrg,data_new,param,gpscity):
|
|
|
+def mkdf_chrg(chrg,data_new,param):
|
|
|
splice_num= np.unique(chrg['data_split_by_status_time'])
|
|
|
- df_sts_chrg=pd.DataFrame()
|
|
|
+ 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)
|
|
|
+
|
|
|
+ df_sts_chrg_temp=stat_chrg_st(df_chrg,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']
|
|
@@ -417,9 +422,10 @@ 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)
|
|
|
+ chrg,data_new,param=sep_chrg_dr(df_merge,sn,gpscity)
|
|
|
if len(chrg)>0:
|
|
|
- data_sta=mkdf_chrg(chrg,data_new,param,gpscity)
|
|
|
+ data_sta=mkdf_chrg(chrg,data_new,param)
|
|
|
+ data_sta.to_csv('data_sta.csv')
|
|
|
new=data_sta.copy()
|
|
|
if len(chrg_last)>0:
|
|
|
new,change=change_new(data_sta,chrg_last)
|