yf_yzl пре 2 година
родитељ
комит
992ada6429

scripts/test/cbd_device_config.py → scripts/test/cbd_config.py


scripts/test/cbd_data.py → scripts/test/cbd_device_data.py


+ 16 - 19
scripts/test/cbd_photo.py

@@ -44,29 +44,26 @@ def dsj_qxz_conf_info():
     for i in scd_device:
         device_info = collection.find_one({'device_id':i})
         device_id = device_info['id']
-        id = device_info["id"]
-        print(device_id, "================")
         data = {'device_id': str(device_id),'uptime':{'$gte':1689006195}}
         cursor = collection1.find(data,{'_id':0,'id':0})
         device_id = MongoDevice.objects.get(device_id=i).id 
         for i in cursor:
-            if i["addr"] == i["indentify_photo"]:
-                scd_data = MongoCBDphoto.objects.create(
-                    device_id = device_id,
-                    addtime = i["addtime"],
-                    uptime = i["uptime"],
-                    addr = i["addr"],
-                    at = i["at"],
-                    ah = i["ah"],
-                    describe = i["describe"],
-                    indentify_photo = i["indentify_photo"],
-                    indentify_result = i["indentify_result"],
-                    photo_status = i["photo_status"],
-                    is_mark = i["is_mark"],
-                    mark = i["mark"],
-                    label = i["label"]
-                )
-                print(scd_data)
+            scd_data = MongoCBDphoto.objects.create(
+                device_id = device_id,
+                addtime = i["addtime"],
+                uptime = i["uptime"],
+                addr = i["addr"],
+                at = i["at"],
+                ah = i["ah"],
+                describe = i["describe"],
+                indentify_photo = i["indentify_photo"],
+                indentify_result = i["indentify_result"],
+                photo_status = i["photo_status"],
+                is_mark = i["is_mark"],
+                mark = i["mark"],
+                label = i["label"]
+            )
+            print(scd_data.id)
         print(f"设备: {i} {device_id} 数据量  {cursor.count()}")
     return True
 

+ 73 - 0
scripts/test/cbd_photo_local.py

@@ -0,0 +1,73 @@
+import os
+import sys
+import time
+import django
+local_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+print(local_path)
+if local_path not in sys.path:
+    sys.path.append(local_path)
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kedong.settings")
+django.setup()
+from django.conf import settings
+from smartfarming.models.device import MongoDevice, MongoCBDData
+from smartfarming.models.worm_forecast import MongoCBDphoto
+import json
+import requests
+import pymongo
+from urllib import parse
+from kedong.settings import MEDIA_ROOT
+
+
+my_client = pymongo.MongoClient(host="8.136.98.49", port=27017, username="root", password="yfkj@6020")
+my_col = my_client['smartfarming']['sa_device']
+
+scd_device = {
+"866547058627400",
+"866547058637276",
+"866547058633663",
+"866547058613921"
+}
+
+
+
+def dsj_qxz_conf_info():
+    cbd_photo = MongoCBDphoto.objects.all()
+    for i in cbd_photo:
+        device = MongoDevice.objects.get(id=i.device_id)
+        device_id = device.device_id
+        addr = "https://bigdata-image.oss-cn-hangzhou.aliyuncs.com/Basics/cbd/" + i.addr
+        cbd_path = os.path.join(MEDIA_ROOT, f"cbd/{device_id}")
+        os.makedirs(cbd_path) if not os.path.exists(cbd_path) else None 
+        file_name = (i.addr).split("/")[-1]
+        local_addr = os.path.join(cbd_path, file_name)
+        response = requests.get(addr)
+        tb = ""
+        try:
+            if int(response.status_code) == 200:
+                with open(local_addr, "wb") as f:
+                    f.write(response.content)
+                tb = f"/media/cbd/{device_id}/{file_name}"
+        except Exception as e:
+            print(e)
+        i.addr = tb 
+
+        indentyfy_addr = "https://bigdata-image.oss-cn-hangzhou.aliyuncs.com/Basics/cbd/" + i.indentify_photo
+        indentyfy_path = os.path.join(MEDIA_ROOT, f"result/cbd/{device_id}")
+        os.makedirs(indentyfy_path) if not os.path.exists(indentyfy_path) else None 
+        indentyfy_file_name = (i.indentify_photo).split("/")[-1]
+        indentyfy_local_addr = os.path.join(indentyfy_path, indentyfy_file_name)
+        response = requests.get(indentyfy_addr)
+        indentyfy_tb = ""
+        try:
+            if int(response.status_code) == 200:
+                with open(indentyfy_local_addr, "wb") as f:
+                    f.write(response.content)
+                indentyfy_tb = f"/media/result/cbd/{device_id}/{indentyfy_file_name}"
+        except Exception as e:
+            print(e)
+        i.indentify_photo = indentyfy_tb
+        i.save()
+
+
+if __name__ == "__main__":
+    dsj_qxz_conf_info()

+ 0 - 58
scripts/test/cbd_save_photo.py

@@ -1,58 +0,0 @@
-import os
-import sys
-import time
-import django
-local_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-print(local_path)
-if local_path not in sys.path:
-    sys.path.append(local_path)
-os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kedong.settings")
-django.setup()
-from django.conf import settings
-from smartfarming.models.device import MongoDevice, MongoCBDData
-from smartfarming.models.worm_forecast import MongoCBDphoto
-import json
-import requests
-import pymongo
-from urllib import parse
-from kedong.settings import MEDIA_ROOT
-
-
-my_client = pymongo.MongoClient(host="8.136.98.49", port=27017, username="root", password="yfkj@6020")
-my_col = my_client['smartfarming']['sa_device']
-
-scd_device = {
-"866547058627400",
-"866547058637276",
-"866547058633663",
-"866547058613921"
-}
-
-
-
-def dsj_qxz_conf_info():
-    cbd_photo = MongoCBDphoto.objects.all()
-    for i in cbd_photo:
-        device = MongoDevice.objects.get(id=i.device_id)
-        device_id = device.device_id
-        addr = "https://bigdata-image.oss-cn-hangzhou.aliyuncs.com/Basics/cbd/" + i.addr
-        if i.addr == i.indentify_photo:
-            cbd_path = os.path.join(MEDIA_ROOT, f"cbd/{device_id}")
-            os.makedirs(cbd_path) if not os.path.exists(cbd_path) else None 
-            file_name = (i.addr).split("/")[-1]
-            local_addr = os.path.join(cbd_path, file_name)
-            response = requests.get(addr)
-            try:
-                if int(response.status_code) == 200:
-                    with open(local_addr, "wb") as f:
-                        f.write(response.content)
-            except Exception as e:
-                print(e)
-            tb = f"/media/cbd/{device_id}/{file_name}"
-            i.addr = tb 
-            i.indentify_photo = tb
-            i.save()
-
-
-if __name__ == "__main__":
-    dsj_qxz_conf_info()

scripts/test/dbd_warning.py → scripts/test/cbd_warning.py


+ 9 - 11
scripts/test/qx_base_info.py

@@ -21,16 +21,14 @@ my_client = pymongo.MongoClient(host="8.136.98.49", port=27017, username="root",
 my_col = my_client['smartfarming']['sa_device']
 
 qx_device = {
-# "861551055315402",
-# "861551056086671",
-# "861551056088693",
-# "861551056088479",
-# "861551056088719",
-# "861551055313365",
-# "861551056086614",
-# "861551056093800"
-
-
+"861551055315402",
+"861551056086671",
+"861551056088693",
+"861551056088479",
+"861551056088719",
+"861551055313365",
+"861551056086614",
+"861551056093800",
 "861551056095367",
 "861551056102502",
 "861551056096621",
@@ -77,7 +75,7 @@ def dsj_qxz_conf_info():
                     "uptime": i.get("uptime")                    
                 }
             )
-        print(f"设备: {k} 数据量  {cursor.count()} {qx_data, is_created} ")
+        print(f"设备: {k} 数据量  {cursor.count()} {qx_data.id, is_created} ")
     return True
 
 

+ 8 - 9
scripts/test/qx_conf.py

@@ -21,15 +21,14 @@ my_client = pymongo.MongoClient(host="8.136.98.49", port=27017, username="root",
 my_col = my_client['smartfarming']['sa_device']
 
 qx_device = {
-# "861551055315402",
-# "861551056086671",
-# "861551056088693",
-# "861551056088479",
-# "861551056088719",
-# "861551055313365",
-# "861551056086614",
-# "861551056093800"
-
+"861551055315402",
+"861551056086671",
+"861551056088693",
+"861551056088479",
+"861551056088719",
+"861551055313365",
+"861551056086614",
+"861551056093800",
 "861551056095367",
 "861551056102502",
 "861551056096621",

+ 8 - 9
scripts/test/qx_data.py

@@ -21,15 +21,14 @@ my_client = pymongo.MongoClient(host="8.136.98.49", port=27017, username="root",
 my_col = my_client['smartfarming']['sa_device']
 
 qx_device = {
-# "861551055315402",
-# "861551056086671",
-# "861551056088693",
-# "861551056088479",
-# "861551056088719",
-# "861551055313365",
-# "861551056086614",
-# "861551056093800"
-
+"861551055315402",
+"861551056086671",
+"861551056088693",
+"861551056088479",
+"861551056088719",
+"861551055313365",
+"861551056086614",
+"861551056093800",
 "861551056095367",
 "861551056102502",
 "861551056096621",

+ 2 - 3
scripts/test/scd_data.py

@@ -103,7 +103,7 @@ def dsj_qxz_conf_info():
             }
         )
         print(device.id, is_created)
-        data = {'device_id': device_id,'addtime':{'$gt':1681808604,'$lt':1682413404}}
+        data = {'device_id': device_id,'addtime':{'$gt':1681808604}}
         cursor = collection1.find(data,{'_id':0,'id':0,'device_id':0})
 
         for i in cursor:
@@ -113,8 +113,7 @@ def dsj_qxz_conf_info():
                 addtime=i['addtime'],
                 device_status=i['device_status']
             )
-            print(scd_data)
-        # print(f"设备: {i} {device_id} 数据量  {cursor.count()}")
+            print(scd_data.id)
     return True
 
 

scripts/test/xy_data.py → scripts/test/xy_device_data.py