|
@@ -14,6 +14,8 @@ import json
|
|
import requests
|
|
import requests
|
|
import pymysql
|
|
import pymysql
|
|
import pdb
|
|
import pdb
|
|
|
|
+from collections import Counter
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
class DBManager():
|
|
class DBManager():
|
|
@@ -80,18 +82,17 @@ class DBManager():
|
|
'''
|
|
'''
|
|
返回json数据的生成器,一次一行
|
|
返回json数据的生成器,一次一行
|
|
'''
|
|
'''
|
|
-
|
|
|
|
i = 0
|
|
i = 0
|
|
while 1:
|
|
while 1:
|
|
try:
|
|
try:
|
|
r = requests.get(url, stream=True, timeout=(0.1, 1000), headers={'Connection':'keep-alive', 'Accept':'*/*', 'Accept-Encoding':'gzip,deflate,br'})
|
|
r = requests.get(url, stream=True, timeout=(0.1, 1000), headers={'Connection':'keep-alive', 'Accept':'*/*', 'Accept-Encoding':'gzip,deflate,br'})
|
|
break
|
|
break
|
|
except requests.exceptions.RequestException as e:
|
|
except requests.exceptions.RequestException as e:
|
|
- if (i == 0):
|
|
|
|
- print()
|
|
|
|
- print('\r' + 'Server Error, retry {}......'.format(str(i)), end=" ")
|
|
|
|
|
|
+ # if (i == 0):
|
|
|
|
+ # print()
|
|
|
|
+ # print('\r' + 'Server Error, retry {}......'.format(str(i)), end=" ")
|
|
time.sleep(0.1)
|
|
time.sleep(0.1)
|
|
- i+=1
|
|
|
|
|
|
+ i+=1
|
|
# print(r.content)
|
|
# print(r.content)
|
|
# pdb.set_trace()
|
|
# pdb.set_trace()
|
|
data = []
|
|
data = []
|
|
@@ -241,16 +242,33 @@ class DBManager():
|
|
CellUNum = 0
|
|
CellUNum = 0
|
|
CellTNum = 0
|
|
CellTNum = 0
|
|
OtherTNum = 0
|
|
OtherTNum = 0
|
|
|
|
+
|
|
|
|
+ cellUNumList = []
|
|
|
|
+ cellTNumList = []
|
|
|
|
+ otherTNumList = []
|
|
|
|
+
|
|
for line in data:
|
|
for line in data:
|
|
temp = len(line['ffBatteryStatus'].get('cellVoltageList', []))
|
|
temp = len(line['ffBatteryStatus'].get('cellVoltageList', []))
|
|
- if (temp > CellUNum):
|
|
|
|
- CellUNum = temp
|
|
|
|
|
|
+ cellUNumList.append(temp)
|
|
|
|
+ # if (temp > CellUNum):
|
|
|
|
+ # CellUNum = temp
|
|
temp = len(line['ffBatteryStatus'].get('cellTempList', []))
|
|
temp = len(line['ffBatteryStatus'].get('cellTempList', []))
|
|
- if (temp > CellTNum):
|
|
|
|
- CellTNum = temp
|
|
|
|
|
|
+ cellTNumList.append(temp)
|
|
|
|
+ # if (temp > CellTNum):
|
|
|
|
+ # CellTNum = temp
|
|
temp = len(line['ffBatteryStatus'].get('otherTempList', []))
|
|
temp = len(line['ffBatteryStatus'].get('otherTempList', []))
|
|
- if (temp > OtherTNum):
|
|
|
|
- OtherTNum = temp
|
|
|
|
|
|
+ otherTNumList.append(temp)
|
|
|
|
+ # if (temp > OtherTNum):
|
|
|
|
+ # OtherTNum = temp
|
|
|
|
+ result = Counter(cellUNumList)
|
|
|
|
+ CellUNum = max(result, key=result.get)
|
|
|
|
+
|
|
|
|
+ result = Counter(cellTNumList)
|
|
|
|
+ CellTNum = max(result, key=result.get)
|
|
|
|
+
|
|
|
|
+ result = Counter(otherTNumList)
|
|
|
|
+ OtherTNum = max(result, key=result.get)
|
|
|
|
+
|
|
data_blocks = pd.DataFrame()
|
|
data_blocks = pd.DataFrame()
|
|
for line in data:
|
|
for line in data:
|
|
et = time.time()
|
|
et = time.time()
|
|
@@ -261,11 +279,13 @@ class DBManager():
|
|
i+=1
|
|
i+=1
|
|
continue
|
|
continue
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
|
+ # print(e)
|
|
continue
|
|
continue
|
|
|
|
|
|
try:
|
|
try:
|
|
data_block = DBManager._convert_to_dataframe_bms(line, mode, CellUNum, CellTNum, OtherTNum)
|
|
data_block = DBManager._convert_to_dataframe_bms(line, mode, CellUNum, CellTNum, OtherTNum)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
|
+ # print(e)
|
|
continue
|
|
continue
|
|
|
|
|
|
try:
|
|
try:
|
|
@@ -328,7 +348,7 @@ class DBManager():
|
|
if not df_all.empty:
|
|
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)))
|
|
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
|
|
- def get_data(self, url='http://172.16.121.236/store/load?dataType={}&limit=0&sn={}', sn='', start_time='', end_time='',
|
|
|
|
|
|
+ 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']):
|
|
data_groups=['bms', 'gps']):
|
|
'''
|
|
'''
|
|
获取指定 sn 和起止日期的bms和gps数据.
|
|
获取指定 sn 和起止日期的bms和gps数据.
|