Files
gps-denied-onboard/docs/02_components/14_result_manager/result_manager_spec.md
T
Oleksandr Bezdieniezhnykh ef75cc5877 components assesment #2
add 2.15_components_assesment.md step
2025-11-29 12:04:51 +02:00

7.2 KiB

Result Manager

Interface Definition

Interface Name: IResultManager

Interface Methods

class IResultManager(ABC):
    @abstractmethod
    def update_frame_result(self, flight_id: str, frame_id: int, result: FrameResult) -> bool:
        pass
    
    @abstractmethod
    def publish_waypoint_update(self, flight_id: str, frame_id: int) -> bool:
        pass
    
    @abstractmethod
    def get_flight_results(self, flight_id: str) -> FlightResults:
        pass
    
    @abstractmethod
    def mark_refined(self, flight_id: str, frame_ids: List[int]) -> bool:
        pass
    
    @abstractmethod
    def get_changed_frames(self, flight_id: str, since: datetime) -> List[int]:
        pass

Component Description

Responsibilities

  • Manage trajectory results per flight
  • Track frame refinements and changes
  • Store waypoint updates via F03 Flight Database
  • Send incremental updates via F15 SSE Event Streamer
  • Maintain result versioning for audit trail
  • Convert optimized poses to GPS coordinates

Scope

  • Result state management
  • Flight Database integration (waypoint storage)
  • SSE event triggering
  • Incremental update detection
  • Result persistence

API Methods

update_frame_result(flight_id: str, frame_id: int, result: FrameResult) -> bool

Description: Updates result for a processed frame.

Called By:

  • Main processing loop (after each frame)
  • F10 Factor Graph (after refinement)

Input:

flight_id: str
frame_id: int
result: FrameResult:
    gps_center: GPSPoint
    altitude: float
    heading: float
    confidence: float
    timestamp: datetime
    refined: bool
    objects: List[ObjectLocation]  # From external detector

Output: bool - True if updated

Processing Flow:

  1. Store result via F03 Flight Database.save_frame_result()
  2. Call publish_waypoint_update()
  3. Call F15 SSE Event Streamer.send_frame_result()
  4. Update flight statistics

Test Cases:

  1. New frame result → stored and published
  2. Refined result → updates existing, marks refined=True

publish_waypoint_update(flight_id: str, frame_id: int) -> bool

Description: Updates waypoint in Flight Database via F03.

Called By:

  • Internal (after update_frame_result)

Input:

flight_id: str
frame_id: int

Output: bool - True if updated successfully

Processing Flow:

  1. Get result for frame_id
  2. Convert to Waypoint format
  3. Call F03 Flight Database.update_waypoint()
  4. Handle errors (retry if transient)

Test Cases:

  1. Successful update → Waypoint stored in database
  2. Database unavailable → logs error, continues

get_flight_results(flight_id: str) -> FlightResults

Description: Retrieves all results for a flight.

Called By:

  • F01 REST API (results endpoint)
  • Testing/validation

Input: flight_id: str

Output:

FlightResults:
    flight_id: str
    frames: List[FrameResult]
    statistics: FlightStatistics

Test Cases:

  1. Get all results → returns complete trajectory

mark_refined(flight_id: str, frame_ids: List[int]) -> bool

Description: Marks frames as refined after batch optimization.

Called By:

  • F10 Factor Graph (after asynchronous refinement)

Input:

flight_id: str
frame_ids: List[int]  # Frames with updated poses

Output: bool

Processing Flow:

  1. For each frame_id:
    • Get refined pose from F10 Factor Graph Optimizer → ENU pose
    • Convert ENU pose to GPS via F13 Coordinate Transformer.enu_to_gps(flight_id, enu_pose)
    • Update result with refined=True via F03 Flight Database.save_frame_result()
    • Update waypoint via F03 Flight Database.update_waypoint()
    • Call F15 SSE Event Streamer.send_refinement()

Test Cases:

  1. Batch refinement → all frames updated and published

get_changed_frames(flight_id: str, since: datetime) -> List[int]

Description: Gets frames changed since timestamp (for incremental updates).

Called By:

  • F15 SSE Event Streamer (for reconnection replay)

Input:

flight_id: str
since: datetime

Output: List[int] - Frame IDs changed since timestamp

Test Cases:

  1. Get changes → returns only modified frames
  2. No changes → returns empty list

update_results_after_chunk_merge(flight_id: str, merged_frames: List[int]) -> bool

Description: Updates frame results after chunk merging changes frame poses.

Called By:

  • F11 Failure Recovery Coordinator (after chunk merging)

Input:

flight_id: str
merged_frames: List[int]  # Frames whose poses changed due to chunk merge

Output: bool - True if updated successfully

Processing Flow:

  1. For each frame_id in merged_frames:
    • Get updated pose from F10 Factor Graph Optimizer.get_trajectory() → ENU pose
    • Convert ENU pose to GPS via F13 Coordinate Transformer.enu_to_gps(flight_id, enu_pose)
    • Update frame result via F03 Flight Database.save_frame_result()
    • Update waypoint via F03 Flight Database.update_waypoint()
    • Send refinement event via F15 SSE Event Streamer.send_refinement()
  2. Return True

Test Cases:

  1. Chunk merge updates: All merged frames updated and published
  2. GPS accuracy: Updated GPS matches optimized poses

Integration Tests

Test 1: Per-Frame Processing

  1. Process frame 237
  2. update_frame_result() → stores result
  3. Verify publish_waypoint_update() called (F03.update_waypoint())
  4. Verify F15 SSE event sent

Test 2: Batch Refinement

  1. Process 100 frames
  2. Factor graph refines frames 10-50
  3. mark_refined([10-50]) → updates all
  4. Verify Flight Database updated (F03.batch_update_waypoints())
  5. Verify SSE refinement events sent

Test 3: Incremental Updates

  1. Process frames 1-100
  2. Client disconnects at frame 50
  3. Client reconnects
  4. get_changed_frames(since=frame_50_time)
  5. Client receives frames 51-100

Non-Functional Requirements

Performance

  • update_frame_result: < 50ms
  • publish_waypoint_update: < 100ms (non-blocking)
  • get_flight_results: < 200ms for 2000 frames

Reliability

  • Result persistence survives crashes
  • Guaranteed at-least-once delivery to Flight Database
  • Idempotent updates

Dependencies

Internal Components

  • F03 Flight Database: For waypoint and frame result persistence
  • F10 Factor Graph Optimizer: For refined pose retrieval
  • F13 Coordinate Transformer: For ENU to GPS conversion
  • F15 SSE Event Streamer: For real-time result streaming
  • F11 Failure Recovery Coordinator: Triggers chunk merge result updates

External Dependencies

  • None

Data Models

FrameResult

class ObjectLocation(BaseModel):
    object_id: str
    pixel: Tuple[float, float]
    gps: GPSPoint
    class_name: str
    confidence: float

class FrameResult(BaseModel):
    frame_id: int
    gps_center: GPSPoint
    altitude: float
    heading: float
    confidence: float
    timestamp: datetime
    refined: bool
    objects: List[ObjectLocation]
    updated_at: datetime

FlightResults

class FlightStatistics(BaseModel):
    total_frames: int
    processed_frames: int
    refined_frames: int
    mean_confidence: float
    processing_time: float

class FlightResults(BaseModel):
    flight_id: str
    frames: List[FrameResult]
    statistics: FlightStatistics