|
|
@@ -388,6 +388,8 @@ class CBDThread(QtCore.QThread):
|
|
|
self.save_path = save_path
|
|
|
self.start_time = time.mktime(start_time.timetuple())
|
|
|
self.end_time = time.mktime(end_time.timetuple())
|
|
|
+ # self.start_time = 1689737400
|
|
|
+ # self.end_time = 1689753600
|
|
|
self.start_time_str = start_time.strftime("%y-%m-%d %H:%M:%S")
|
|
|
self.end_time_str = end_time.strftime("%y-%m-%d %H:%M:%S")
|
|
|
self.set_plat = set_plat
|
|
|
@@ -405,6 +407,7 @@ class CBDThread(QtCore.QThread):
|
|
|
self.cbd_collection = self.db.sa_device_cbd_data
|
|
|
self.cbd_photo = self.db.sa_device_cbdphoto
|
|
|
self.cbd_alerm = self.db.sa_alarm_record
|
|
|
+ self.device_config = self.db.sa_device_config
|
|
|
|
|
|
self.config = {
|
|
|
'host': '120.27.222.26',
|
|
|
@@ -418,6 +421,24 @@ class CBDThread(QtCore.QThread):
|
|
|
self.connection = pymysql.connect(**self.config)
|
|
|
self.cursor = self.connection.cursor()
|
|
|
|
|
|
+
|
|
|
+ def get_position(self, device_id):
|
|
|
+ device = self.device_collection.find_one({"device_id": device_id})
|
|
|
+ lng, lat = device.get("lng"), device.get("lat")
|
|
|
+ if lng and lat:
|
|
|
+ try:
|
|
|
+ ret = requests.post("http://api.map.baidu.com/geocoder?location=%s,%s&coord_type=gcj02&output=json"%(lat,lng))
|
|
|
+ ret_json = json.loads(ret.text)
|
|
|
+ province, city, district = ret_json["result"]["addressComponent"]["province"], \
|
|
|
+ ret_json["result"]["addressComponent"]["city"], \
|
|
|
+ ret_json["result"]["addressComponent"]["district"]
|
|
|
+
|
|
|
+ return province + city + district
|
|
|
+ except Exception as e:
|
|
|
+ return False
|
|
|
+ else:
|
|
|
+ return False
|
|
|
+
|
|
|
|
|
|
def sim_info(self,iccid):
|
|
|
# 时间戳 用于获取sign
|
|
|
@@ -462,15 +483,15 @@ class CBDThread(QtCore.QThread):
|
|
|
time_difference = int((expiry_date - now_date) / 3600 / 24)
|
|
|
print(time_difference)
|
|
|
if time_difference < 30:
|
|
|
- return [0,"有效期剩余{}天".format(time_difference)]
|
|
|
+ return [1,"有效期剩余{}天".format(time_difference)]
|
|
|
elif time_difference >= 181:
|
|
|
return [1,"有效期剩余{}天".format(time_difference)]
|
|
|
else:
|
|
|
- return [2,"有效期剩余{}天".format(time_difference)]
|
|
|
+ return [1,"有效期剩余{}天".format(time_difference)]
|
|
|
except:
|
|
|
- return [0, "查询无结果"]
|
|
|
+ return [1, "查询无结果"]
|
|
|
else:
|
|
|
- return [0, "查询无结果"]
|
|
|
+ return [1, "查询无结果"]
|
|
|
|
|
|
|
|
|
def _imageToMatrix(self, image):
|
|
|
@@ -697,7 +718,7 @@ class CBDThread(QtCore.QThread):
|
|
|
return result
|
|
|
|
|
|
|
|
|
- def __bigdata_verify(self,data_cursor,data_status,device_id_info, image_score, proess, data_temps):
|
|
|
+ def __bigdata_verify(self,data_cursor,data_status,device_id_info, image_score, proess, data_temps, position, tt):
|
|
|
"""
|
|
|
获取大数据平台查询结果
|
|
|
1. 合格
|
|
|
@@ -780,6 +801,7 @@ 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
|
|
|
@@ -937,23 +959,34 @@ class CBDThread(QtCore.QThread):
|
|
|
rtu_num = [0, ",".join(rtus)]
|
|
|
# 工作时长 判定
|
|
|
if self.set_power == "DC":
|
|
|
- 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:
|
|
|
+ print(tt, "+++++++++++++++++++++++++")
|
|
|
+ if tt == "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:
|
|
|
- if i not in power_pass:
|
|
|
- power_pass.append(i)
|
|
|
- if len(power_pass) == 1 and power_pass[0] == 9:
|
|
|
- time_jg = [1, "9"]
|
|
|
- else:
|
|
|
- time_jg = [0, ",".join([str(i) for i in power_pass])]
|
|
|
+ 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])]
|
|
|
+ # if self.set_power == "AC":
|
|
|
+ # 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] == 9:
|
|
|
+ # time_jg = [1, "9"]
|
|
|
+ # else:
|
|
|
+ # time_jg = [0, ",".join([str(i) for i in power_pass])]
|
|
|
+ if position == "河南省新乡市原阳县":
|
|
|
+ position_cg = [1, position]
|
|
|
+ else:
|
|
|
+ position_cg = [0, position]
|
|
|
return [
|
|
|
device_id_info,
|
|
|
[1, self.set_order],
|
|
|
@@ -977,7 +1010,8 @@ class CBDThread(QtCore.QThread):
|
|
|
# lig_jg,
|
|
|
# machine_jg,
|
|
|
# camera_jg,
|
|
|
- time_jg
|
|
|
+ time_jg,
|
|
|
+ position_cg
|
|
|
]
|
|
|
|
|
|
|
|
|
@@ -1042,6 +1076,7 @@ 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", "")
|
|
|
@@ -1054,11 +1089,13 @@ 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:
|
|
|
@@ -1270,7 +1307,7 @@ class CBDThread(QtCore.QThread):
|
|
|
title_data = [
|
|
|
"文档ID","设备ID", "任务单号", "卡号及有效期","经度","纬度","工作状态切换", "电路板固件版本号","RTU固件版本号",
|
|
|
"电路板输入电压","温控","雨控","上报信息条数","加热仓温度","环境温度","环境湿度","图片质量",
|
|
|
- "工作时长", "综合判定"
|
|
|
+ "工作时长", "位置", "综合判定"
|
|
|
]
|
|
|
worksheet.write_row(row = 2 ,col = 0, data = title_data,cell_format=title_style)
|
|
|
explain_data = [
|
|
|
@@ -1298,18 +1335,20 @@ class CBDThread(QtCore.QThread):
|
|
|
# "合格条件(绿色):\n在工作时间段内没有接收到“电流不足”的信息为合格,否则不合格",
|
|
|
# "合格条件(绿色):\n在工作时间段内没有接收到“电流不足”的信息为合格,否则不合格",
|
|
|
"合格条件(绿色):\n与供电选择输入对照,(DC为4h,AC为9h)一致判定为合格,否则为不合格",
|
|
|
+ "位置信息(绿色): \n合格条件(绿色), 显示河南省新乡市原阳县为合格,否则不合格",
|
|
|
"合格条件(绿色):\nd:r列全部合格为合格,否则为不合格"
|
|
|
]
|
|
|
worksheet.write_row(row = 3 ,col = 0, data = explain_data,cell_format=explain_style)
|
|
|
formal_counts = 0
|
|
|
verify_list = []
|
|
|
for index, short_id in enumerate(self.device_list):
|
|
|
- short_id = str(short_id).strip() # 把device_id转换成字符串并去除空格
|
|
|
+ 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, "合格"]
|
|
|
+ # 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 == "大数据平台":
|
|
|
@@ -1322,18 +1361,31 @@ class CBDThread(QtCore.QThread):
|
|
|
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_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")
|
|
|
+ device_config_temp = eval(device_config_temp)
|
|
|
+ device_config_temp_ext = device_config_temp.get("ext")
|
|
|
+ tt = device_config_temp_ext.get("tt")
|
|
|
+
|
|
|
image_score = self.__bigdata_iamge_verify(d_id)
|
|
|
if data_counts == 0:
|
|
|
- for i in range(1,25):
|
|
|
+ for i in range(1,19):
|
|
|
worksheet.write(index+4,i,"搜索时间内无数据",error_style)
|
|
|
- worksheet.write(index+4,24,"不合格",error_style)
|
|
|
+ worksheet.write(index+4,19,"不合格",error_style)
|
|
|
danji_verify = []
|
|
|
- for i in range(23):
|
|
|
+ for i in range(19):
|
|
|
danji_verify.append(0)
|
|
|
verify_list.append(danji_verify)
|
|
|
else:
|
|
|
danji_verify = []
|
|
|
- verify_data = self.__bigdata_verify(data_cursor,data_status, device_id_info, image_score, proess, data_temps)
|
|
|
+ result = self.get_position(deviceId)
|
|
|
+ verify_data = self.__bigdata_verify(data_cursor,data_status, device_id_info, image_score, proess, data_temps, result, tt)
|
|
|
for clo_index, verify_ in enumerate(verify_data):
|
|
|
danji_verify.append(verify_[0])
|
|
|
if verify_[0] == 0:
|
|
|
@@ -1343,10 +1395,10 @@ class CBDThread(QtCore.QThread):
|
|
|
else:
|
|
|
worksheet.write(index+4,clo_index+1,verify_[1],common_style)
|
|
|
if 0 in danji_verify:
|
|
|
- worksheet.write(index+4,18,"不合格",error_style)
|
|
|
+ worksheet.write(index+4,19,"不合格",error_style)
|
|
|
else:
|
|
|
formal_counts += 1
|
|
|
- worksheet.write(index+4,18,"合格",formal_style)
|
|
|
+ worksheet.write(index+4,19,"合格",formal_style)
|
|
|
verify_list.append(danji_verify)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
@@ -1368,11 +1420,11 @@ class CBDThread(QtCore.QThread):
|
|
|
status_all_result = self.cursor.fetchall()
|
|
|
if len(data_result) == 0:
|
|
|
# 空白数据填充
|
|
|
- for i in range(1,25):
|
|
|
+ for i in range(1,19):
|
|
|
worksheet.write(index+4,i,"搜索时间内无数据",error_style)
|
|
|
- worksheet.write(index+4,24,"不合格",error_style)
|
|
|
+ worksheet.write(index+4,19,"不合格",error_style)
|
|
|
danji_verify = []
|
|
|
- for i in range(23):
|
|
|
+ for i in range(19):
|
|
|
danji_verify.append(0)
|
|
|
verify_list.append(danji_verify)
|
|
|
else:
|
|
|
@@ -1388,10 +1440,10 @@ class CBDThread(QtCore.QThread):
|
|
|
else:
|
|
|
worksheet.write(index+4,clo_index+1,verify_[1],common_style)
|
|
|
if 0 in danji_verify:
|
|
|
- worksheet.write(index+4,24,"不合格",error_style)
|
|
|
+ worksheet.write(index+4,19,"不合格",error_style)
|
|
|
else:
|
|
|
formal_counts += 1
|
|
|
- worksheet.write(index+4,24,"合格",formal_style)
|
|
|
+ worksheet.write(index+4,19,"合格",formal_style)
|
|
|
verify_list.append(danji_verify)
|
|
|
except Exception as e:
|
|
|
print(e)
|