林轩 1 год назад
Родитель
Сommit
be21cde7cb

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+__pycache__
+*.pyc
+.vscode





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


+ 2 - 2
bigdata_django/zhijian/cbd_zhijian.py

@@ -585,7 +585,7 @@ class CBDThread(QtCore.QThread):
     def __bigdata_iamge_verify(self, device_id):
         # 对图片质量进行打分并求平均值
         scores_time = {}
-        photo_obj = self.cbd_photo.find({"device_id":str(device_id), 'addtime': {"$gte": int(self.start_time) - 3600 * 48,"$lte":self.start_time}})
+        photo_obj = self.cbd_photo.find({"device_id":str(device_id), 'addtime': {"$gte": int(self.start_time) - 3600 * 4,"$lte":self.start_time}})
         for p in photo_obj:
             photo_addr = p.get("addr")
             addtime = p.get("addtime")
@@ -921,7 +921,7 @@ class CBDThread(QtCore.QThread):
                 else:
                     img_jg = [1, ",".join(score)]
             else:
-                img_jg = [0, "输入开始时间前48h内无图片"]
+                img_jg = [0, "输入开始时间前4h内无图片"]
         else:
             img_jg = [1, ""]
         # 上报信息条数

BIN
tools/example.xlsx


+ 47 - 31
tools/test_http_mqtt.py

@@ -1,31 +1,47 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-#
-import os
-import time
- 
-threshold = 120
-# 获取前一分钟的结果
-date = time.strftime('%Y:%H:%M', time.localtime(time.time()-60))
-filename = '/usr/share/nginx/logs/geokon.access.log '
- 
-def popen(command):
-    return os.popen(command).readlines()
- 
-def main():
-    with open('/tmp/ipset.txt', 'a') as f:
-        f.write('%s: 日志搜索...........\n' % (date))
-        command = "grep %s %s | awk '{counts[$1]++}; END {for(url in counts) print counts[url], url}'" % (date, filename)
-        for ip in popen(command):
-            num, ipaddr = ip.split(' ')
-            num, ipaddr = int(num), ipaddr.strip()  # 第一个值是整型, 第二个值应当去掉空格
-            if num >= threshold:
-                if all(popen('ipset list | grep %s' % (ipaddr))):  # 如果不为true 那就添加
-                    f.write('每分钟大于%s次 地址: %s 将被禁止访问' % (threshold, ipaddr))
-                    popen('ipset add blacklist %s timeout 3600 &>/dev/null' % (ipaddr))
-            elif num >= 50:
-                f.write('访问次数 %s: %s\n' % (num, ipaddr))
-        f.write('日志搜索结束.................\n\n\n')
- 
-if __name__ == '__main__':
-    main()
+import pymysql
+import requests
+import json
+
+
+db = pymysql.connect(
+    # host='172.16.15.167',
+    host='114.55.0.7',
+    user='root',
+    port=3306,
+    password='yfkj@6020',
+    database='bigdata_api',
+    charset='utf8mb4'
+)
+cursor = db.cursor()
+
+address_info_id_sql = """
+
+    select cityid from address_info
+"""
+
+address_ids = cursor.execute(address_info_id_sql)
+cityids = [i[0] for i in cursor.fetchall()]
+print(len(cityids))
+
+city_sql = """
+    select id, cityZh, provinceZh, leaderZh, lat, lon from city
+"""
+
+city_ids = cursor.execute(city_sql)
+ids = [(i[0])[2:] for i in cursor.fetchall()]
+print(len(ids))
+for i in ids:
+    if i not in cityids:
+        sql = """
+            select id, cityZh, provinceZh, leaderZh, lat, lon from city where id = %s
+        """
+        cursor.execute(sql, ("CN" + id, ))
+        c = cursor.fetchone()
+        print(c)
+        lat, lon = c[-2], c[-1]
+        ret = requests.post("http://api.map.baidu.com/geocoder?location=%s,%s&coord_type=gcj02&output=json"%(lat,lon))
+        ret_json = json.loads(ret.text)
+        province, city, district = ret_json["result"]["addressComponent"]["province"], \
+                                ret_json["result"]["addressComponent"]["city"], \
+                                ret_json["result"]["addressComponent"]["district"]
+        print(province, city, district)

+ 95 - 0
tools/yumi_taozhu.py

@@ -0,0 +1,95 @@
+import pymongo
+from urllib import parse
+import re 
+from openpyxl import load_workbook
+import datetime
+# 打开Excel文件
+workbook = load_workbook('tools\example.xlsx')
+
+# 获取工作表
+sheet = workbook['Sheet1']
+
+
+user = parse.quote_plus("root")
+passwd = parse.quote_plus("yfkj@6020")
+host = parse.quote_plus("8.136.98.49")
+port = "57017"
+myclient = pymongo.MongoClient("mongodb://{0}:{1}@{2}:{3}/".format(user,passwd, host, port))
+db = myclient.smartfarming
+cbd_photo = db.sa_device_cbdphoto
+device = db.sa_device
+start = 1640966400
+end = 1672502399
+photo = cbd_photo.find({"addtime": {"$gte": start, "$lte": end}}).sort("device_id", 1)
+
+for i in list(photo):
+    indentify_result = i.get("indentify_result")
+    sp = indentify_result.split("#")
+    chong = {}
+    for s in sp:
+        csp = s.split(",")
+        chong[csp[0]] = csp[1]
+    last_row = sheet.max_row
+    device_info = device.find_one({"id": i.get("id")})
+    if "79" in chong.keys():
+        sheet.insert_rows(last_row + 1)
+        pest_num = chong["79"]
+        province = device_info.get("province")
+        city = device_info.get("city")
+        district = device_info.get("district")
+        lng = device_info.get("lng")
+        lat = device_info.get("lat")
+        at = i.get("at")
+        ah = i.get("ah")
+        addtime = i.get("addtime")
+        date = datetime.datetime.fromtimestamp(addtime)
+        datestr = date.strftime("%Y%m%d%H:%M:%S")
+        sheet.cell(row=last_row + 1, column=1).value = device_info.get("device_id")
+        sheet.cell(row=last_row + 1, column=2).value = "玉米螟"
+        sheet.cell(row=last_row + 1, column=3).value = chong["79"]
+        sheet.cell(row=last_row + 1, column=3).value = date
+        sheet.cell(row=last_row + 1, column=3).value = date.year
+        sheet.cell(row=last_row + 1, column=3).value = date.month
+        sheet.cell(row=last_row + 1, column=3).value = date.day
+        sheet.cell(row=last_row + 1, column=3).value = date.hour
+        sheet.cell(row=last_row + 1, column=3).value = date.minute
+        sheet.cell(row=last_row + 1, column=3).value = date.second
+        sheet.cell(row=last_row + 1, column=3).value = province + city + district
+        sheet.cell(row=last_row + 1, column=3).value = province
+        sheet.cell(row=last_row + 1, column=3).value = city 
+        sheet.cell(row=last_row + 1, column=3).value = district 
+        sheet.cell(row=last_row + 1, column=3).value = at 
+        sheet.cell(row=last_row + 1, column=3).value = ah 
+        sheet.cell(row=last_row + 1, column=3).value = lng  
+        sheet.cell(row=last_row + 1, column=3).value = lat
+    if "52" in chong.keys():
+        sheet.insert_rows(last_row + 1)
+        pest_num = chong["52"]
+        province = device_info.get("province")
+        city = device_info.get("city")
+        district = device_info.get("district")
+        lng = device_info.get("lng")
+        lat = device_info.get("lat")
+        at = i.get("at")
+        ah = i.get("ah")
+        addtime = i.get("addtime")
+        date = datetime.datetime.fromtimestamp(addtime)
+        datestr = date.strftime("%Y%m%d%H:%M:%S")
+        sheet.cell(row=last_row + 1, column=1).value = device_info.get("device_id")
+        sheet.cell(row=last_row + 1, column=2).value = "桃蛀螟"
+        sheet.cell(row=last_row + 1, column=3).value = chong["52"]
+        sheet.cell(row=last_row + 1, column=3).value = date
+        sheet.cell(row=last_row + 1, column=3).value = date.year
+        sheet.cell(row=last_row + 1, column=3).value = date.month
+        sheet.cell(row=last_row + 1, column=3).value = date.day
+        sheet.cell(row=last_row + 1, column=3).value = date.hour
+        sheet.cell(row=last_row + 1, column=3).value = date.minute
+        sheet.cell(row=last_row + 1, column=3).value = date.second
+        sheet.cell(row=last_row + 1, column=3).value = province + city + district
+        sheet.cell(row=last_row + 1, column=3).value = province
+        sheet.cell(row=last_row + 1, column=3).value = city 
+        sheet.cell(row=last_row + 1, column=3).value = district 
+        sheet.cell(row=last_row + 1, column=3).value = at 
+        sheet.cell(row=last_row + 1, column=3).value = ah 
+        sheet.cell(row=last_row + 1, column=3).value = lng  
+        sheet.cell(row=last_row + 1, column=3).value = lat

BIN
热通量增加测试.xlsx