Refactor: nearly done phase 5

This commit is contained in:
ziesorx 2025-09-24 20:29:31 +07:00
parent 227e696ed6
commit 7a9a149955
12 changed files with 2750 additions and 105 deletions

View file

@ -3,7 +3,7 @@ Message types, constants, and validation functions for WebSocket communication.
"""
import json
import logging
from typing import Dict, Any, Optional
from typing import Dict, Any, Optional, Union
from .models import (
IncomingMessage, OutgoingMessage,
SetSubscriptionListMessage, SetSessionIdMessage, SetProgressionStageMessage,
@ -161,14 +161,14 @@ def create_state_report(cpu_usage: float, memory_usage: float,
)
def create_image_detection(subscription_identifier: str, detection_data: Dict[str, Any],
def create_image_detection(subscription_identifier: str, detection_data: Union[Dict[str, Any], None],
model_id: int, model_name: str) -> ImageDetectionMessage:
"""
Create an image detection message.
Args:
subscription_identifier: Camera subscription identifier
detection_data: Flat dictionary of detection results
detection_data: Detection results - Dict for data, {} for empty, None for abandonment
model_id: Model identifier
model_name: Model name
@ -176,6 +176,12 @@ def create_image_detection(subscription_identifier: str, detection_data: Dict[st
ImageDetectionMessage object
"""
from .models import DetectionData
from typing import Union
# Handle three cases:
# 1. None = car abandonment (detection: null)
# 2. {} = empty detection (triggers session creation)
# 3. {...} = full detection data (updates session)
data = DetectionData(
detection=detection_data,