|
@@ -224,6 +224,25 @@ class DBManager():
|
|
|
columns=['时间戳','累计充电电量','累计充电能量','累计放电电量','累计放电能量', '累积里程'],data=data_block)
|
|
|
return df
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def _convert_to_dataframe_storage_accum(data, mode=0):
|
|
|
+ if mode == 0:
|
|
|
+
|
|
|
+ data_block = np.array([data['info'].get('obdTime',None),data['ffEnergyStoreStat'].get('usedEnergy',None), data['ffEnergyStoreStat'].get('inputEnergy',None),
|
|
|
+ data['ffEnergyStoreStat'].get('outputEnergy',None), data['ffEnergyStoreStat'].get('usedEnergy2',None), data['ffEnergyStoreStat'].get('inputEnergy2',None),
|
|
|
+ data['ffEnergyStoreStat'].get('outputEnergy2',None)]).reshape(1,7)
|
|
|
+ df = pd.DataFrame(
|
|
|
+ columns=['时间戳','累计用电kWh数1', '累计正向输入kWh1','累计反向输出kWh数1',
|
|
|
+ '累计用电kWh数2', '累计正向输入kWh2','累计反向输出kWh数2'],data=data_block)
|
|
|
+
|
|
|
+ if mode == 1:
|
|
|
+ data_block = np.array([data['info'].get('obdTime',None),data['ffEnergyStoreStat'].get('usedEnergy',None), data['ffEnergyStoreStat'].get('inputEnergy',None),
|
|
|
+ data['ffEnergyStoreStat'].get('outputEnergy',None), data['ffEnergyStoreStat'].get('usedEnergy2',None), data['ffEnergyStoreStat'].get('inputEnergy2',None),
|
|
|
+ data['ffEnergyStoreStat'].get('outputEnergy2',None)]).reshape(1,7)
|
|
|
+ df = pd.DataFrame(
|
|
|
+ columns=['时间戳','累计用电kWh数1', '累计正向输入kWh1','累计反向输出kWh数1',
|
|
|
+ '累计用电kWh数2', '累计正向输入kWh2','累计反向输出kWh数2'],data=data_block)
|
|
|
+ return df
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
@@ -337,8 +356,7 @@ class DBManager():
|
|
|
df_all = df_all.append(df_add,ignore_index=True)
|
|
|
if not df_all.empty:
|
|
|
df_all.loc[:,'时间戳'] = df_all.loc[:,'时间戳'].apply(lambda x:time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(int(x)/1000)))
|
|
|
- return df_all
|
|
|
-
|
|
|
+ return df_all
|
|
|
elif type_name =='accum':
|
|
|
if mode == 0:
|
|
|
df_all = pd.DataFrame(columns=['时间戳','SOH未标定时间', '累计充电电量','累计充电能量','累计放电电量','累计放电能量',
|
|
@@ -351,6 +369,18 @@ class DBManager():
|
|
|
if not df_all.empty:
|
|
|
df_all.loc[:,'时间戳'] = df_all.loc[:,'时间戳'].apply(lambda x:time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(int(x)/1000)))
|
|
|
return df_all
|
|
|
+ elif type_name =='storage_accum':
|
|
|
+ if mode == 0:
|
|
|
+ df_all = pd.DataFrame(columns=['时间戳','累计用电kWh数1', '累计正向输入kWh1','累计反向输出kWh数1',
|
|
|
+ '累计用电kWh数2', '累计正向输入kWh2','累计反向输出kWh数2'])
|
|
|
+ elif mode == 1:
|
|
|
+ df_all = pd.DataFrame()
|
|
|
+ for line in data:
|
|
|
+ df_add = DBManager._convert_to_dataframe_storage_accum(line, mode)
|
|
|
+ df_all = df_all.append(df_add,ignore_index=True)
|
|
|
+ if not df_all.empty:
|
|
|
+ df_all.loc[:,'时间戳'] = df_all.loc[:,'时间戳'].apply(lambda x:time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(int(x)/1000)))
|
|
|
+ return df_all
|
|
|
def get_data(self, url='http://172.16.126.13/store/load?dataType={}&limit=0&sn={}', sn='', start_time='', end_time='',
|
|
|
data_groups=['bms', 'gps']):
|
|
|
'''
|
|
@@ -373,7 +403,7 @@ class DBManager():
|
|
|
df_data: {'bms':dataframe, 'gps':dataframe, 'system':dataframe, ;accum':dataframe}
|
|
|
'''
|
|
|
|
|
|
- if len(set(data_groups) - (set(data_groups) and set(['bms', 'gps', 'system', 'accum']))) > 0:
|
|
|
+ if len(set(data_groups) - (set(data_groups) and set(['bms', 'gps', 'system', 'accum', 'storage_accum']))) > 0:
|
|
|
raise Exception("data_groups 参数错误")
|
|
|
|
|
|
|
|
@@ -386,6 +416,7 @@ class DBManager():
|
|
|
gps_all_data = pd.DataFrame()
|
|
|
system_all_data = pd.DataFrame()
|
|
|
accum_all_data = pd.DataFrame()
|
|
|
+ storage_accum_all_data = pd.DataFrame()
|
|
|
maxnum = (datetime.datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S") - datetime.datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S")).days +1
|
|
|
print("### start to get data {} from {} to {}".format(sn, start_time, end_time))
|
|
|
# 为避免chunkEncodingError错误,数据每天获取一次,然后将每天的数据合并,得到最终的数据
|
|
@@ -402,6 +433,7 @@ class DBManager():
|
|
|
gps_data = pd.DataFrame()
|
|
|
system_data = pd.DataFrame()
|
|
|
accum_data = pd.DataFrame()
|
|
|
+ storage_accum_all_data = pd.DataFrame()
|
|
|
while True:
|
|
|
try:
|
|
|
print('\r' + "# get data from {} to {}.........".format(str(timefrom), str(timeto)), end=" ")
|
|
@@ -418,6 +450,9 @@ class DBManager():
|
|
|
if data_group == 'accum':
|
|
|
file_url = url.format(23, sn) + "&from="+timefrom.strftime('%Y-%m-%d %H:%M:%S')+"&to="+timeto.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
accum_data = DBManager._get_data(file_url,'accum',mode)
|
|
|
+ if data_group == 'storage_accum':
|
|
|
+ file_url = url.format(29, sn) + "&from="+timefrom.strftime('%Y-%m-%d %H:%M:%S')+"&to="+timeto.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
+ storage_accum_data = DBManager._get_data(file_url,'storage_accum',mode)
|
|
|
except Exception as e:
|
|
|
if 'Connection broken' in str(e):
|
|
|
continue
|
|
@@ -430,13 +465,15 @@ class DBManager():
|
|
|
gps_all_data = pd.concat([gps_all_data, gps_data], ignore_index=True)
|
|
|
system_all_data = pd.concat([system_all_data, system_data], ignore_index=True)
|
|
|
accum_all_data = pd.concat([accum_all_data, accum_data], ignore_index=True)
|
|
|
+ storage_accum_all_data = pd.concat([storage_accum_all_data, storage_accum_data], ignore_index=True)
|
|
|
break
|
|
|
|
|
|
bms_all_data = bms_all_data.reset_index(drop=True)
|
|
|
gps_all_data = gps_all_data.reset_index(drop=True)
|
|
|
system_all_data = system_all_data.reset_index(drop=True)
|
|
|
accum_all_data = accum_all_data.reset_index(drop=True)
|
|
|
- print('\nall data-getting done, bms_count is {}, gps_count is {}, system_count is {}, accum_count is {} \n'.format(
|
|
|
- str(len(bms_all_data)), str(len(gps_all_data)), str(len(system_all_data)), str(len(accum_all_data))))
|
|
|
- return {'bms':bms_all_data, 'gps':gps_all_data, 'system':system_all_data, 'accum':accum_all_data}
|
|
|
+ storage_accum_all_data = storage_accum_all_data.reset_index(drop=True)
|
|
|
+ print('\nall data-getting done, bms_count is {}, gps_count is {}, system_count is {}, accum_count is {} ,storage_accum_count is {}\n'.format(
|
|
|
+ str(len(bms_all_data)), str(len(gps_all_data)), str(len(system_all_data)), str(len(accum_all_data)), str(len(storage_accum_all_data))))
|
|
|
+ return {'bms':bms_all_data, 'gps':gps_all_data, 'system':system_all_data, 'accum':accum_all_data,'storage_accum':storage_accum_all_data}
|
|
|
|