Casper 1 mese fa
parent
commit
46c99e895a

+ 0 - 19
sri-server-bg02/app.py

@@ -8,25 +8,6 @@ import importlib
 
 def generate_app():
     """"""
-    # from settings import action_methods
-    from lib.LineManage import LineManage
-
-    # see: https://lzomedia.com/blog/host-fastapi-backend-api-and-react-app-frontend-locally/
-    # --- define middleware --- see: https://www.starlette.io/middleware/
-    # from starlette.applications import Starlette
-    # from starlette.middleware import Middleware
-    # # from starlette.middleware.httpsredirect import HTTPSRedirectMiddleware
-    # # from starlette.middleware.trustedhost import TrustedHostMiddlewar
-    # middleware = [
-    #     Middleware(
-    #         TrustedHostMiddleware,
-    #         allow_credentials=True,
-    #         allowed_hosts=['*'],
-    #         allow_methods=["*"],
-    #         allow_headers=["*"],
-    #     ),
-    #     # Middleware(HTTPSRedirectMiddleware)
-    # ]
 
     # --- define app --- see: https://responder.kennethreitz.org/en/latest/tour.html#cors
     import responder

+ 7 - 4
sri-server-bg02/hub.py

@@ -7,20 +7,23 @@ methods = importlib.import_module(f"xlib")
 
 
 class Global(object):
+    """
+    """
 
-    # todo 需要实现实例化emqx
+    save_dir = r'C:\logs'  # sri内网测试环境
+    # save_dir = r'E:\logs'  # 湛江现场环境(容量为512G)
 
     # --- 中间件服务器 --- for test
     emqx_MessageListenerC001 = importlib.import_module(f"xclient.xmqtt").Client(host='127.0.0.1', port=41883)
     emqx_MessageListenerV001 = importlib.import_module(f"xclient.xmqtt").Client(host='127.0.0.1', port=41883)
-    
-    # --- 中间件服务器 --- for 湛江项目现场
+
+    # --- 中间件服务器 --- for 湛江项目现场 todo 需要实现实例化emqx | 只能是哪里用到哪里实例化
     emqx_Veh0533 = importlib.import_module(f"xclient.xmqtt").Client(host='127.0.0.1', port=41883)
     emqx_Veh0534 = importlib.import_module(f"xclient.xmqtt").Client(host='127.0.0.1', port=41883)
     emqx_Veh0535 = importlib.import_module(f"xclient.xmqtt").Client(host='127.0.0.1', port=41883)
     emqx_Veh0537 = importlib.import_module(f"xclient.xmqtt").Client(host='127.0.0.1', port=41883)
     emqx_Veh0538 = importlib.import_module(f"xclient.xmqtt").Client(host='127.0.0.1', port=41883)
-    
+
     aps = importlib.import_module(f"xpip.xapscheduler").APS(db_type='mongo',
                                                             db_host='127.0.0.1',
                                                             db_port=47017,

+ 3 - 8
sri-server-bg02/lib/JobManage.py

@@ -2,11 +2,6 @@ from hub import Global, methods
 
 import os
 
-# --- for linux
-# save_dir = f'/home/server/logs'
-
-# --- for windows
-save_dir = r'C:\logs'  # sri内网测试环境
 
 class JobManage(object):
     """"""
@@ -45,15 +40,15 @@ class JobManage(object):
         methods.debug_log("JobManage|49", f"------------------------------ start job101")
 
         # --- get log_file_uuid_list ---
-        log_file_list = methods.get_file_path_list(save_dir)
+        log_file_list = methods.get_file_path_list(Global.save_dir)
         log_file_name_list = [i.split('\\')[-1] for i in log_file_list]
         log_file_uuid_list = [i.split('.')[0] for i in log_file_name_list]
 
         # --- test ---
         for log_file_uuid in log_file_uuid_list:
-            
+
             # --- check ---
-            file_path = os.path.join(save_dir, f"{log_file_uuid}.log")
+            file_path = os.path.join(Global.save_dir, f"{log_file_uuid}.log")
             item = Global.mdb.get_one_by_id('UserWorkRecordList', log_file_uuid)
             if not item:
                 methods.remove_file(file_path)

+ 0 - 253
sri-server-bg02/lib/LineManage.py

@@ -1,253 +0,0 @@
-from hub import methods, Global
-
-import asyncio
-import threading
-import traceback
-
-
-class LineManage(object):
-    """"""
-
-    line_dict = {}  # {<line_id>: <ws>, <now_ts>}
-
-    @classmethod
-    def run_forever(cls):
-        tasks = [cls.check_loop()]
-        _loop = asyncio.new_event_loop()
-        asyncio.set_event_loop(_loop)
-        loop = asyncio.get_event_loop()
-        loop.run_until_complete(asyncio.wait(tasks))
-
-    @classmethod
-    def run_background(cls, is_back_run=True):
-        t1 = threading.Thread(target=cls.run_forever)
-        t1.start()
-
-    @classmethod
-    async def check_loop(cls):
-
-        # --- define ---
-        # last_send_id = str()
-
-        while True:
-
-            try:
-
-                # --- debug ---
-                # methods.debug_log(f"LineManage.check_loop44", f"#run at {methods.now_string()} "
-                #                                                f"| {len(cls.line_dict.values())}")
-                # await asyncio.sleep(3)
-                # await asyncio.sleep(0.5)
-
-                # --- get send_data ---
-                # """
-                # send_data = {
-                #     send_id: 数据id
-                #     send_list: 数据列表
-                # }
-                # """
-                # send_data = Global.rdb.get_one(key='send_data')
-                # send_data = db0.get_one(key='send_data')
-
-                # --- check ---
-                # if not send_data:
-                #     continue
-
-                # --- check ---
-                # send_id = send_data.get('send_id')
-                # if not send_id:
-                #     continue
-
-                # --- check ---
-                # if send_id == last_send_id:
-                #     continue
-
-                # --- check ---
-                # send_list = send_data.get('send_list')
-                # if send_list is None or len(send_list) == 0:
-                #     continue
-
-                # --- debug ---
-                # await asyncio.sleep(3)
-                # await asyncio.sleep(0.5)
-                # methods.debug_log(f"LineManage", f"m-74: run at {methods.now_string()} "
-                #                                  f"| send count is {len(send_list)} "
-                #                                  f"| online count is {len(cls.line_dict.values())}")
-
-                # --- define ---
-                now_ts = methods.now_ts()
-
-                # --- check ---
-                for username in list(cls.line_dict.keys()):
-
-                    try:
-
-                        # --- debug ---
-                        _ws, last_live_at, _id = cls.line_dict.get(username)
-                        methods.debug_log(f"LineManage.check_loop87", f"#username: {username}"
-                                                                      f" | #last_live_at: {last_live_at}"
-                                                                      f" | #now_ts: {now_ts}")
-
-                        # --- check 180s ---
-                        if now_ts - last_live_at >= 3 * 60:
-                            cls.line_dict.pop(username)
-
-                        # --- check ---
-                        # if not cls.check_line_is_live(line_id):
-                        #     methods.debug_log(f"LineManage", f"m-56: websocket link broken.")
-                        #     cls.line_dict.pop(line_id)
-                        #     continue
-
-                        # --- send ---
-                        # """
-                        # send_list = [
-                        #     {
-                        #         base_face_uuid: 底库人脸id
-                        #         snap_face_image: 抓拍人脸
-                        #         base_face_image_path: 底库人脸路径
-                        #         face_similarity: 相似度
-                        #     }
-                        # ]
-                        # """
-                        # for data in send_list:
-                        #
-                        #     # --- check ---
-                        #     if data.get('snap_face_image') is None:
-                        #         continue
-                        #
-                        #     # --- define ---
-                        #     """
-                        #     send_dict = {
-                        #         input_face_b64: 抓拍人脸图像
-                        #         face_uuid: 人脸id
-                        #         face_name: 人脸名称
-                        #         known_face_b64: 底库人脸图像
-                        #         face_similarity: 相似度
-                        #         face_type_name_list: 人员类型
-                        #     }
-                        #     """
-                        #     send_dict = dict(
-                        #         input_face_b64=cls.image_to_b64(data.get('snap_face_image')),
-                        #         # input_face_b64=str(),
-                        #         known_face_b64=str(),
-                        #         face_uuid=str(),
-                        #         face_name=str(),
-                        #         face_similarity=data.get('face_similarity'),
-                        #         face_type_name_list=list(),
-                        #     )
-                        #
-                        #     # --- fill input_face_b64 ---
-                        #     # snap_face_image_path = data.get('snap_face_image_path')
-                        #     # if snap_face_image_path and methods.is_file(snap_face_image_path):
-                        #     #     frame = cv2.imread(snap_face_image_path)
-                        #     #     if frame is not None:
-                        #     #         _, image = cv2.imencode('.jpg', frame)
-                        #     #         base64_data = base64.b64encode(image)  # byte to b64 byte
-                        #     #         s = base64_data.decode()  # byte to str
-                        #     #         send_dict['input_face_b64'] = f'data:image/jpeg;base64,{s}'
-                        #
-                        #     # --- fill known_face_b64 ---
-                        #     base_face_image_path = data.get('base_face_image_path')
-                        #     if base_face_image_path and methods.is_file(base_face_image_path):
-                        #         frame = cv2.imread(base_face_image_path)
-                        #         if frame is not None:
-                        #             _, image = cv2.imencode('.jpg', frame)
-                        #             base64_data = base64.b64encode(image)  # byte to b64 byte
-                        #             s = base64_data.decode()  # byte to str
-                        #             send_dict['known_face_b64'] = f'data:image/jpeg;base64,{s}'
-                        #
-                        #     # --- fill face_uuid and face_name ---
-                        #     """
-                        #     Face: 陌生人脸表
-                        #     Face.face_name: 人脸名称
-                        #     """
-                        #     face_uuid = data.get('base_face_uuid')
-                        #     if face_uuid:
-                        #         send_dict['face_uuid'] = face_uuid
-                        #         face = Global.mdb.get_one_by_id('Face', face_uuid)
-                        #         if face and face.get('face_name'):
-                        #             send_dict['face_name'] = face.get('face_name')
-                        #
-                        #         # --- fill face_type_name_list ---
-                        #         face_type_uuid_list = face.get('face_type_uuid_list')
-                        #         if face_type_uuid_list:
-                        #             send_dict['face_type_name_list'] = [face_type_name_dict.get(i)
-                        #                                                 for i in face_type_uuid_list
-                        #                                                 if face_type_name_dict.get(i)]
-                        #
-                        #     # --- send ---
-                        #     # methods.debug_log(f"LineManage", f"m-153: send_dict is {send_dict}")
-                        #     line = cls.line_dict.get(line_id)
-                        #     send_json = methods.json_dumps(send_dict)
-                        #     await line.send_text(send_json)
-                        #     # methods.debug_log(f"LineManage",
-                        #     #                   f"m-161: end at {datetime.datetime.now().strftime('%H:%M:%S.%f')}")
-                        #     # await asyncio.sleep(0.1)
-
-                    except Exception as exception:
-
-                        # --- check ---
-                        if not cls.check_line_is_live(username):
-                            cls.line_dict.pop(username)
-
-                        if exception.__class__.__name__ == 'RuntimeError':
-                            methods.debug_log(f"LineManage.check_loop194", f"d2: {cls.get_line_state()}")
-                        else:
-                            methods.debug_log("LineManage.check_loop194", f"#e: {exception.__class__.__name__}")
-                            methods.debug_log("LineManage.check_loop194", f"#t: {traceback.format_exc()}")
-
-                    # --- debug ---
-                    methods.debug_log(f"LineManage.check_loop198", f"wait 1 minutes check again")
-                    await asyncio.sleep(60)
-                    # await asyncio.sleep(60)
-                    # await asyncio.sleep(60)
-
-
-            except Exception as exception:
-
-                methods.debug_log(f"LineManage.check_loop208", f"#e: {exception.__class__.__name__}")
-                methods.debug_log(f"LineManage.check_loop208", f"#t: {traceback.format_exc()}")
-                methods.debug_log(f"LineManage.check_loop208", f"wait 1 minutes try again!")
-                await asyncio.sleep(60)
-
-    @classmethod
-    def get_line_total(cls):
-        count = 0
-        for k, v in cls.line_dict.items():
-            count += 1
-        return count
-
-    @classmethod
-    def check_line_is_live(cls, line_id):
-        d1 = {
-            0: 'CONNECTING',
-            1: 'CONNECTED',
-            2: 'DISCONNECTED',
-        }
-        _ws, _, _ = cls.line_dict.get(line_id)
-        if _ws and d1.get(_ws.client_state.value) != 'DISCONNECTED':
-            return True
-        else:
-            return False
-
-    @classmethod
-    def get_line_state(cls):
-        d1 = {
-            0: 'CONNECTING',
-            1: 'CONNECTED',
-            2: 'DISCONNECTED',
-        }
-        d2 = dict()  # {<line_id>: <state>}
-        for line_id, line in cls.line_dict.items():
-            state = d1.get(line.client_state.value)
-            _id = line_id[-6:]
-            d2[_id] = state
-        return d2
-
-    # @staticmethod
-    # def image_to_b64(image):
-    #     frame = numpy_method.to_array(image)  # list to numpy array
-    #     _, image = cv2.imencode('.jpg', frame)
-    #     base64_data = base64.b64encode(image)
-    #     s = base64_data.decode()
-    #     return f'data:image/jpeg;base64,{s}'

+ 0 - 7
sri-server-bg02/lib/MessageListener.py

@@ -5,13 +5,6 @@ import time
 import json
 import os
 
-# --- for linux
-# save_dir = f"/home/server/logs"
-
-# --- for windows
-# save_dir = r'C:\SRI-DINO.Server-py\logs'  # sri内网测试环境
-save_dir = r'C:\logs'  # sri内网测试环境
-
 
 class MessageListener(object):
     """

+ 2 - 7
sri-server-bg02/lib/MessageListenerC001.py

@@ -8,16 +8,11 @@ import os
 
 from lib.UserWorkRecord import UserWorkRecord
 
-# --- for linux
-# save_dir = f"/home/server/logs"
-
-# --- for windows
-# save_dir = r'C:\SRI-DINO.Server-py\logs'  # sri内网测试环境
-save_dir = r'C:\logs'  # sri内网测试环境
 
 class LocalClass(object):
     last_log_key = str()
 
+
 def method_c001(client, userdata, message):
     """消息处理方法"""
     """
@@ -155,7 +150,7 @@ def method_c001(client, userdata, message):
 
     # --- save ---
     # methods.debug_log(f"MessageListenerC001|158", f"#log_list: {log_list}")
-    log_file_path = os.path.join(save_dir, f'{log_uuid}.log')
+    log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
     methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
 
 

+ 3 - 9
sri-server-bg02/lib/MessageListenerV001.py

@@ -8,12 +8,6 @@ import os
 
 from lib.UserWorkRecord import UserWorkRecord
 
-# --- for linux
-# save_dir = f"/home/server/logs"
-
-# --- for windows
-# save_dir = r'C:\SRI-DINO.Server-py\logs'  # sri内网测试环境
-save_dir = r'C:\logs'  # sri内网测试环境
 
 
 class LocalClass(object):
@@ -27,8 +21,8 @@ def method_v001(client, userdata, message):
     # return
 
     # --- check ---
-    # if not methods.is_dir(save_dir):
-    #     out = methods.run_command(f'mkdir -p {save_dir}', callback=True)
+    # if not methods.is_dir(Global.save_dir):
+    #     out = methods.run_command(f'mkdir -p {Global.save_dir}', callback=True)
     #     methods.debug_log('MessageListener46', f"#out: {out}")
 
     # --- check ---
@@ -114,7 +108,7 @@ def method_v001(client, userdata, message):
 
     # --- save ---
     # methods.debug_log(f"MessageListenerV001|113", f"#log_list: {log_list}")
-    log_file_path = os.path.join(save_dir, f'{log_uuid}.log')
+    log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
     methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
 
 

+ 3 - 9
sri-server-bg02/lib/MessageListenerZJV1.py

@@ -8,12 +8,6 @@ import os
 
 from lib.UserWorkRecord import UserWorkRecord
 
-# --- for linux
-# save_dir = f"/home/server/logs"
-
-# --- for windows
-# save_dir = r'C:\SRI-DINO.Server-py\logs'  # sri内网测试环境
-save_dir = r'C:\logs'  # sri内网测试环境
 
 
 class LocalClass(object):
@@ -27,8 +21,8 @@ def method_v001(client, userdata, message):
     # return
 
     # --- check ---
-    # if not methods.is_dir(save_dir):
-    #     out = methods.run_command(f'mkdir -p {save_dir}', callback=True)
+    # if not methods.is_dir(Global.save_dir):
+    #     out = methods.run_command(f'mkdir -p {Global.save_dir}', callback=True)
     #     methods.debug_log('MessageListener46', f"#out: {out}")
 
     # --- check ---
@@ -114,7 +108,7 @@ def method_v001(client, userdata, message):
 
     # --- save ---
     # methods.debug_log(f"MessageListenerV001|113", f"#log_list: {log_list}")
-    log_file_path = os.path.join(save_dir, f'{log_uuid}.log')
+    log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
     methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
 
 

+ 1 - 7
sri-server-bg02/lib/MessageListenerZJV2.py

@@ -8,12 +8,6 @@ import os
 
 from lib.UserWorkRecord import UserWorkRecord
 
-# --- for linux
-# save_dir = f"/home/server/logs"
-
-# --- for windows
-# save_dir = r'C:\SRI-DINO.Server-py\logs'  # sri内网测试环境
-save_dir = r'C:\logs'  # sri内网测试环境
 
 
 class LocalClass(object):
@@ -114,7 +108,7 @@ def method_v001(client, userdata, message):
 
     # --- save ---
     # methods.debug_log(f"MessageListenerV001|113", f"#log_list: {log_list}")
-    log_file_path = os.path.join(save_dir, f'{log_uuid}.log')
+    log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
     methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
 
 

+ 1 - 7
sri-server-bg02/lib/MessageListenerZJV3.py

@@ -8,12 +8,6 @@ import os
 
 from lib.UserWorkRecord import UserWorkRecord
 
-# --- for linux
-# save_dir = f"/home/server/logs"
-
-# --- for windows
-# save_dir = r'C:\SRI-DINO.Server-py\logs'  # sri内网测试环境
-save_dir = r'C:\logs'  # sri内网测试环境
 
 
 class LocalClass(object):
@@ -114,7 +108,7 @@ def method_v001(client, userdata, message):
 
     # --- save ---
     # methods.debug_log(f"MessageListenerV001|113", f"#log_list: {log_list}")
-    log_file_path = os.path.join(save_dir, f'{log_uuid}.log')
+    log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
     methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
 
 

+ 1 - 7
sri-server-bg02/lib/MessageListenerZJV4.py

@@ -8,12 +8,6 @@ import os
 
 from lib.UserWorkRecord import UserWorkRecord
 
-# --- for linux
-# save_dir = f"/home/server/logs"
-
-# --- for windows
-# save_dir = r'C:\SRI-DINO.Server-py\logs'  # sri内网测试环境
-save_dir = r'C:\logs'  # sri内网测试环境
 
 
 class LocalClass(object):
@@ -114,7 +108,7 @@ def method_v001(client, userdata, message):
 
     # --- save ---
     # methods.debug_log(f"MessageListenerV001|113", f"#log_list: {log_list}")
-    log_file_path = os.path.join(save_dir, f'{log_uuid}.log')
+    log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
     methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
 
 

+ 1 - 7
sri-server-bg02/lib/MessageListenerZJV5.py

@@ -8,12 +8,6 @@ import os
 
 from lib.UserWorkRecord import UserWorkRecord
 
-# --- for linux
-# save_dir = f"/home/server/logs"
-
-# --- for windows
-# save_dir = r'C:\SRI-DINO.Server-py\logs'  # sri内网测试环境
-save_dir = r'C:\logs'  # sri内网测试环境
 
 
 class LocalClass(object):
@@ -114,7 +108,7 @@ def method_v001(client, userdata, message):
 
     # --- save ---
     # methods.debug_log(f"MessageListenerV001|113", f"#log_list: {log_list}")
-    log_file_path = os.path.join(save_dir, f'{log_uuid}.log')
+    log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
     methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
 
 

+ 2 - 3
sri-server-bg02/main.py

@@ -1,12 +1,11 @@
-# from app import generate_app
-# app = generate_app()
-import traceback
 from app import generate_app
 
 # import uvicorn
+import traceback
 
 app = generate_app()
 
+
 def main():
     try:
         # 定时任务

+ 0 - 1
sri-server-bg03/hub.py

@@ -14,7 +14,6 @@ class Global(object):
     # ---服务端口
     egoserver_port = 20918
 
-
     # --- 业务数据数据库 ---
     mdb = importlib.import_module(f"xclient.xmongo").Client(host='127.0.0.1', port=47017, database='bg',
                                                             username='admin', password='admin')