cbd_single.py 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. from asyncio import ensure_future, shield
  2. from cmath import infj
  3. from concurrent.futures import process
  4. from msilib import OpenDatabase
  5. from sqlite3 import DataError
  6. from ssl import wrap_socket
  7. from tracemalloc import start
  8. from turtle import st
  9. from PyQt5 import QtCore, QtGui, QtWidgets
  10. import os
  11. import sys
  12. import re
  13. import ast
  14. from urllib import parse
  15. import json
  16. import time
  17. import datetime
  18. import requests
  19. import uuid
  20. import pymongo
  21. import pymysql
  22. from xlrd import open_workbook
  23. from xlsxwriter.workbook import Workbook
  24. import numpy as np
  25. import cv2
  26. import argparse
  27. import io
  28. # import torch
  29. from PIL import Image
  30. from skimage import filters
  31. import os
  32. save_filename = ""
  33. pwd_str = "yf6021"
  34. toji_format = {
  35. 'font_name' : '宋体',
  36. 'font_size': 14,
  37. 'font_color': 'black',
  38. 'text_wrap': True,
  39. 'bold': False,
  40. 'fg_color': '92D050',
  41. 'align': 'center',
  42. 'valign': 'vcenter',
  43. 'border': 1,
  44. 'top': 1,
  45. 'left': 1,
  46. 'right': 1,
  47. 'bottom': 1
  48. }
  49. title_format = {
  50. 'font_name' : '宋体',
  51. 'font_size': 12,
  52. 'bold': True,
  53. 'align': 'center',
  54. 'valign': 'vcenter',
  55. 'border': 1,
  56. 'top': 1,
  57. 'left': 1,
  58. 'right': 1,
  59. 'bottom': 1
  60. }
  61. merge_title_format = {
  62. 'font_name' : '宋体',
  63. 'font_size': 26,
  64. 'bold': True,
  65. 'align': 'center',
  66. 'valign': 'vcenter',
  67. "fg_color": "8DB4E2",
  68. 'border': 1,
  69. 'top': 1,
  70. 'left': 1,
  71. 'right': 1,
  72. 'bottom': 1
  73. }
  74. explain_formal = {
  75. 'font_name' : '宋体',
  76. 'font_size': 11,
  77. 'font_color': 'black',
  78. 'text_wrap': True,
  79. 'align': 'justify',
  80. 'valign': 'vcenter',
  81. 'border': 1,
  82. 'top': 1,
  83. 'left': 1,
  84. 'right': 1,
  85. 'bottom': 1
  86. }
  87. formal_format = {
  88. 'font_name' : '宋体',
  89. 'font_size': 11,
  90. 'font_color': 'black',
  91. 'fg_color': '77E88C',
  92. 'text_wrap': True,
  93. 'align': 'center',
  94. 'valign': 'vcenter',
  95. 'border': 1,
  96. 'top': 1,
  97. 'left': 1,
  98. 'right': 1,
  99. 'bottom': 1
  100. }
  101. common_format = {
  102. 'font_name' : '宋体',
  103. 'font_size': 11,
  104. 'font_color': 'black',
  105. "fg_color": 'E7EC73',
  106. 'text_wrap': True,
  107. 'align': 'center',
  108. 'valign': 'vcenter',
  109. 'border': 1,
  110. 'top': 1,
  111. 'left': 1,
  112. 'right': 1,
  113. 'bottom': 1
  114. }
  115. error_format = {
  116. 'font_name' : '宋体',
  117. 'font_size': 11,
  118. 'font_color': 'black',
  119. "fg_color": 'F4746A',
  120. 'text_wrap': True,
  121. 'align': 'center',
  122. 'valign': 'vcenter',
  123. 'border': 1,
  124. 'top': 1,
  125. 'left': 1,
  126. 'right': 1,
  127. 'bottom': 1
  128. }
  129. class SCDThread(QtCore.QThread):
  130. """涉及进度条需主界面动态执行GUI,线程执行业务逻辑,避免主页面卡死"""
  131. proess_signal = QtCore.pyqtSignal(int)
  132. def __init__(self,device_list,save_path,start_time,end_time,set_plat,set_stm8vs,set_dver,set_order, set_product, set_power):
  133. super(SCDThread, self).__init__()
  134. self.device_list = device_list
  135. self.save_path = save_path
  136. self.start_time = time.mktime(start_time.timetuple())
  137. self.end_time = time.mktime(end_time.timetuple())
  138. self.start_time_str = start_time.strftime("%y-%m-%d %H:%M:%S")
  139. self.end_time_str = end_time.strftime("%y-%m-%d %H:%M:%S")
  140. self.set_plat = set_plat
  141. self.set_stm8vs = set_stm8vs
  142. self.set_dver = set_dver
  143. self.set_order = set_order
  144. self.set_product = set_product
  145. self.set_power = set_power
  146. self.user = parse.quote_plus("root")
  147. self.passwd = parse.quote_plus("yfkj@6020")
  148. self.myclient = pymongo.MongoClient("mongodb://{0}:{1}@8.136.98.49:57017/".format(self.user,self.passwd))
  149. self.db = self.myclient.smartfarming
  150. self.device_collection = self.db.sa_device
  151. self.cbd_collection = self.db.sa_device_cbd_data
  152. self.cbd_photo = self.db.sa_device_cbdphoto
  153. self.cbd_alerm = self.db.sa_alarm_record
  154. self.config = {
  155. 'host': '120.27.222.26',
  156. 'port': 3306,
  157. 'user': 'yfwlw',
  158. 'password': 'sql_yfkj_6019',
  159. 'db': 'yfwlw',
  160. 'charset': 'utf8mb4',
  161. 'cursorclass': pymysql.cursors.DictCursor,
  162. }
  163. self.connection = pymysql.connect(**self.config)
  164. self.cursor = self.connection.cursor()
  165. def mongo_ping(self):
  166. """mongo-ping预防连接失效"""
  167. try:
  168. self.myclient.admin.command('ping')
  169. except: # "ConnectionFailure"
  170. self.myclient = pymongo.MongoClient("mongodb://{0}:{1}@8.136.98.49:57017/".format(self.user,self.passwd))
  171. self.db = self.myclient.smartfarming
  172. self.device_collection = self.db.sa_device
  173. self.cbd_collection = self.db.sa_device_cbd_data
  174. self.cbd_photo = self.db.sa_device_cbdphoto
  175. self.cbd_alerm = self.db.sa_alarm_record
  176. def sql_ping(self):
  177. """mysql-ping 预防连接失效"""
  178. try:
  179. self.connection.ping()
  180. except:
  181. self.connection = pymysql.connect(**self.config)
  182. self.cursor = self.connection.cursor()
  183. def __time_dif(self,checkdatetime):
  184. """计算时间差"""
  185. nowdatetime = datetime.datetime.now()
  186. checkdatetime = datetime.datetime.strptime(checkdatetime, "%Y-%m-%d %H:%M:%S")
  187. timedif = checkdatetime - nowdatetime
  188. return timedif.days
  189. def device_their_platform(self,shortId):
  190. """确定设备所在平台已经完整设备号"""
  191. self.mongo_ping()
  192. self.sql_ping()
  193. regex = re.compile('.*{}$'.format(shortId))
  194. bd_device_dict = self.device_collection.find_one(
  195. filter = {"device_id":regex,"device_type_id":3},
  196. projection = {'_id': 0},
  197. sort = [('uptime', pymongo.DESCENDING)]
  198. )
  199. device_sql = "SELECT * FROM AppInfoManage_cbdstatus WHERE equip_id_id LIKE '%{}' ORDER BY upl_time DESC LIMIT 1;".format(shortId)
  200. self.cursor.execute(device_sql)
  201. sq_device_dict = self.cursor.fetchone()
  202. if bd_device_dict and sq_device_dict:
  203. bd_upltime = bd_device_dict["uptime"]
  204. sq_upltime = time.mktime(sq_device_dict["upl_time"].timetuple())
  205. if bd_upltime >= sq_upltime:
  206. d_id = bd_device_dict["id"]
  207. deviceId = bd_device_dict["device_id"]
  208. platform = "大数据平台"
  209. else:
  210. d_id = ""
  211. deviceId = sq_device_dict["equip_id_id"]
  212. platform = "四情平台"
  213. elif bd_device_dict and not sq_device_dict:
  214. d_id = bd_device_dict["id"]
  215. deviceId = bd_device_dict["device_id"]
  216. platform = "大数据平台"
  217. return d_id,deviceId,platform
  218. elif not bd_device_dict and sq_device_dict:
  219. d_id = ""
  220. deviceId = sq_device_dict["equip_id_id"]
  221. platform = "四情平台"
  222. else:
  223. d_id = ""
  224. deviceId = "平台无此设备"
  225. platform = "未知"
  226. return d_id,deviceId,platform
  227. def sim_info(self,iccid):
  228. """查询卡信息"""
  229. url = "http://8.136.98.49:10001/iotcard/platsimview/inquiries/"
  230. try:
  231. response = requests.request("POST", url, data={"iccid":iccid})
  232. except:
  233. return [0,"查询卡信息异常稍后重试"]
  234. else:
  235. res_data = json.loads(response.text)
  236. if res_data["msg"]=="success" and res_data["data"]:
  237. expiry_date = res_data["data"]["expiry_date"]
  238. if expiry_date == "未知":
  239. return [0,"未查询到卡信息"]
  240. elif expiry_date == "未激活":
  241. return [3, "未激活"]
  242. else:
  243. time_difference = self.__time_dif(expiry_date)
  244. if time_difference < 30:
  245. return [1,"有效期剩余{}天".format(time_difference)]
  246. elif time_difference >= 181:
  247. return [1,"有效期剩余{}天".format(time_difference)]
  248. else:
  249. return [1,"有效期剩余{}天".format(time_difference)]
  250. else:
  251. return [0,"查询无结果"]
  252. def __bigdata_verify(self,data_cursor,data_status,device_id_info, image_score, proess):
  253. """
  254. 获取大数据平台查询结果
  255. 1. 合格
  256. 2. 不合格
  257. """
  258. current_jg = [1,"无电流不足信息"] # 振动电机工作状态下电流匹配度
  259. up_jg = [1,"无电流不足信息"] # 上仓门电机电机工作状态
  260. down_jg = [1,"无电流不足信息"] # 下仓门电机电机工作状态
  261. lig_jg = [1,"无电流不足信息"] # 灯管工作状态下
  262. machine_jg = [1, "无电流不足信息"]# 电机工作状态
  263. camera_jg = [1, "无电流不足信息"] # 相机工作状态
  264. current_jg_ct, up_jg_ct, down_jg_ct, lig_jg_ct, camera_jg_ct = 0,0,0,0,0
  265. for alerm in data_status:
  266. a = alerm.get("alarm_desc", "")
  267. if a:
  268. a = json.loads(a)
  269. if a.get("type", "") == "震动电机":
  270. if a.get("status") == "电流不足":
  271. current_jg_ct += 1
  272. elif a.get("type", "") == "上仓门电机":
  273. if a.get("status") in ["打开电流不足", "关闭电流不足"]:
  274. up_jg_ct += 1
  275. elif a.get("type", "") == "下仓门电机":
  276. if a.get("status") in ["打开电流不足", "关闭电流不足"]:
  277. down_jg_ct += 1
  278. elif a.get("type", "") == "灯管":
  279. if a.get("status") == "电流不足":
  280. lig_jg_ct += 1
  281. elif a.get("type", "") == "相机":
  282. if a.get("status") == "电流不足":
  283. camera_jg_ct += 1
  284. if current_jg_ct:
  285. current_jg = [0,f"有电流不足信息{str(current_jg_ct)}条"]
  286. if up_jg_ct:
  287. up_jg = [0,f"有电流不足信息{str(up_jg_ct)}条"]
  288. if down_jg_ct:
  289. down_jg = [0,f"有电流不足信息{str(down_jg_ct)}条"]
  290. if lig_jg_ct:
  291. lig_jg = [0,f"有电流不足信息{str(lig_jg_ct)}条"]
  292. if camera_jg_ct:
  293. camera_jg = [0,f"有电流不足信息{str(camera_jg_ct)}条"]
  294. iccid = ""
  295. lng_lst = []
  296. lat_lst = []
  297. work_status = [] # 工作状态切换
  298. elec_vs_lst = [] # 电路板固件版本号
  299. v_vs_lst = [] # 电压
  300. tr_k_jg_lst = [] # 温控
  301. rain_k_jg_lst = []# 雨控
  302. infor_jg_count = 0 # 上报信息条数
  303. heat_temp_lst = []# 加热仓温度
  304. temp_hum = [] # 环境温度 环境湿度
  305. total_time = [] # 总时长
  306. start_time = 0
  307. information_count = [] # 上报时间
  308. dver_lst = []
  309. for index, cur in enumerate(data_cursor):
  310. start_time = int(cur.get("addtime", 0))
  311. information_count.append(start_time)
  312. device_data = cur.get("device_data", "")
  313. if device_data:
  314. device_data = ast.literal_eval(device_data)
  315. iccid = device_data.get("iccid", "")
  316. lng = device_data.get("lng", "")
  317. lat = device_data.get("lat", "")
  318. try:
  319. lng_lst.append(float(lng))
  320. lat_lst.append(float(lat))
  321. except Exception as e:
  322. lng_lst.append(0)
  323. lat_lst.append(0)
  324. work_status.append(device_data.get("ws", ""))
  325. elec_vs_lst.append(device_data.get("dver", ""))
  326. v_vs_lst.append(float(device_data.get("vbat", 0)))
  327. tr_k_jg_lst.append(device_data.get("tps", ""))
  328. rain_k_jg_lst.append(device_data.get("rps", ""))
  329. infor_jg_count += 1
  330. heat_temp_lst.append(float(device_data.get("hrt", 0)))
  331. temp_hum.append({"at": device_data.get("at", ""), "ah": device_data.get("ah", "")})
  332. if self.set_power == "AC":
  333. total_time.append(int(device_data.get("tt")))
  334. elif self.set_power == "DC":
  335. st = device_data.get("st") # 19:00
  336. et = device_data.get("et") # 08:00
  337. st = int(st.split(":")[0])
  338. et = int(et.split(":")[0])
  339. if st > et:
  340. total = 24 - st + et
  341. else:
  342. total = et - st
  343. total_time.append(total)
  344. dver = device_data.get("dver", "")
  345. if dver:
  346. dver_lst.append(dver)
  347. # 检查卡号及有效期
  348. card_jg = self.sim_info(iccid)
  349. # 经度
  350. lng_pass = [i for i in lng_lst if 113.76194444 >= i or i >= 113.77861111]
  351. if len(lng_pass):
  352. lng_jg = [0,f"{str(min(lng_lst))}~{str(max(lng_lst))},不符合条件的数据有{str(len(lng_pass))}条"]
  353. else:
  354. lng_jg = [1, f"{str(min(lng_lst))}~{str(max(lng_lst))}"]
  355. # 纬度 35.02083333,35.0375
  356. lat_pass = [i for i in lat_lst if 35.02083333 >=i or i >= 35.0375]
  357. if len(lat_pass):
  358. lat_jg = [0,f"{str(min(lat_lst))}~{str(max(lat_lst))},不符合条件的数据有{str(len(lat_pass))}条"]
  359. else:
  360. lat_jg = [1, f"{str(min(lat_lst))}~{str(max(lat_lst))}"]
  361. # 工作状态切换
  362. work_status_str = "".join(work_status)
  363. wr = work_status_str.count("01")
  364. if wr > 4:
  365. work_jg = [1, f"待机/工作转换{str(wr)}次"]
  366. else:
  367. work_jg = [0, f"待机/工作转换{str(wr)}次"]
  368. # 电路板输入电压
  369. v_vs_pass = [i for i in v_vs_lst if 22 >= i or i >= 30]
  370. if len(v_vs_pass):
  371. v_vs = [0, f"{str(min(v_vs_lst))}~{str(max(v_vs_lst))},不合格数据3条"]
  372. else:
  373. v_vs = [1, f"{str(min(v_vs_lst))}~{str(max(v_vs_lst))}"]
  374. # 温控
  375. if "1" in tr_k_jg_lst:
  376. tr_k_jg = [1, f"上报被温控数据{str(tr_k_jg_lst.count('1'))}条"]
  377. else:
  378. tr_k_jg = [0, f"无数据上报"]
  379. # 雨控
  380. if "1" in rain_k_jg_lst:
  381. rain_k_jg = [1, f"被雨控有{str(rain_k_jg_lst.count('1'))}条数据"]
  382. else:
  383. rain_k_jg = [0, "无被雨控数据上报"]
  384. # 加热仓温度
  385. heat_temp = []
  386. for h in heat_temp_lst:
  387. if 85 <= h <= 105:
  388. heat_temp = [1, f"{str(min(heat_temp_lst))}~{str(max(heat_temp_lst))}"]
  389. break
  390. if not heat_temp:
  391. heat_temp = [0, f"{str(min(heat_temp_lst))}~{str(max(heat_temp_lst))}"]
  392. # 环境温度
  393. if {"at": "25", "ah": "35"} in temp_hum:
  394. en_temp = [0,"35且环境湿度显示25"]
  395. else:
  396. temp = [float(k.get("at", 0)) for k in temp_hum]
  397. en_temp = [1,f"{str(min(temp))}~{str(max(temp))}"]
  398. # 环境湿度
  399. if {"at": "35", "ah": "25"} in temp_hum:
  400. en_hum = [0,"25且环境温度显示35"]
  401. else:
  402. temp = [float(k.get("ah", 0)) for k in temp_hum]
  403. en_hum = [1,f"{str(min(temp))}~{str(max(temp))}"]
  404. # 图片质量
  405. img_pass = []
  406. img_score = []
  407. for k, v in image_score.items():
  408. if v > 50:
  409. img_score.append(v)
  410. if v < 68:
  411. img_pass.append((datetime.datetime.fromtimestamp(int(k))).strftime("%Y-%m-%d %H:%M:%S"))
  412. if img_score:
  413. if img_pass:
  414. img_jg = [0, f"{str(min(img_score))}~{str(max(img_score))}, 不合格图片{str(len(img_pass))}幅, 上报时间为{','.join(img_pass)}"]
  415. else:
  416. img_jg = [1, f"{str(min(img_score))}~{str(max(img_score))}"]
  417. else:
  418. img_jg = [0, "图片得分均在50以下"]
  419. # 上报信息条数
  420. interval = [abs(information_count[i+1] - information_count[i]) for i in range(len(information_count) - 1)]
  421. k = 0
  422. for i in interval:
  423. if i < 5 * 60:
  424. k += 1
  425. if len(information_count) >= 22 and k == 0:
  426. infor_jg_count = [1, f"数据条数为{str(len(information_count))},无小于5分钟的数据间隔"]
  427. elif len(information_count) >= 22 and k ==1:
  428. infor_jg_count = [1, f"数据条数{str(len(information_count))},其中有小于5分钟的数据间隔{str(k)}条"]
  429. elif len(information_count) >= 22 and k >=2:
  430. infor_jg_count = [0, f"数据条数{str(len(information_count))},其中有小于5分钟的数据间隔{str(k)}条"]
  431. else:
  432. infor_jg_count = [0, f"数据条数{str(len(information_count))}"]
  433. # 电路板固件版本号 RTU固件版本号
  434. rtus = []
  435. gujians = []
  436. for d in dver_lst:
  437. rtu = d.split("-")[-1]
  438. gujian = d.replace(rtu, "").replace("-", "")
  439. # if gujian == self.set_stm8vs:
  440. gujians.append(gujian)
  441. # if rtu == self.set_dver:
  442. rtus.append(rtu)
  443. rtus = list(set(rtus))
  444. gujians = list(set(gujians))
  445. if len(gujians) == 1 and gujians[0] == self.set_stm8vs:
  446. gujian_num = [1, self.set_stm8vs]
  447. else:
  448. if len(gujians) == 1:
  449. gujian_num = [0, gujians[0]]
  450. else:
  451. gujian_num = [0, ",".join(gujians)]
  452. if len(rtus) == 1 and rtus[0] == self.set_dver:
  453. rtu_num = [1, self.set_dver]
  454. else:
  455. if len(rtus) == 1:
  456. rtu_num = [0, rtus[0]]
  457. else:
  458. rtu_num = [0, ",".join(rtus)]
  459. # 工作时长 判定
  460. if self.set_power == "DC":
  461. power_pass = []
  462. for i in total_time:
  463. if i not in power_pass:
  464. power_pass.append(i)
  465. if len(power_pass) == 1 and power_pass[0] == 4:
  466. time_jg = [1, "4"]
  467. else:
  468. if len(power_pass) > 1:
  469. time_jg = [0, ",".join([str(i) for i in power_pass])]
  470. if self.set_power == "AC":
  471. power_pass = []
  472. for i in total_time:
  473. if i not in power_pass:
  474. power_pass.append(i)
  475. if len(power_pass) == 1 and power_pass[0] == 9:
  476. time_jg = [1, "9"]
  477. else:
  478. if len(power_pass) > 1:
  479. time_jg = [0, ",".join([str(i) for i in power_pass])]
  480. return [
  481. device_id_info,
  482. [1, self.set_order],
  483. card_jg,
  484. lng_jg,
  485. lat_jg,
  486. work_jg,
  487. gujian_num,
  488. rtu_num,
  489. v_vs,
  490. tr_k_jg,
  491. rain_k_jg,
  492. infor_jg_count,
  493. heat_temp,
  494. en_temp,
  495. en_hum,
  496. current_jg,
  497. up_jg,
  498. down_jg,
  499. lig_jg,
  500. img_jg,
  501. machine_jg,
  502. camera_jg,
  503. time_jg
  504. ]
  505. def _imageToMatrix(self, image):
  506. """
  507. 根据名称读取图片对象转化矩阵
  508. :param strName:
  509. :return: 返回矩阵
  510. """
  511. imgMat = np.matrix(image)
  512. return imgMat
  513. def preImgOps(self, img):
  514. """
  515. 图像的预处理操作
  516. :param img: 图像的而明朝
  517. :return: 灰度化和resize之后的图片对象
  518. """
  519. # 预处理操作
  520. reImg = cv2.resize(img, (300, 400), interpolation=cv2.INTER_CUBIC) #
  521. img2gray = cv2.cvtColor(reImg, cv2.COLOR_BGR2GRAY) # 将图片压缩为单通道的灰度图
  522. return reImg,img2gray
  523. def ReadImage(self, im_file):
  524. """
  525. 读取图片
  526. :param im_file: 图像的路径
  527. :return: 利用opencv读取的完整图像img 托虫板内接四边形图像cutimg 内接四边形的坐标c[xmin,ymin,xmax,ymax]
  528. """
  529. img = cv2.imdecode(np.fromfile(im_file, dtype=np.uint8), cv2.IMREAD_COLOR)
  530. # imgfile = np.asarray(bytearray(im_file.read()), dtype="uint8")
  531. # img = cv2.imdecode(imgfile, cv2.IMREAD_ANYCOLOR)
  532. ImgShape = img.shape
  533. print("原始图像大小{}".format(ImgShape))
  534. center = [ImgShape[1]/2,ImgShape[0]/2] #圆盘中心
  535. print("图像中心位置{}".format(center))
  536. radius = int(ImgShape[0]/2) #圆盘半径
  537. print("半径{}".format(radius))
  538. length = pow(2,0.5)*radius #圆的内接正方形边长
  539. # print(length)
  540. Size = int(length/2)
  541. xmin = int(center[0] - Size)
  542. xmax = int(center[0] + Size)
  543. ymin = int((center[1] - Size)*1.1)
  544. ymax = int(center[1] + Size)
  545. c = [xmin,ymin,xmax,ymax]
  546. # print(c)
  547. cutimg = img[ymin:ymax,xmin:xmax]
  548. # img = cv2.imdecode(imgfile, cv2.IMREAD_ANYCOLOR)
  549. return img,cutimg,c
  550. def getFileName(self, imageFile):
  551. url, FileName = os.path.split(imageFile)
  552. # print(FileName)
  553. tamp = []
  554. tamp.append(FileName)
  555. return tamp
  556. #图像清晰度检测
  557. def predict(self, imageFile):
  558. """
  559. 图像清晰度检测
  560. Args:
  561. imageFile(dir or file):单张图片或者存放图片的文件夹
  562. """
  563. print(imageFile)
  564. # return str(len(dirs))
  565. result = [] #存放清晰度评分
  566. imgList = [] #存放识别后图片
  567. if os.path.isdir(imageFile):
  568. imageFileList = [os.path.join(imageFile,x) for x in os.listdir(imageFile)]
  569. print("imageFileList",imageFileList)
  570. for image in imageFileList:
  571. print(image)
  572. img,cutimg,c = self.ReadImage(image)
  573. reImg, img2gray= self.preImgOps(cutimg)
  574. f = self._imageToMatrix(img2gray)
  575. tmp = filters.sobel(f)
  576. source=np.sum(tmp**2)
  577. source=np.sqrt(source)
  578. result.append(source)
  579. imgList.append(img)
  580. elif os.path.isfile(imageFile):
  581. img,cutimg,c = self.ReadImage(imageFile)
  582. reImg, img2gray= self.preImgOps(cutimg)
  583. f = self._imageToMatrix(img2gray)
  584. tmp = filters.sobel(f)
  585. source=np.sum(tmp**2)
  586. source=np.sqrt(source)
  587. result.append(source)
  588. imgList.append(img)
  589. return result
  590. def __siqing_verify(self, data_result,status_result, status_all_result, alarm_result, device_id_info, image_score, process):
  591. """获取四情平台查询结果"""
  592. current_jg = [1,"无电流不足数据上报"] # 振动电机工作状态下电流匹配度
  593. up_jg = [1,"无电流不足数据上报"] # 上仓门电机电机工作状态
  594. down_jg = [1,"无电流不足数据上报"] # 下仓门电机电机工作状态
  595. lig_jg = [1,"无电流不足数据上报"] # 灯管工作状态下
  596. machine_jg = [1, "无电流不足数据上报"]# 电机工作状态
  597. camera_jg = [1, "无电流不足数据上报"] # 相机工作状态
  598. time_jg = [1, "合格"] # 工作时长
  599. current_jg_ct, up_jg_ct, down_jg_ct, lig_jg_ct, camera_jg_ct = 0,0,0,0,0
  600. if alarm_result:
  601. for alerm in alarm_result:
  602. a = alerm.get("alarm_desc", "")
  603. if a:
  604. try:
  605. a = eval(a)
  606. except Exception as e:
  607. a = json.loads(a)
  608. if a.get("type", "") == "震动电机":
  609. if a.get("status") == "电流不足":
  610. current_jg_ct += 1
  611. elif a.get("type", "") == "上仓门电机":
  612. if a.get("status") in ["打开电流不足", "关闭电流不足"]:
  613. up_jg_ct += 1
  614. elif a.get("type", "") == "下仓门电机":
  615. if a.get("status") in ["打开电流不足", "关闭电流不足"]:
  616. down_jg_ct += 1
  617. elif a.get("type", "") == "灯管":
  618. if a.get("status") == "电流不足":
  619. lig_jg_ct += 1
  620. elif a.get("type", "") == "相机":
  621. if a.get("status") == "电流不足":
  622. camera_jg_ct += 1
  623. if current_jg_ct:
  624. current_jg = [0,f"有{str(current_jg_ct)}条电流不足数据上报记录"]
  625. if up_jg_ct:
  626. up_jg = [0,f"有{str(up_jg_ct)}条电流不足数据上报记录"]
  627. if down_jg_ct:
  628. down_jg = [0,f"有{str(down_jg_ct)}条电流不足数据上报记录"]
  629. if lig_jg_ct:
  630. lig_jg = [0,f"有{str(lig_jg_ct)}条电流不足数据上报记录"]
  631. if camera_jg_ct:
  632. camera_jg = [0,f"有{str(camera_jg_ct)}条电流不足数据上报记录"]
  633. lng_lst = [] # 经度
  634. lat_lst = [] # 纬度
  635. tr_k_jg_lst = [] # 温控
  636. rain_k_jg_lst = []# 雨控
  637. infor_jg_count = 0 # 上报信息条数
  638. heat_temp_lst = []# 加热仓温度
  639. temp_hum = [] # 环境温度 环境湿度
  640. total_time = [] # 总时长
  641. information_count = 0
  642. for index, cur in enumerate(data_result):
  643. upl_time_str = cur.get("upl_time", "0")
  644. upl_time_int = int(time.mktime(upl_time_str.timetuple()))
  645. infor_start = 0
  646. if index == 0:
  647. infor_start = upl_time_int
  648. else:
  649. if upl_time_int < 3600 * 10 + infor_start:
  650. lamp = device_data.get("lamp", "")
  651. if lamp == "0":
  652. information_count += 1
  653. device_data = cur.get("cbd_data", "")
  654. if device_data:
  655. device_data = ast.literal_eval(device_data)
  656. lng = device_data.get("lng", "")
  657. lng_lst.append(float(lng))
  658. lat = device_data.get("lat", "")
  659. lat_lst.append(float(lat))
  660. # v_vs_lst.append(float(device_data.get("vbat", 0)))
  661. tr_k_jg_lst.append(device_data.get("tps", ""))
  662. rain_k_jg_lst.append(device_data.get("rps", ""))
  663. infor_jg_count += 1
  664. heat_temp_lst.append(float(device_data.get("hrt", 0)))
  665. temp_hum.append({"at": device_data.get("at", ""), "ah": device_data.get("ah", "")})
  666. if self.set_power == "AC":
  667. total_time.append(device_data.get("tt"))
  668. elif self.set_power == "DC":
  669. st = device_data.get("st", "00:00")
  670. et = device_data.get("et", "00:00")
  671. st = int(st.split(":")[0])
  672. et = int(et.split(":")[0])
  673. if st > et:
  674. total = 24 - st + et
  675. else:
  676. total = et - st
  677. total_time.append(total)
  678. # 经度
  679. lng_pass = [i for i in lng_lst if 113.76194444 <= i <= 113.77861111]
  680. if len(lng_pass) != len(lng_lst):
  681. lng_jg = [0,f"不符合条件的数据有{str(len(lng_lst) - len(lng_pass))}条"]
  682. else:
  683. lng_jg = [1, f"共{str(len(lng_pass))}条符合条件"]
  684. # 纬度 35.02083333,35.0375
  685. lat_pass = [i for i in lat_lst if 35.02083333 <=i <=35.0375]
  686. if len(lat_pass) != len(lat_lst):
  687. lat_jg = [0,f"不符合条件的数据有{str(len(lat_lst) - len(lat_pass))}条"]
  688. else:
  689. lat_jg = [1, f"共{str(len(lat_lst))}条符合条件"]
  690. # 温控
  691. if "1" in tr_k_jg_lst:
  692. tr_k_jg = [1, f"有{str(tr_k_jg_lst.count('1'))}条上报记录"]
  693. else:
  694. tr_k_jg = [0, f"无上报记录"]
  695. # 雨控
  696. if "1" in rain_k_jg_lst:
  697. rain_k_jg = [1, f"有{str(rain_k_jg_lst.count('1'))}条上报记录"]
  698. else:
  699. rain_k_jg = [0, "无上报记录"]
  700. # 加热仓温度
  701. heat_temp = []
  702. for h in heat_temp_lst:
  703. if 85 <= h <= 105:
  704. heat_temp = [1, f"温度为{str(h)}符合条件"]
  705. break
  706. if not heat_temp:
  707. heat_temp = [0, "没有符合温度的记录"]
  708. # 环境温度
  709. if {"at": "25", "ah": "35"} in temp_hum:
  710. en_temp = [0,"存在等于25度且环境湿度等于35的数据"]
  711. else:
  712. en_temp = [1,"符合要求"]
  713. # 环境湿度
  714. if {"at": "35", "ah": "25"} in temp_hum:
  715. en_hum = [0,"存在等于35且环境温度等于25的"]
  716. else:
  717. en_hum = [1,"符合要求"]
  718. # 图片质量
  719. if image_score > 68:
  720. img_jg = [1,"合格"]
  721. else:
  722. img_jg = [0,"不合格"]
  723. # 上报信息条数
  724. if information_count >= 22:
  725. infor_jg_count = [1, f"上报信息条数为{str(information_count)}"]
  726. else:
  727. infor_jg_count = [0, f"上报信息条数为{str(information_count)}小于22"]
  728. iccid = ""
  729. work_status = [] # 工作状态切换
  730. elec_vs_lst = [] # 电路板固件版本号
  731. for index, cur in enumerate(status_all_result):
  732. device_data = cur.get("cbd_status", "")
  733. if device_data:
  734. device_data = ast.literal_eval(device_data)
  735. iccid = device_data.get("iccid", "")
  736. work_status.append(str(device_data.get("ws", "")))
  737. elec_vs_lst.append(device_data.get("dver", ""))
  738. # 电路板固件版本号 RTU固件版本号
  739. rtus = []
  740. gujians = []
  741. for d in elec_vs_lst:
  742. rtu = d.split("-")[-1]
  743. gujian = d.replace(rtu, "").replace("-", "")
  744. # if gujian == self.set_stm8vs:
  745. gujians.append(gujian)
  746. # if rtu == self.set_dver:
  747. rtus.append(rtu)
  748. rtus = list(set(rtus))
  749. gujians = list(set(gujians))
  750. if len(gujians) == 1 and gujians[0] == self.set_stm8vs:
  751. gujian_num = [1, self.set_stm8vs]
  752. else:
  753. if len(gujians) == 1:
  754. gujian_num = [0, gujians[0]]
  755. else:
  756. gujian_num = [0, ",".join(gujians)]
  757. if len(rtus) == 1 and rtus[0] == self.set_dver:
  758. rtu_num = [1, self.set_dver]
  759. else:
  760. if len(rtus) == 1:
  761. rtu_num = [0, rtus[0]]
  762. else:
  763. rtu_num = [0, ",".join(rtus)]
  764. # 工作状态切换
  765. work_status_str = "".join(work_status)
  766. wr = work_status_str.count("01")
  767. if wr > 4:
  768. work_jg = [1, f"工作状态切换成功的有{str(wr)}次"]
  769. else:
  770. work_jg = [0, f"工作状态切换成功的只有{str(wr)}次"]
  771. # 检查卡号及有效期
  772. card_jg = self.sim_info(iccid)
  773. # total_time 判定
  774. if self.set_power == "DC":
  775. power_pass = [i for i in total_time if i == 4]
  776. if len(power_pass) == len(total_time):
  777. time_jg = [1, f"共{str(len(power_pass))}条记录均符合要求"]
  778. else:
  779. time_jg = [0, f"共{str(len(total_time) - len(power_pass))}条记录不符合要求"]
  780. if self.set_power == "AC":
  781. power_pass = [i for i in total_time if i == 9]
  782. if len(power_pass) == len(total_time):
  783. time_jg = [1, f"共{str(len(power_pass))}条记录均符合要求"]
  784. else:
  785. time_jg = [0, f"共{str(len(total_time) - len(power_pass))}条记录不符合要求"]
  786. return [
  787. device_id_info,
  788. [1, self.set_order],
  789. card_jg,
  790. lng_jg,
  791. lat_jg,
  792. work_jg,
  793. gujian_num,
  794. rtu_num,
  795. [0, "数据不存在"],
  796. tr_k_jg,
  797. rain_k_jg,
  798. infor_jg_count,
  799. heat_temp,
  800. en_temp,
  801. en_hum,
  802. current_jg,
  803. up_jg,
  804. down_jg,
  805. lig_jg,
  806. img_jg,
  807. machine_jg,
  808. camera_jg,
  809. time_jg
  810. ]
  811. def __bigdata_iamge_verify(self, device_id):
  812. # 对图片质量进行打分并求平均值
  813. scores_time = {}
  814. photo_obj = self.cbd_photo.find({"device_id":str(device_id), 'addtime': {"$gte":self.start_time ,"$lte":self.end_time}})
  815. for p in photo_obj[:5]:
  816. photo_addr = p.get("addr")
  817. addtime = p.get("addtime")
  818. # 把图片下载到本地
  819. local_dir = "org_image"
  820. file_name = photo_addr.split("/")[-1]
  821. file_name = file_name.replace("?", "")
  822. os.makedirs(local_dir) if not os.path.exists(local_dir) else None
  823. response = requests.get(f"https://bigdata-image.oss-cn-hangzhou.aliyuncs.com/Basics/cbd/{photo_addr}")
  824. with open(os.path.join(local_dir, file_name), 'wb') as f:
  825. f.write(response.content)
  826. result_score = self.predict(os.path.join(local_dir, file_name))
  827. avg_score = sum(result_score)/len(result_score)
  828. scores_time[str(addtime)] = avg_score
  829. return scores_time
  830. def __siqing_image_verify(self, device_id):
  831. # 对图片质量进行打分并求平均值
  832. scores_time = {}
  833. sql = "SELECT * FROM AppInfoManage_cbdphoto WHERE equip_id_id='{}' AND upl_time BETWEEN '{}' AND '{}' order by 'alarm_time';".format(device_id,self.start_time_str,self.end_time_str)
  834. self.cursor.execute(sql)
  835. photo_obj = self.cursor.fetchall()
  836. for p in photo_obj[:5]:
  837. photo_addr = p.get("addr")
  838. addtime = p.get("addtime")
  839. # 把图片下载到本地
  840. local_dir = "org_image"
  841. file_name = photo_addr.split("/")[-1]
  842. os.makedirs(local_dir) if not os.path.exists(local_dir) else None
  843. response = requests.get(photo_addr)
  844. with open(os.path.join(local_dir, file_name), 'wb') as f:
  845. f.write(response.content)
  846. result_score = self.predict(os.path.join(local_dir, file_name))
  847. avg_score = sum(result_score)/len(result_score)
  848. scores_time[str(addtime)] = avg_score
  849. return scores_time
  850. def run(self):
  851. """主业务逻辑,涉及进度条不能模块化,慢慢捋"""
  852. proess = 0
  853. now_time = datetime.datetime.now()
  854. global save_filename
  855. save_filename = self.set_order + "_" + now_time.strftime("%m%d") + "测报灯检验.xlsx"
  856. save_path = os.path.join(self.save_path,save_filename)
  857. workbook = Workbook(save_path)
  858. worksheet = workbook.add_worksheet()
  859. worksheet.set_row(0, 50)
  860. worksheet.set_row(1, 37.5)
  861. worksheet.set_row(2, 50)
  862. worksheet.set_row(3, 100)
  863. for i in range(len(self.device_list)):
  864. worksheet.set_row(i+4, 30)
  865. worksheet.set_column(0, 26, 24)
  866. toji_style = workbook.add_format(toji_format)
  867. title_style = workbook.add_format(title_format)
  868. explain_style = workbook.add_format(explain_formal)
  869. formal_style = workbook.add_format(formal_format)
  870. error_style = workbook.add_format(error_format)
  871. common_style = workbook.add_format(common_format)
  872. merge_title_style = workbook.add_format(merge_title_format)
  873. worksheet.merge_range('A1:Y1',"物联网测报灯在线检验原始表格",merge_title_style)
  874. title_data = [
  875. "文档ID","设备ID", "任务单号", "卡号及有效期","经度","纬度","工作状态切换", "电路板固件版本号","RTU固件版本号",
  876. "电路板输入电压","温控","雨控","上报信息条数","加热仓温度","环境温度","环境湿度","振动电机工作状态下 \n电流匹配度",
  877. "上仓门电机电机工作状态下 \n电流匹配度","下仓门电机工作状态下 \n电流匹配度","灯管工作状态下 \n电流匹配度","图片质量",
  878. "清扫电机/转盘电机工作状态下的 \n最大电流","相机工作状态下 \n电流匹配度", "工作时长", "综合判定"
  879. ]
  880. worksheet.write_row(row = 2 ,col = 0, data = title_data,cell_format=title_style)
  881. explain_data = [
  882. "/",
  883. "后台显示与输入一致为合格,否则为不合格",
  884. "按照输入文件的任务单为依据复制到此列",
  885. "有显示卡号及有效期即为合格,否则为不合格",
  886. "合格条件(绿色):\n113°46′13″±30″范围内,转为十进度为:(113.76194444,113.77861111)区间内",
  887. "合格条件(绿色):\n35°1′45″±30″范围内,转为十进度为:(35.02083333,35.0375)区间内",
  888. "合格条件(绿色):\n测试时间段内有待机/工作且出现4次以上循环",
  889. "合格条件(绿色):\n后台上报结果与输入标准对照,相符则合格,其余则不合格",
  890. "合格条件(绿色):\n后台上报结果与输入标准对照,相符则合格,其余则不合格",
  891. "合格条件(绿色):\n电路板输入电压:22~30V",
  892. "合格条件(绿色):\n测试时间段之前至少有一条被温控数据上报",
  893. "合格条件(绿色):\n测试时间段内至少有一条被雨控数据上报",
  894. "合格条件(绿色):\n检测时间大于10h,在灯管状态栏内出现“工作”状态至少大于22条,不允许出现上传间隔小于5分钟的条数2条",
  895. "合格条件(绿色):\n上传的加热温度包含但不局限于85~105°之间的值",
  896. "合格条件(绿色):\n等于35且环境温度等于25的前提下为不合格,其余显示的任何值为合格",
  897. "合格条件(绿色):\n等于25度且环境湿度等于35的前提下为不合格,其余显示的任何值为合格",
  898. "合格条件(绿色):\n在工作时间段内没有接收到“电流不足”的信息为合格,否则不合格",
  899. "合格条件(绿色):\n在工作时间段内没有接收到“电流不足”的信息为合格,否则不合格",
  900. "合格条件(绿色):\n在工作时间段内没有接收到“电流不足”的信息为合格,否则不合格",
  901. "合格条件(绿色):\n在工作时间段内没有接收到“电流不足”的信息为合格,否则不合格",
  902. "合格条件(绿色):\n对自动检查前上传的图片质量进行打分,平均分数大于68分为合格,否则,不合格",
  903. "合格条件(绿色):\n在工作时间段内没有接收到“电流不足”的信息为合格,否则不合格",
  904. "合格条件(绿色):\n在工作时间段内没有接收到“电流不足”的信息为合格,否则不合格",
  905. "合格条件(绿色):\n与供电选择输入对照,(DC为4h,AC为9h)一致判定为合格,否则为不合格",
  906. "合格条件(绿色):\nd:y列全部合格为合格,否则为不合格"
  907. ]
  908. worksheet.write_row(row = 3 ,col = 0, data = explain_data,cell_format=explain_style)
  909. formal_counts = 0
  910. verify_list = []
  911. for index, short_id in enumerate(self.device_list):
  912. short_id = str(short_id).strip() # 把device_id转换成字符串并去除空格
  913. d_id,deviceId,platform = self.device_their_platform(short_id)
  914. if short_id != deviceId:
  915. device_id_info = [0, "不合格"]
  916. else:
  917. device_id_info = [1, "合格"]
  918. worksheet.write(index+4,0,short_id,formal_style)
  919. if platform == "大数据平台":
  920. try:
  921. worksheet.write(index+4,1,deviceId,formal_style)
  922. self.mongo_ping()
  923. data_status = self.cbd_alerm.find({"equip_id": deviceId, "alarm_time": {"$gte":self.start_time ,"$lte":self.end_time}}).sort([('alarm_time', pymongo.DESCENDING)])
  924. data_cursor = self.cbd_collection.find({"device_id":d_id,'addtime': {"$gte":self.start_time ,"$lte":self.end_time}}).sort([('addtime', pymongo.DESCENDING)])
  925. data_counts = data_cursor.count()
  926. image_score = self.__bigdata_iamge_verify(d_id)
  927. if data_counts == 0:
  928. for i in range(1,24):
  929. worksheet.write(index+4,i,"搜索时间内无数据",error_style)
  930. worksheet.write(index+4,24,"不合格",error_style)
  931. danji_verify = []
  932. for i in range(12):
  933. danji_verify.append(0)
  934. verify_list.append(danji_verify)
  935. else:
  936. danji_verify = []
  937. verify_data = self.__bigdata_verify(data_cursor,data_status, device_id_info, image_score, proess)
  938. for clo_index, verify_ in enumerate(verify_data):
  939. danji_verify.append(verify_[0])
  940. if verify_[0] == 0:
  941. worksheet.write(index+4,clo_index+1,verify_[1],error_style)
  942. elif verify_[0] == 1:
  943. worksheet.write(index+4,clo_index+1,verify_[1],formal_style)
  944. else:
  945. worksheet.write(index+4,clo_index+1,verify_[1],common_style)
  946. if 0 in danji_verify:
  947. worksheet.write(index+4,24,"不合格",error_style)
  948. else:
  949. formal_counts += 1
  950. worksheet.write(index+4,24,"合格",formal_style)
  951. verify_list.append(danji_verify)
  952. except Exception as e:
  953. print(e)
  954. elif platform == "四情平台":
  955. try:
  956. worksheet.write(index+4,1,deviceId,formal_style)
  957. self.sql_ping()
  958. data_sql = "SELECT * FROM AppInfoManage_cbddata WHERE equip_id_id='{}' AND upl_time BETWEEN '{}' AND '{}' order by upl_time;".format(deviceId,self.start_time_str,self.end_time_str)
  959. alarm_sql = "SELECT * FROM AppInfoManage_cbd_alarm_record WHERE equip_id_id='{}' AND alarm_time BETWEEN '{}' AND '{}' order by alarm_time;".format(deviceId,self.start_time_str,self.end_time_str)
  960. self.cursor.execute(data_sql)
  961. data_result = self.cursor.fetchall()
  962. self.cursor.execute(alarm_sql)
  963. alarm_result = self.cursor.fetchall()
  964. status_sql = "SELECT * FROM AppInfoManage_cbdstatus WHERE equip_id_id='{}' AND upl_time BETWEEN '{}' AND '{}' order by upl_time;".format(deviceId,self.start_time_str,self.end_time_str)
  965. self.cursor.execute(status_sql)
  966. status_result = self.cursor.fetchall()
  967. status_all_sql = "SELECT * FROM AppInfoManage_cbdstatus_all WHERE equip_id_id='{}' AND upl_time BETWEEN '{}' AND '{}' order by upl_time;".format(deviceId,self.start_time_str,self.end_time_str)
  968. self.cursor.execute(status_all_sql)
  969. status_all_result = self.cursor.fetchall()
  970. if len(data_result) == 0:
  971. # 空白数据填充
  972. for i in range(1,24):
  973. worksheet.write(index+4,i,"搜索时间内无数据",error_style)
  974. worksheet.write(index+4,15,"不合格",error_style)
  975. danji_verify = []
  976. for i in range(23):
  977. danji_verify.append(0)
  978. verify_list.append(danji_verify)
  979. else:
  980. image_score = self.__siqing_image_verify(deviceId)
  981. verify_data = self.__siqing_verify(data_result,status_result, status_all_result, alarm_result, device_id_info, image_score, process)
  982. danji_verify = []
  983. for clo_index, verify_ in enumerate(verify_data):
  984. danji_verify.append(verify_[0])
  985. if verify_[0] == 0:
  986. worksheet.write(index+4,clo_index+1,verify_[1],error_style)
  987. elif verify_[0] == 1:
  988. worksheet.write(index+4,clo_index+1,verify_[1],formal_style)
  989. else:
  990. worksheet.write(index+4,clo_index+1,verify_[1],common_style)
  991. if 0 in danji_verify:
  992. worksheet.write(index+4,24,"不合格",error_style)
  993. else:
  994. formal_counts += 1
  995. worksheet.write(index+4,24,"合格",formal_style)
  996. verify_list.append(danji_verify)
  997. except Exception as e:
  998. print(e)
  999. pass
  1000. toji_data = [
  1001. "任务单号",self.set_order,
  1002. "检验时间",'{}\n{}'.format(self.start_time_str,self.end_time_str),
  1003. "检验数量",len(self.device_list),
  1004. "合格数",formal_counts,
  1005. "检验平台",self.set_plat,
  1006. "主板版本",self.set_stm8vs,
  1007. "联网版本",self.set_dver,
  1008. "产品名称", self.set_product,
  1009. "供电选择", self.set_power,
  1010. "报告日期",now_time.strftime("%y-%m-%d %H:%M:%S")
  1011. ]
  1012. worksheet.write_row(row = 1 ,col = 0, data = toji_data,cell_format=toji_style)
  1013. # worksheet.protect(pwd_str) # 保护视图,不允许修改
  1014. workbook.close()
  1015. self.cursor.close()
  1016. self.connection.close()
  1017. self.myclient.close()
  1018. self.proess_signal.emit(100)
  1019. if __name__ == "__main__":
  1020. device_list = [
  1021. # "861551053998357", # 大数据平台
  1022. # "862991419825259" # 四情
  1023. "861551058841537",
  1024. "861551058861188",
  1025. "861551058840109"
  1026. # "861551058866203",
  1027. # "861551058865767"
  1028. ]
  1029. save_path = "F:\\质检工具处理文件\\新版临时处理"
  1030. start_time = "2023-06-24 8:30:00"
  1031. end_time = "2023-06-26 13:45:00"
  1032. # start_time = "2018-03-31 11:39:02"
  1033. # end_time = "2018-03-31 12:00:00"
  1034. set_plat = "大数据平台"
  1035. # set_plat = "四情平台"
  1036. start_time = datetime.datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S")
  1037. end_time = datetime.datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S")
  1038. SCDThread(device_list,save_path,start_time,end_time,set_plat,"1","1","1", "4.0测报灯", "AC").run()