mirror of
https://github.com/azaion/gps-denied-onboard.git
synced 2026-04-23 06:16:38 +00:00
feat: stage1 — domain schemas, SSE events, pydantic-settings config
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
"""Application configuration loaded from environment / YAML."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class DatabaseConfig(BaseSettings):
|
||||
"""Database connection settings."""
|
||||
|
||||
model_config = SettingsConfigDict(env_prefix="DB_")
|
||||
|
||||
url: str = Field(
|
||||
default="sqlite+aiosqlite:///./flight_data.db",
|
||||
description="SQLAlchemy async connection URL",
|
||||
)
|
||||
echo: bool = False
|
||||
|
||||
|
||||
class APIConfig(BaseSettings):
|
||||
"""API server settings."""
|
||||
|
||||
model_config = SettingsConfigDict(env_prefix="API_")
|
||||
|
||||
host: str = "127.0.0.1"
|
||||
port: int = 8000
|
||||
reload: bool = True
|
||||
cors_origins: list[str] = Field(default_factory=lambda: ["*"])
|
||||
|
||||
|
||||
class TileProviderConfig(BaseSettings):
|
||||
"""Satellite tile provider settings (Google Maps by default)."""
|
||||
|
||||
model_config = SettingsConfigDict(env_prefix="TILES_")
|
||||
|
||||
provider: str = "google"
|
||||
api_key: str = ""
|
||||
cache_dir: Path = Path("tile_cache")
|
||||
zoom_level: int = 18
|
||||
max_concurrent_requests: int = 4
|
||||
|
||||
|
||||
class ModelPaths(BaseSettings):
|
||||
"""Paths to ML model weights."""
|
||||
|
||||
model_config = SettingsConfigDict(env_prefix="MODEL_")
|
||||
|
||||
weights_dir: Path = Path("weights")
|
||||
superpoint_path: str = "superpoint.pt"
|
||||
lightglue_path: str = "lightglue.pt"
|
||||
litesam_path: str = "litesam.pt"
|
||||
|
||||
|
||||
class OperationalArea(BaseSettings):
|
||||
"""Default operational boundaries."""
|
||||
|
||||
model_config = SettingsConfigDict(env_prefix="AREA_")
|
||||
|
||||
name: str = "Eastern Ukraine"
|
||||
min_lat: float = 45.0
|
||||
max_lat: float = 52.0
|
||||
min_lon: float = 22.0
|
||||
max_lon: float = 40.0
|
||||
|
||||
|
||||
class RecoveryConfig(BaseSettings):
|
||||
"""Failure recovery and progressive search settings."""
|
||||
|
||||
model_config = SettingsConfigDict(env_prefix="RECOVERY_")
|
||||
|
||||
search_grid_sizes: list[int] = Field(default_factory=lambda: [1, 4, 9, 16, 25])
|
||||
min_chunk_frames: int = 5
|
||||
max_chunk_frames: int = 20
|
||||
user_input_threshold_tiles: int = 25
|
||||
confidence_threshold_good: float = 0.7
|
||||
confidence_threshold_degraded: float = 0.5
|
||||
min_inlier_count_good: int = 50
|
||||
min_inlier_count_tracking: int = 20
|
||||
|
||||
|
||||
class RotationConfig(BaseSettings):
|
||||
"""Image rotation and heading tracking settings."""
|
||||
|
||||
model_config = SettingsConfigDict(env_prefix="ROTATION_")
|
||||
|
||||
step_degrees: float = 30.0
|
||||
litesam_max_tolerance: float = 45.0
|
||||
sharp_turn_threshold: float = 45.0
|
||||
heading_history_size: int = 10
|
||||
confidence_threshold: float = 0.7
|
||||
|
||||
@property
|
||||
def rotation_iterations(self) -> int:
|
||||
return int(360 / self.step_degrees)
|
||||
|
||||
|
||||
class AppSettings(BaseSettings):
|
||||
"""Root settings — aggregates all sub-configs."""
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
env_nested_delimiter="__",
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
db: DatabaseConfig = Field(default_factory=DatabaseConfig)
|
||||
api: APIConfig = Field(default_factory=APIConfig)
|
||||
tiles: TileProviderConfig = Field(default_factory=TileProviderConfig)
|
||||
models: ModelPaths = Field(default_factory=ModelPaths)
|
||||
area: OperationalArea = Field(default_factory=OperationalArea)
|
||||
recovery: RecoveryConfig = Field(default_factory=RecoveryConfig)
|
||||
rotation: RotationConfig = Field(default_factory=RotationConfig)
|
||||
|
||||
|
||||
def get_settings() -> AppSettings:
|
||||
"""Singleton-like factory for application settings."""
|
||||
return AppSettings()
|
||||
Reference in New Issue
Block a user