lmstack преди 3 години
родител
ревизия
ec4a4ed724
променени са 1 файла, в които са добавени 32 реда и са изтрити 12 реда
  1. 32 12
      LIB/BACKEND/DBManager.py

+ 32 - 12
LIB/BACKEND/DBManager.py

@@ -14,6 +14,8 @@ import json
 import requests
 import pymysql
 import pdb
+from collections import Counter
+
 
 
 class DBManager():
@@ -80,18 +82,17 @@ class DBManager():
         '''
         返回json数据的生成器,一次一行
         '''
-
         i = 0
         while 1:
             try:
                 r = requests.get(url, stream=True, timeout=(0.1, 1000),  headers={'Connection':'keep-alive', 'Accept':'*/*', 'Accept-Encoding':'gzip,deflate,br'})
                 break
             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)
-                i+=1
+                i+=1    
         # print(r.content)
         # pdb.set_trace()
         data = [] 
@@ -241,16 +242,33 @@ class DBManager():
             CellUNum = 0
             CellTNum = 0
             OtherTNum = 0
+            
+            cellUNumList = []
+            cellTNumList = []
+            otherTNumList = []
+
             for line in data:
                 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', []))
-                if (temp > CellTNum):
-                    CellTNum = temp
+                cellTNumList.append(temp)
+                # if (temp > CellTNum):
+                #     CellTNum = temp
                 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()
             for line in data:
                 et = time.time()
@@ -261,11 +279,13 @@ class DBManager():
                             i+=1
                         continue
                 except Exception as e:
+                    # print(e)
                     continue
                     
                 try:
                     data_block = DBManager._convert_to_dataframe_bms(line, mode, CellUNum, CellTNum, OtherTNum)
                 except Exception as e:
+                    # print(e)
                     continue
            
                 try:
@@ -328,7 +348,7 @@ 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
-    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']):
         '''
         获取指定 sn 和起止日期的bms和gps数据.