Bladeren bron

更新气象站

yf_yzl 2 jaren geleden
bovenliggende
commit
15d724aabe

BIN
0722.xlsx


BIN
1_0722.xlsx


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


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


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


+ 4 - 1
bigdata_django/zhijian/cbd_zhijian.py

@@ -727,10 +727,11 @@ class CBDThread(QtCore.QThread):
         camera_jg = [1, "无电流不足信息"] # 相机工作状态
         current_jg_ct, up_jg_ct, down_jg_ct, lig_jg_ct, camera_jg_ct, machine_ct = 0,0,0,0,0,0
         for alerm in data_status:
+            alarm_time = datetime.datetime.fromtimestamp(alerm.get("alarm_time")).strftime("%Y-%m-%d %H:%M:%S")
             a = alerm.get("alarm_desc", "")
             if a:
                 a = json.loads(a)
-                print(a, "电流不足")
+                
                 if a.get("type", "") == "震动电机":
                     if "电流不足" in a.get("status"):
                         current_jg_ct += 1
@@ -747,6 +748,7 @@ class CBDThread(QtCore.QThread):
                     if "电流不足" in a.get("status"):
                         machine_ct += 1
                 elif a.get("type", "") == "相机":
+                    print(a, "电流不足", alarm_time)
                     if "电流不足" in a.get("status"):
                         camera_jg_ct += 1
         if current_jg_ct:
@@ -1263,6 +1265,7 @@ class CBDThread(QtCore.QThread):
         worksheet.set_row(1, 35)
         worksheet.set_row(2, 50)
         worksheet.set_row(3, 80)
+        from openpyxl.utils import get_column_letter
         for i in range(len(self.device_list)):
             worksheet.set_row(i+4, 15)
         worksheet.set_column(0, 26, 12)

+ 43 - 2
bigdata_django/zhijian/qxz_zhijian_new.py

@@ -1315,6 +1315,7 @@ function(uptime_list){
         for device_id in self.device_list:
             self.mongo_ping()
             element_dict = self.parse_data(device_id, qxz_conf_dict, vr_dict, device_data_dict, sim_data)
+
             not_qualified = 0
             for index, k in enumerate(title_name_list):
                 status, msg = 3, "无数据"
@@ -1326,10 +1327,50 @@ function(uptime_list){
                     elif key in default_func_dict:
                         rt = default_func_dict[key](value)
                     else:
-                        rt = self.cond.cond_msg_dict[key](value)
+                        if key == "日照时数":
+                            print(key)
+                            idevice_key_sun = ""
+                            device_config = self.db.sa_qxz_conf.find_one({"device_id": device_id}, {'_id':0,'id':0})
+                            device_data = self.db.sa_qxz_data.find({"device_id": device_id, "uptime": {"$gte": self.start_time, "$lte": self.end_time}})
+                            device_config = dict(device_config)
+                            print(rt, "===============3=============")
+                            for iname, ivalue in device_config.items():
+                                if ivalue and isinstance(ivalue, str):
+                                    if "日照时数" in ivalue:
+                                        idevice_key_sun = iname
+                            idevice_data = []
+                            print(rt, "===============2=============")
+                            for d in device_data:
+                                idevice_data.append(float((d.get(idevice_key_sun)).split("#")[0]))
+                            if max(idevice_data) > 0.1:
+                                rt = {'status': 1, 'msg': f'最大值:{str(max(idevice_data))},最小值:{str(min(idevice_data))}'}
+                            else:
+                                rt = {'status': 0, 'msg': f'最大值:{str(max(idevice_data))},最小值:{str(min(idevice_data))}'}
+                            print(rt, "===============1=============")
+                        elif key == "降雨量累计":
+                            print(key)
+                            idevice_key_rain = ""
+                            device_config = self.db.sa_qxz_conf.find_one({"device_id": device_id}, {'_id':0,'id':0})
+                            device_data = self.db.sa_qxz_data.find({"device_id": device_id, "uptime": {"$gte": self.start_time, "$lte": self.end_time}})
+                            device_config = dict(device_config)
+                            for iname, ivalue in device_config.items():
+                                if ivalue and isinstance(ivalue, str):
+                                    if "降雨量累计" in ivalue:
+                                        idevice_key_rain = iname
+                            print(rt, "===============31=============")
+                            idevice_data = []
+                            for d in device_data:
+                                idevice_data.append(float((d.get(idevice_key_rain)).split("#")[0]))
+                            print(rt, "===============21=============")
+                            if max(idevice_data) > 0.1:
+                                rt = {'status': 1, 'msg': f'最大值:{str(max(idevice_data))},最小值:{str(min(idevice_data))}'}
+                            else:
+                                rt = {'status': 0, 'msg': f'最大值:{str(max(idevice_data))},最小值:{str(min(idevice_data))}'}
+                            print(rt, "===============2=============")
+                        else:
+                            rt = self.cond.cond_msg_dict[key](value)
                     status, msg = rt['status'], rt['msg']
                 except Exception as e:
-                    print('-----------', e)
                     pass
 
                 if status == 0:

+ 112 - 0
bigdata_django/zhijian/score_img.py

@@ -0,0 +1,112 @@
+import sys
+from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QPushButton, QFileDialog
+import os 
+import numpy as np
+import cv2
+from skimage import filters
+
+
+class ImageFileViewer(QWidget):
+    def __init__(self):
+        super().__init__()
+        self.setGeometry(100, 100, 500, 500)  # 设置窗口大小和位置
+        self.setWindowTitle("图片打分工具")
+
+        self.layout = QVBoxLayout()
+        self.label = QLabel("暂无图片")
+        self.button = QPushButton("请选择图片")
+        self.button.clicked.connect(self.select_image)
+
+        self.layout.addWidget(self.label)
+        self.layout.addWidget(self.button)
+
+        self.setLayout(self.layout)
+
+
+    def _imageToMatrix(self, image):
+            """
+            根据名称读取图片对象转化矩阵
+            :param strName:
+            :return: 返回矩阵
+            """
+            imgMat = np.matrix(image)
+            return imgMat
+
+    def preImgOps(self, img):
+            """
+            图像的预处理操作
+            :param img: 图像的而明朝
+            :return: 灰度化和resize之后的图片对象
+            """
+            # 预处理操作
+            try:
+                reImg = cv2.resize(img, (300, 400), interpolation=cv2.INTER_CUBIC)  #
+                img2gray = cv2.cvtColor(reImg, cv2.COLOR_BGR2GRAY)  # 将图片压缩为单通道的灰度图
+                return reImg,img2gray, True
+            except Exception as e:
+                return None, None, False
+
+    def ReadImage(self, im_file):
+        """
+            读取图片
+            :param im_file: 图像的路径
+            :return: 利用opencv读取的完整图像img  托虫板内接四边形图像cutimg   内接四边形的坐标c[xmin,ymin,xmax,ymax] 
+        """
+        try:
+            img = cv2.imdecode(np.fromfile(im_file, dtype=np.uint8), cv2.IMREAD_COLOR)
+            ImgShape = img.shape
+            center = [ImgShape[1]/2,ImgShape[0]/2] #圆盘中心
+            radius = int(ImgShape[0]/2) #圆盘半径
+            length = pow(2,0.5)*radius    #圆的内接正方形边长
+            Size = int(length/2)
+            xmin = int(center[0] - Size)
+            xmax = int(center[0] + Size)
+            ymin = int((center[1] - Size)*1.1)
+            ymax = int(center[1] + Size)
+            c = [xmin,ymin,xmax,ymax]
+            cutimg = img[ymin:ymax,xmin:xmax]
+            return img,cutimg,c, True
+        except Exception as e:
+            return None, None, None, False
+
+    def getFileName(self, imageFile):
+        url, FileName = os.path.split(imageFile)
+        tamp = []
+        tamp.append(FileName)
+        return tamp
+
+    #图像清晰度检测
+    def predict(self, imageFile):
+        """
+        图像清晰度检测
+        Args:
+            imageFile(dir or file):单张图片或者存放图片的文件夹
+        """
+        result = [] #存放清晰度评分
+        imgList = [] #存放识别后图片
+        if os.path.isfile(imageFile):
+                img,cutimg,c, is_get = self.ReadImage(imageFile)
+                if is_get:
+                    reImg, img2gray, is_imgs= self.preImgOps(cutimg)
+                    if is_imgs:
+                        f = self._imageToMatrix(img2gray)
+                        tmp = filters.sobel(f)
+                        source=np.sum(tmp**2)
+                        source=np.sqrt(source)
+                        result.append(source)
+                        imgList.append(img)
+        return result
+
+    def select_image(self):
+        file_dialog = QFileDialog()
+        image_file, _ = file_dialog.getOpenFileName(self, "选择图片", "", "支持图片格式 (*.png *.jpg *.jpeg)")
+        if image_file:
+            result = self.predict(image_file)
+            self.label.setText(f"图片 {image_file.split('/')[-1]}:\n得分 {result[0]}")
+
+
+if __name__ == "__main__":
+    app = QApplication(sys.argv)
+    viewer = ImageFileViewer()
+    viewer.show()
+    sys.exit(app.exec_())