Ver Fonte

脚本统一

liuxingchen há 1 ano atrás
pai
commit
604068e776
1 ficheiros alterados com 64 adições e 58 exclusões
  1. 64 58
      001_h511/imageCapture/dataPackUp.py

+ 64 - 58
001_h511/imageCapture/dataPackUp.py

@@ -82,10 +82,9 @@ def getMqttDataFromMysqlHistory(data_list, code_list):
             code, point = getCodeAndPoint(code_list[i]['mqttCode'])
             dataDist[point] = str(data_list[index]["c" + str(code_list[i]['serialNumber'])])
             if code_list[i]['lowLimit'] != None and code_list[i]['upLimit'] != None:
-                if dataDist[point] != 'None':
-                    if dataDist[point] is None or float(dataDist[point]) < code_list[i]['lowLimit'] or float(dataDist[point]) > code_list[i]['upLimit']:
-                        # dataDist['DQ_DI'] = '1'     # 功能优化
-                        dataDist.pop(point)     # 功能优化,过滤坏数据
+                if dataDist[point] != 'None' or float(dataDist[point]) < code_list[i]['lowLimit'] or float(dataDist[point]) > code_list[i]['upLimit']:
+                    # dataDist['DQ_DI'] = '1'     # 功能优化
+                    dataDist.pop(point)     # 功能优化,过滤坏数据
 
             if code_list[i]['storageType'] == "datetime":
 
@@ -159,23 +158,35 @@ def post(zip_file):
     headers = {
         "Authorization": token,
         "Content-Type": "application/json"}
-    data = {"platformId": PLATFORM_ID,
-            "fileNames": zip_file
-            }
-    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
-    # print(zip_file)
-    # print('timestamp: ',datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
-    try:
-        ret = requests.post('https://management.super-sight.com.cn/device/api/v2/device/history', headers=headers,json=data, verify=False)
-    except Exception as e:
-        print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+"[ERROR] {0}\n".format(e))
-
-    if ret.status_code == 200:
-        print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), ret.text, ret.status_code, 'len(zip_file)=', len(zip_file))
-        return "SUCCESS"
-    else:
-        print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), ret.text, ret.status_code)
-        return "FAIL"
+
+    result = "SUCCESS"
+    step_size = 1000
+    for i in range(0, len(zip_file), step_size):
+        if len(zip_file) > i + step_size:
+            group_zip_file = zip_file[i:i+step_size]
+        else:
+            group_zip_file = zip_file[i:]
+
+        data = {"platformId": PLATFORM_ID,
+                "fileNames": group_zip_file
+                }
+
+        # print(data)
+        # print(len(group_zip_file))
+        # print('timestamp: ',datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
+        try:
+            urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
+            ret = requests.post('https://management.super-sight.com.cn/device/api/v2/device/history', headers=headers, json=data, verify=False)
+
+            if ret.status_code == 200:
+                print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), ret.text, ret.status_code, 'len(group_zip_file)=', len(group_zip_file))
+            else:
+                print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), ret.text, ret.status_code, 'len(group_zip_file)=', len(group_zip_file))
+                result = "FAIL"
+        except Exception as e:
+            print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "e=", e)
+
+    return result
 
 
 if __name__ == "__main__":
@@ -213,7 +224,7 @@ if __name__ == "__main__":
     if not os.path.exists(txt_path):
         os.mkdir(txt_path)
     while True:
-        # time.sleep(1)
+        time.sleep(1)
         if post_time < time.time() - 3600:
             zip_list = []
             flie_name = os.listdir("HDU/")
@@ -231,45 +242,40 @@ if __name__ == "__main__":
             while i < max(int(200 / count), 1):
                 for device_name in list_devices:
                     code_devices = mysql_object.get_mqtt_devices_from_name(device_name)
-                    # 鏋勯?犺〃鍚嶇О锛屽table_fg
+                    # 构造表名称,如table_fg
                     table_name = 'table_' + device_name
-                    # 鑾峰彇鏂偣鏃堕棿
+                    # 获取断点时间
                     break_point = mysql_object.get_breakpoint_last_time_datetime(table_name)
                     if break_point != None:
-                        # 构造表名称,如table_fg
-                        table_name = 'table_' + device_name
-                        # 获取断点时间
-                        break_point = mysql_object.get_breakpoint_last_time_datetime(table_name)
-                        if break_point != None:
-                            # 找到断点时间前后一个小时的时间点
-                            timeArray = time.strptime(str(break_point['times']), "%Y-%m-%d %H:%M:%S")
-                            begin = time.strftime("%Y-%m-%d %H:00:00", timeArray)
-                            end = time.strftime("%Y-%m-%d %H:59:59", timeArray)
-                            begin_timeArray = time.strptime(str(begin), "%Y-%m-%d %H:%M:%S")
-                            end_timeArray = time.strptime(str(end), "%Y-%m-%d %H:%M:%S")
-                            begin_timestamp = int(time.mktime(begin_timeArray))
-                            end_timestamp = int(time.mktime(end_timeArray))
-                            # 获取断点前后一个小时的数据
-                            data_list = mysql_object.get_hour_data_datetime(table_name, begin, end)
-                            history_data_list = data_alignment(data_list, begin_timestamp, end_timestamp, 2)
-                            if len(code_devices) >= 1:
-                                for index in range(len(code_devices)):
-                                    # 获取设备码表
-                                    code_list = mysql_object.get_mqtt_point(code_devices[index])
-                                    param, id = getMqttDataFromMysqlHistory(history_data_list, code_list)
-                                    txt_name = get_txt_name(begin_timestamp, param[0]["code"])
-                                    # 将txt_path目录下所有设备txt组包
-                                    if len(os.listdir(txt_path)) >= 20:
-                                        zip_name = make_zip(txt_path)
-                                        time.sleep(5)
-                                    with open(os.path.join(txt_path, txt_name), 'w') as f:
-                                        txt_content = [str(line) + '\n' for line in param]
-                                        f.writelines(txt_content)
-                                    time.sleep(1)
-                                    # print(zip_name)
-                                    if index == len(code_devices) - 1:
-                                        # pass
-                                        mysql_object.set_many_send_status(table_name, data_list)
+                        # 找到断点时间前后一个小时的时间点
+                        timeArray = time.strptime(str(break_point['times']), "%Y-%m-%d %H:%M:%S")
+                        begin = time.strftime("%Y-%m-%d %H:00:00", timeArray)
+                        end = time.strftime("%Y-%m-%d %H:59:59", timeArray)
+                        begin_timeArray = time.strptime(str(begin), "%Y-%m-%d %H:%M:%S")
+                        end_timeArray = time.strptime(str(end), "%Y-%m-%d %H:%M:%S")
+                        begin_timestamp = int(time.mktime(begin_timeArray))
+                        end_timestamp = int(time.mktime(end_timeArray))
+                        # 获取断点前后一个小时的数据
+                        data_list = mysql_object.get_hour_data_datetime(table_name, begin, end)
+                        history_data_list = data_alignment(data_list, begin_timestamp, end_timestamp, 2)
+                        if len(code_devices) >= 1:
+                            for index in range(len(code_devices)):
+                                # 获取设备码表
+                                code_list = mysql_object.get_mqtt_point(code_devices[index])
+                                param, id = getMqttDataFromMysqlHistory(history_data_list, code_list)
+                                txt_name = get_txt_name(begin_timestamp, param[0]["code"])
+                                # 将txt_path目录下所有设备txt组包
+                                if len(os.listdir(txt_path)) >= 20:
+                                    zip_name = make_zip(txt_path)
+                                    time.sleep(5)
+                                with open(os.path.join(txt_path, txt_name), 'w') as f:
+                                    txt_content = [str(line) + '\n' for line in param]
+                                    f.writelines(txt_content)
+                                time.sleep(1)
+                                # print(zip_name)
+                                if index == len(code_devices) - 1:
+                                    # pass
+                                    mysql_object.set_many_send_status(table_name, data_list)
                 i += 1
             pack_time = time.time()
             if len(os.listdir(txt_path)) > 0: