SXXXXXXX_FlightMonitor/flightmonitor/data/config.py
2025-06-13 09:13:13 +02:00

103 lines
4.9 KiB
Python

# FlightMonitor/data/config.py
from typing import Optional, Dict
import os # Required for os.getenv
"""
Global configurations for the FlightMonitor application.
This file centralizes constants and settings used across different modules,
making them easier to manage and modify. Each configuration option should
be clearly documented.
"""
# --- API Configuration ---
# Base URL for the OpenSky Network API's 'states/all' endpoint.
OPENSKY_API_URL: str = "https://opensky-network.org/api/states/all" # Used for direct calls with OAuth2
# Default timeout for API requests in seconds.
DEFAULT_API_TIMEOUT_SECONDS: int = 15
# --- OpenSky Network API Authentication Configuration ---
# Set to True to attempt authentication with OpenSky Network API using OAuth2 Client Credentials.
# If False, or if Client ID/Secret are not provided, anonymous access will be used.
USE_OPENSKY_CREDENTIALS: bool = True # Set this to True to enable OAuth2 authentication
# Your OpenSky Network API Client ID.
OPENSKY_CLIENT_ID: Optional[str] = "luca.vallongo@gmail.com-api-client" # os.getenv("OPENSKY_CLIENT_ID")
# Your OpenSky Network API Client Secret.
OPENSKY_CLIENT_SECRET: Optional[str] = "heEkoeugbCmfKml5wTxk9ywoPFW1Z3vW" # os.getenv("OPENSKY_CLIENT_SECRET")
# OpenSky Network Token URL (used for OAuth2 Client Credentials Flow)
# MODIFICATION: Corrected the entire URL to match the official documentation, including the 'auth.' subdomain.
OPENSKY_TOKEN_URL: str = "https://auth.opensky-network.org/auth/realms/opensky-network/protocol/openid-connect/token"
# Removed OPENSKY_USERNAME and OPENSKY_PASSWORD as they are for Basic Auth (being deprecated)
# --- ADS-B Exchange API Configuration (Placeholder for future) ---
# LIVE_DATA_SOURCE: str = "OPENSKY" # Options: "OPENSKY", "ADSB_EXCHANGE", "MOCK"
# ADSBEXCHANGE_API_KEY: Optional[str] = os.getenv("ADSBEXCHANGE_API_KEY", None)
# ADSBEXCHANGE_API_URL: str = "https://adsbexchange.com/api/aircraft/v2/lat/{lat_min}/lon/{lon_min}/latmax/{lat_max}/lonmax/{lon_max}/"
# --- Flag per Mock API ---
USE_MOCK_OPENSKY_API: bool = False
MOCK_API_FLIGHT_COUNT: int = 50
MOCK_API_ERROR_SIMULATION: Optional[str] = None
MOCK_RETRY_AFTER_SECONDS: int = 60 # Example for mock
MOCK_HTTP_ERROR_STATUS: int = 500 # Example for mock
# --- Polling Interval Configuration ---
# MODIFICATO: Introdotti due valori distinti per il polling rate.
# PERCHE': Per differenziare il rate in base allo stato di autenticazione.
# COME: Aggiunte due costanti.
AUTHENTICATED_POLLING_INTERVAL: int = 5 # Polling rate for authenticated users (in seconds)
ANONYMOUS_POLLING_INTERVAL: int = 15 # Polling rate for anonymous users (in seconds)
# MODIFICATO: LIVE_POLLING_INTERVAL_SECONDS ora viene calcolato dinamicamente.
# PERCHE': Per selezionare automaticamente il rate corretto in base alla configurazione.
# COME: Usata un'espressione condizionale che controlla sia il flag che la presenza delle credenziali.
LIVE_POLLING_INTERVAL_SECONDS: int = (
AUTHENTICATED_POLLING_INTERVAL
if USE_OPENSKY_CREDENTIALS and OPENSKY_CLIENT_ID and OPENSKY_CLIENT_SECRET
else ANONYMOUS_POLLING_INTERVAL
)
# --- GUI Configuration ---
DEFAULT_BBOX_LAT_MIN: float = 44.986
DEFAULT_BBOX_LON_MIN: float = 7.9341
DEFAULT_BBOX_LAT_MAX: float = 46.9567
DEFAULT_BBOX_LON_MAX: float = 10.5997
DEFAULT_CANVAS_WIDTH: int = 800
DEFAULT_CANVAS_HEIGHT: int = 600
MAP_TILE_CACHE_DIR: str = "flightmonitor_tile_cache"
COORDINATE_DECIMAL_PLACES: int = 5 # Added for consistency for GUI display of coordinates
DEFAULT_TRACK_HISTORY_POINTS: int = 20 # Moved from main_window
MAP_SIZE_KM_DECIMAL_PLACES: int = 1
TRACK_MAX_AGE_HOURS_FOR_CONTINUITY: int = 1 # Max age in hours for a track to be considered continuous
# --- Data Storage Configuration ---
DATABASE_DIRECTORY: str = "flight_data_history"
DATABASE_FILENAME_FORMAT: str = "flights_%Y-%m-%d.db"
# --- Raw Data Logging Configuration ---
RAW_DATA_LOGGING_ENABLED: bool = False
RAW_DATA_LOGGING_DEFAULT_DIR: str = "Atc_download"
# --- GUI Layout Configuration ---
LAYOUT_MAIN_HORIZONTAL_WEIGHTS: Dict[str, int] = {"left_column": 20, "right_column": 80}
LAYOUT_MAIN_HORIZONTAL_MIN_SIZES: Dict[str, int] = {"left_column": 100, "right_column": 400}
LAYOUT_LEFT_VERTICAL_WEIGHTS: Dict[str, int] = {"function_notebook": 70, "log_status_area": 30}
LAYOUT_LEFT_VERTICAL_MIN_SIZES: Dict[str, int] = {"function_notebook": 200, "log_status_area": 100}
LAYOUT_RIGHT_VERTICAL_WEIGHTS: Dict[str, int] = {"views_notebook": 80, "map_tools_info": 20}
LAYOUT_RIGHT_VERTICAL_MIN_SIZES: Dict[str, int] = {"views_notebook": 300, "map_tools_info": 120}
LAYOUT_TOOLS_INFO_HORIZONTAL_WEIGHTS: Dict[str, int] = {"map_tools": 20, "map_info": 80}
LAYOUT_TOOLS_INFO_HORIZONTAL_MIN_SIZES: Dict[str, int] = {"map_tools": 150, "map_info": 200}
LAYOUT_BOTTOM_PANELS_HORIZONTAL_WEIGHTS: Dict[str, int] = {"map_tools": 20, "map_info": 35, "flight_details": 45}
LAYOUT_START_MAXIMIZED: bool = True
LAYOUT_WINDOW_MIN_WIDTH: int = 700
LAYOUT_WINDOW_MIN_HEIGHT: int = 500