feat(aiot): 告警冷却时间调整 + 截图本地保留 + 中文路径修复
- 离岗检测冷却时间: 300s → 600s(10分钟) - 入侵检测冷却时间: 120s → 300s(5分钟) - 入侵告警级别改为高(alarm_level=3) - COS 不可用时保留本地截图文件,不再上报后删除 - 修复 cv2.imwrite 中文路径失败,改用 imencode + write_bytes - 配置订阅在 LOCAL 模式下跳过 Redis 连接 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -92,7 +92,7 @@ class COSConfig:
|
||||
@dataclass
|
||||
class AlarmUploadConfig:
|
||||
"""告警上报配置"""
|
||||
cloud_api_url: str = "http://124.221.55.225:8000"
|
||||
cloud_api_url: str = "http://localhost:8000"
|
||||
edge_token: str = ""
|
||||
retry_max: int = 3
|
||||
retry_interval: int = 5
|
||||
@@ -123,6 +123,18 @@ class InferenceConfig:
|
||||
fp16_mode: bool = True
|
||||
|
||||
|
||||
# ===================== Debug / Local Sync =====================
|
||||
|
||||
@dataclass
|
||||
class DebugConfig:
|
||||
"""本地调试相关配置"""
|
||||
enabled: bool = True
|
||||
host: str = "127.0.0.1"
|
||||
port: int = 9001
|
||||
reload_signal_file: str = "./config/reload.signal"
|
||||
local_config_path: str = "./config/local_config.json"
|
||||
|
||||
|
||||
# COCO 数据集类别名称(YOLO 模型使用)
|
||||
COCO_CLASS_NAMES = [
|
||||
"person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat",
|
||||
@@ -177,6 +189,20 @@ class Settings:
|
||||
|
||||
def _load_env_vars(self):
|
||||
"""从环境变量加载配置"""
|
||||
# 加载 .env 文件(如果 python-dotenv 可用)
|
||||
try:
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
def _abs_path(path: str) -> str:
|
||||
if not path:
|
||||
return path
|
||||
return path if os.path.isabs(path) else os.path.normpath(os.path.join(base_dir, path))
|
||||
|
||||
self.database = DatabaseConfig(
|
||||
host=os.getenv("DB_HOST", "localhost"),
|
||||
port=int(os.getenv("DB_PORT", "3306")),
|
||||
@@ -186,8 +212,8 @@ class Settings:
|
||||
)
|
||||
|
||||
self.sqlite = SQLiteConfig(
|
||||
db_path=os.getenv("SQLITE_DB_PATH", "./data/security_events.db"),
|
||||
image_dir=os.getenv("SQLITE_IMAGE_DIR", "./data/captures"),
|
||||
db_path=_abs_path(os.getenv("SQLITE_DB_PATH", "./data/security_events.db")),
|
||||
image_dir=_abs_path(os.getenv("SQLITE_IMAGE_DIR", "./data/captures")),
|
||||
retention_days=int(os.getenv("SQLITE_RETENTION_DAYS", "7")),
|
||||
wal_mode=os.getenv("SQLITE_WAL_MODE", "1") == "1",
|
||||
)
|
||||
@@ -229,11 +255,13 @@ class Settings:
|
||||
)
|
||||
|
||||
self.alarm_upload = AlarmUploadConfig(
|
||||
cloud_api_url=os.getenv("CLOUD_API_URL", "http://124.221.55.225:8000"),
|
||||
cloud_api_url=os.getenv("CLOUD_API_URL", "http://localhost:8000"),
|
||||
edge_token=os.getenv("EDGE_TOKEN", ""),
|
||||
retry_max=int(os.getenv("ALARM_RETRY_MAX", "3")),
|
||||
retry_interval=int(os.getenv("ALARM_RETRY_INTERVAL", "5")),
|
||||
)
|
||||
|
||||
self.alarm_upload_enabled = os.getenv("ALARM_UPLOAD_ENABLED", "1") == "1"
|
||||
|
||||
self.video_stream = VideoStreamConfig(
|
||||
default_fps=int(os.getenv("VIDEO_DEFAULT_FPS", "5")),
|
||||
@@ -248,6 +276,16 @@ class Settings:
|
||||
conf_threshold=float(os.getenv("CONF_THRESHOLD", "0.5")),
|
||||
nms_threshold=float(os.getenv("NMS_THRESHOLD", "0.45")),
|
||||
)
|
||||
|
||||
self.config_sync_mode = os.getenv("CONFIG_SYNC_MODE", "LOCAL").upper()
|
||||
|
||||
self.debug = DebugConfig(
|
||||
enabled=os.getenv("DEBUG_SERVER_ENABLED", "1") == "1",
|
||||
host=os.getenv("DEBUG_SERVER_HOST", "127.0.0.1"),
|
||||
port=int(os.getenv("DEBUG_SERVER_PORT", "9001")),
|
||||
reload_signal_file=_abs_path(os.getenv("DEBUG_RELOAD_SIGNAL_FILE", "./config/reload.signal")),
|
||||
local_config_path=_abs_path(os.getenv("LOCAL_CONFIG_PATH", "./config/local_config.json")),
|
||||
)
|
||||
|
||||
self.log_level = os.getenv("LOG_LEVEL", "INFO")
|
||||
self.log_dir = os.getenv("LOG_DIR", "./logs")
|
||||
|
||||
Reference in New Issue
Block a user