yf_yzl 2 лет назад
Родитель
Сommit
0f2033f3ae

BIN
bigdata_django/zhijian/__pycache__/cbd_zhijian.cpython-36.pyc


+ 17 - 28
bigdata_django/zhijian/cbd_zhijian.py

@@ -424,6 +424,10 @@ class CBDThread(QtCore.QThread):
 
     def get_position(self, device_id):
         device = self.device_collection.find_one({"device_id": device_id})
+        province, city, district = device.get("province"), device.get("city"), device.get("district")
+        position_device = f"{province}{city}{district}"
+        if position_device:
+            return position_device
         lng, lat = device.get("lng"), device.get("lat")
         if lng and lat:
             try:
@@ -468,20 +472,17 @@ class CBDThread(QtCore.QThread):
                     data = {"iccids":[iccid]}
                     data = json.dumps(data)
                     ret = requests.post(url,data=data,timeout=(10,30))
-                    print(ret.text)
                     status = 3
         except:
             status = 0
             ret = 0
         day = 0
-        print(ret)
         if ret:
             try:
                 result = json.loads(ret.text)
                 expiry_date = result.get("data", {}).get("expiry_date")
                 now_date = int(time.time())
                 time_difference = int((expiry_date - now_date) / 3600 / 24) 
-                print(time_difference)
                 if time_difference < 30:
                     return [1,"有效期剩余{}天".format(time_difference)]
                 elif time_difference >= 181:
@@ -586,7 +587,6 @@ class CBDThread(QtCore.QThread):
         scores_time = {}
         photo_obj = self.cbd_photo.find({"device_id":str(device_id), 'addtime': {"$gte": int(self.start_time) - 3600 * 24,"$lte":self.start_time}})
         # photo_obj = self.cbd_photo.find({"device_id":str(device_id), 'addtime': {"$lte":self.start_time}})
-        print("图片数量:", photo_obj.count())
         for p in photo_obj:
             photo_addr = p.get("addr")
             addtime = p.get("addtime")
@@ -602,8 +602,6 @@ class CBDThread(QtCore.QThread):
             result_score = self.predict(os.path.join(local_dir, file_name))
             if result_score:
                 avg_score = sum(result_score)/len(result_score)
-                if avg_score > 60:
-                    print(f"score  {avg_score}")
                 scores_time[str(addtime)] = avg_score
             try:
                 os.remove(os.path.join(local_dir, file_name))
@@ -792,7 +790,6 @@ class CBDThread(QtCore.QThread):
                 device_c = ast.literal_eval(device_c)
                 tp = device_c.get("tps", "")
                 if tp == "1":
-                    print(device_c)
                     tr_k_jg_lst.append(tp)
 
         for index, cur in enumerate(data_cursor):
@@ -801,7 +798,6 @@ class CBDThread(QtCore.QThread):
             if device_data:
                 device_data = ast.literal_eval(device_data)
                 iccid = device_data.get("iccid", "")
-            print(device_data, self.set_power, "--------------")
             lamp = device_data.get("lamp")
             if lamp == "0":
                 infor_lamp[str(start_time)] = lamp
@@ -854,7 +850,6 @@ class CBDThread(QtCore.QThread):
             lat_jg = [1, f"{str(min(lat_lst))}~{str(max(lat_lst))}"]
         # 工作状态切换
         work_status_str = "".join(work_status)
-        print(work_status_str, "工作状态切换")
         result = self.eliminate_adjacent_duplicates(work_status_str)
         count_01 = result.count("01")
         count_10 = result.count("10")
@@ -919,7 +914,6 @@ class CBDThread(QtCore.QThread):
         else:
             img_jg = [1, ""]
         # 上报信息条数
-        print("上报信息条数", infor_lamp, information_count)
         interval = [abs(information_count[i+1] - information_count[i]) for i in range(len(information_count) - 1)]
         k = 0
         for i in interval:
@@ -959,21 +953,23 @@ class CBDThread(QtCore.QThread):
                 rtu_num = [0, ",".join(rtus)]
         # 工作时长 判定
         if self.set_power == "DC":
-            print(tt, "+++++++++++++++++++++++++")
-            if tt == "4":
+            # total_time 去重
+            total_time = list(set(total_time))
+            if len(total_time) == 1 and total_time[0] == 4:
+            # if tt == "4":
                 time_jg = [1, "4"]
             else:
                 time_jg = [0, "不合格"]
         else:
             time_jg = [0, "不合格"]
-        #     power_pass = []
-        #     for i in total_time:
-        #         if i not in power_pass:
-        #             power_pass.append(i)
-        #     if len(power_pass) == 1 and power_pass[0] == 4:
-        #         time_jg = [1, "4"]
-        #     else:
-        #         time_jg = [0, ",".join([str(i) for i in power_pass])]
+            # power_pass = []
+            # for i in total_time:
+            #     if i not in power_pass:
+            #         power_pass.append(i)
+            # if len(power_pass) == 1 and power_pass[0] == 4:
+            #     time_jg = [1, "4"]
+            # else:
+            #     time_jg = [0, ",".join([str(i) for i in power_pass])]
         # if self.set_power == "AC":
         #     power_pass = []
         #     for i in total_time:
@@ -1076,7 +1072,6 @@ class CBDThread(QtCore.QThread):
             device_data = cur.get("cbd_data", "")
             if device_data:
                 device_data = ast.literal_eval(device_data)
-            print(device_data, "-------------------")
             lng = device_data.get("lng", "")
             lng_lst.append(float(lng))
             lat = device_data.get("lat", "")
@@ -1089,13 +1084,11 @@ class CBDThread(QtCore.QThread):
             temp_hum.append({"at": device_data.get("at", ""), "ah": device_data.get("ah", "")})
             if self.set_power == "AC":
                 total_time.append(device_data.get("tt"))
-                print(device_data, "-------------------")
             elif self.set_power == "DC":
                 st = device_data.get("st", "00:00")
                 et = device_data.get("et", "00:00")
                 st = int(st.split(":")[0])
                 et = int(et.split(":")[0])
-                print(device_data, "-------------------")
                 if st > et:
                     total = 24 - st + et
                 else:
@@ -1343,14 +1336,12 @@ class CBDThread(QtCore.QThread):
         verify_list = []
         for index, short_id in enumerate(self.device_list):
             short_id = str(int(short_id)).strip() # 把device_id转换成字符串并去除空格
-            print(short_id, "short_id")
             d_id,deviceId,platform = self.device_their_platform(short_id)
             # if short_id != deviceId:
             #     device_id_info = [0, "不合格"]
             # else:
             device_id_info = [1, deviceId]
             worksheet.write(index+4,0,short_id,formal_style)
-            print("ping success", platform)
             if platform == "大数据平台":
                 try:
                     worksheet.write(index+4,1,deviceId,formal_style)
@@ -1359,13 +1350,11 @@ class CBDThread(QtCore.QThread):
                     
                     data_status = self.cbd_alerm.find({"equip_id": deviceId, "alarm_time": {"$gte":self.start_time ,"$lte":self.end_time}}).sort([('alarm_time', pymongo.DESCENDING)])
                     data_cursor = self.cbd_collection.find({"device_id":d_id,'addtime': {"$gte":self.start_time ,"$lte":self.end_time}}).sort([('addtime', pymongo.DESCENDING)])
-                    data_temps = self.cbd_collection.find({"device_id":d_id,'addtime': {"$gte":self.end_time ,"$lte":self.end_time + 3600 * 24}}).sort([('addtime', pymongo.DESCENDING)])
+                    data_temps = self.cbd_collection.find({"device_id":d_id,'addtime': {"$gte":self.start_time - 3600 * 24 ,"$lte":self.start_time}}).sort([('addtime', pymongo.DESCENDING)])
                     data_counts = data_cursor.count()
                     # 配置
                     de = self.device_collection.find_one({"device_id":deviceId})
-                    print(de, "__________1_________")
                     device_config = self.device_config.find_one({"d_id":de.get("id")})
-                    print(device_config, "___________2__________")
                     tt = 0
                     if device_config:
                         device_config_temp = device_config.get("device_config")

+ 4 - 1
bigdata_django/zhijian/qxz_zhijian_new.py

@@ -1411,7 +1411,10 @@ function(uptime_list){
                     result = self.get_position(lng, lat)
                     if not result:
                         device_tp = self.device_collection.find_one({"device_id": device_id})
-                        result = device_tp.get("province") + device_tp.get("city") + device_tp.get("district")
+                        if device_tp:
+                            result = device_tp.get("province") + device_tp.get("city") + device_tp.get("district")
+                        else:
+                            result = ""
                     if result and result == "河南省新乡市原阳县":
                         status = 1
                         msg = result