leon hai 3 semanas
pai
achega
957fdd0793
Modificáronse 4 ficheiros con 27 adicións e 11 borrados
  1. 10 4
      server/config.py
  2. 5 3
      server/parser.py
  3. 6 2
      server/server.py
  4. 6 2
      server/test.py

+ 10 - 4
server/config.py

@@ -2,17 +2,23 @@ class Config:
     # 生产环境配置
     PROD = {
         'url' : "http://172.19.152.231/open/api/operate/upload",
-        'channel': "64",
         'classIndex': "68",
-        'nvr': "172.19.152.231"
+        'nvr': "172.19.152.231",
+        'ip2channle' : {
+            "172.19.152.181" : "251",
+            "172.19.152.182" : "252",
+        }
     }
 
     # 测试环境配置
     TEST = {
         'url' : "http://36.7.84.146:28801/open/api/operate/upload",
-        'channel': "251",
         'classIndex': "101",
-        'nvr': "172.16.20.251"
+        'nvr': "172.16.20.251",
+        'ip2channle' : {
+            "172.19.152.181" : "251",
+            "172.19.152.182" : "252",
+        }
     }
 
     @staticmethod

+ 5 - 3
server/parser.py

@@ -115,6 +115,7 @@ def parser_json_data(data):
             if event_alert is None:
                 continue  # 如果没有 EventNotificationAlert,跳过当前记录
 
+            ip_addr = event_alert.get("ipAddress")
             iso_time = event_alert.get("dateTime")
             dt = datetime.fromisoformat(iso_time)
             dateTime = dt.strftime("%Y-%m-%d %H:%M:%S")
@@ -135,7 +136,8 @@ def parser_json_data(data):
                 "dateTime" : dateTime,
                 "pictureInfo": picture_info_list,
                 "VehicleInfo": VehicleInfo,
-                "PlateInfo": PlateInfo
+                "PlateInfo": PlateInfo,
+                "ipAddress" : ip_addr
             })
 
         elif content_type == "image/jpeg":
@@ -154,7 +156,7 @@ def parser_json_data(data):
 
     
 if __name__ == "__main__":
-    with open("tfs_0.txt", "r") as f:
+    with open("../assert/isapi_data/tfs_0.txt", "r") as f:
         multipart_data = eval(f.read())
     # print("===============", multipart_data[:3000])
     # 示例调用
@@ -164,7 +166,7 @@ if __name__ == "__main__":
     result = parse_multipart(multipart_data, boundary)
     print(result)
     infos, images = parser_json_data(result)
-    print(infos, "======", images)
+    print(infos)
 
     # with open("res.xml", "r") as f:
     #     xml_str = f.read()

+ 6 - 2
server/server.py

@@ -16,7 +16,6 @@ app = FastAPI()
 
 conf = Config.get("prod")
 url = conf["url"]
-channel = conf["channel"]
 classIndex = conf["classIndex"]
 nvr = conf["nvr"]
 
@@ -39,6 +38,7 @@ async def speed(request: Request):
                 videoTime = info["dateTime"]
                 speed = info["VehicleInfo"]["vehicleSpeed"]
                 plate = info["PlateInfo"]["plate"]
+                ip_addr = info["ipAddress"]
                 filename = None
                 imagedata = None
                 filename = image_content["filename"]
@@ -50,7 +50,11 @@ async def speed(request: Request):
                     text = f"{plate} : {speed} km/h"
                     draw(img, text, (100, 100))
                     byte_data = pil2byte(img)
-                    res = await upload(url, channel, classIndex, nvr, videoTime, filename, byte_data, plate, speed)
+                    if ip_addr not in conf["ip2channle"]:
+                        logger.info(f"{ip_addr} not in ip2channle")
+                        return
+                    channel = conf["ip2channle"][ip_addr]
+                    res = await upload(url, ip_addr, classIndex, nvr, videoTime, filename, byte_data, plate, speed)
                     logger.info(res)
             except Exception as error:
                 logger.info(error)

+ 6 - 2
server/test.py

@@ -9,9 +9,8 @@ from parser import parser_json_data
 
 from byteimg import byte2pil, pil2byte, draw
 
-conf = Config.get("prod")
+conf = Config.get("test")
 url = conf["url"]
-channel = conf["channel"]
 classIndex = conf["classIndex"]
 nvr = conf["nvr"]
 
@@ -32,6 +31,7 @@ async def local_test():
                 videoTime = info["dateTime"]
                 speed = info["VehicleInfo"]["vehicleSpeed"]
                 plate = info["PlateInfo"]["plate"]
+                ip_addr = info["ipAddress"]
                 filename = None
                 imagedata = None
                 filename = image_content["filename"]
@@ -44,6 +44,10 @@ async def local_test():
                     # draw(img, text, (100, 100))
                     # byte_data = pil2byte(img)
                     # img.show()
+                    if ip_addr not in conf["ip2channle"]:
+                        logger.info(f"{ip_addr} not in ip2channle")
+                        return
+                    channel = conf["ip2channle"][ip_addr]
                     res = await upload(url, channel, classIndex, nvr, videoTime, filename, imagedata, plate, speed)
                     logger.info(res)
             except Exception as error: