skytracker.storage.tables.state.StateTableManager#

class skytracker.storage.tables.state.StateTableManager(database: DatabaseManager)#

Bases: TableManager[State]

Async aircraft state table manager

Properties

TABLE_FIELDS

column_name - column_type pairs

TABLE_KEYS

keys used in database table

TABLE_NAME

name of aircraft state table

Methods

__init__

Initialize table manager by storing database manager

count

Get the number of states stored in the table

ensure_exists

Ensure aircraft state table exists

exists

Check if the aircraft state table exists

get_last_state

Get the last known state of a specific aircraft

get_latest_batch

Get the latest batch of states in the table

get_latest_batch_map

Get the latest batch of states in the table as simple map states

get_nearby

Get aircraft states in range of a specific point

get_track

Get the state history of a specific aircraft

insert_state

Insert a state in the table

insert_states

Insert a list of states in the table

search_state

Search for states matching specific information

__init__(database: DatabaseManager) None#

Initialize table manager by storing database manager

Parameters:

database (DatabaseManager) – ClickHouse database manager

async count() int#

Get the number of states stored in the table

Returns:

number of states stored in table

Return type:

int

async ensure_exists() None#

Ensure aircraft state table exists

async exists() bool#

Check if the aircraft state table exists

Returns:

whether the aircraft state table exists

Return type:

bool

async get_last_state(callsign: str) State | None#

Get the last known state of a specific aircraft

Parameters:

callsign (str) – aircraft callsign (ICAO)

Returns:

last known aircraft state, or None if not found

Return type:

State | None

async get_latest_batch(limit: int = 0, lat_min: float | None = None, lat_max: float | None = None, lon_min: float | None = None, lon_max: float | None = None) list[State]#

Get the latest batch of states in the table

Parameters:
  • limit (int, optional) – maximum number of states to get (0=all). Defaults to 0 (all).

  • lat_min (float, optional) – minimum latitude

  • lat_max (float, optional) – maximmum latitude

  • lon_min (float, optional) – minimum longitude

  • lon_max (float, optional) – maximum longitude

Returns:

list of aircraft states in last batch

Return type:

list[State]

async get_latest_batch_map(limit: int = 0, lat_min: float | None = None, lat_max: float | None = None, lon_min: float | None = None, lon_max: float | None = None) list[MapState]#

Get the latest batch of states in the table as simple map states

Parameters:
  • limit (int, optional) – maximum number of states to get (0=all). Defaults to 0 (all).

  • lat_min (float, optional) – minimum latitude

  • lat_max (float, optional) – maximmum latitude

  • lon_min (float, optional) – minimum longitude

  • lon_max (float, optional) – maximum longitude

Returns:

list of simple map states in last batch

Return type:

list[MapState]

async get_nearby(lat: float, lon: float, radius: float = 50.0, limit: int = 0) list[State]#

Get aircraft states in range of a specific point

Parameters:
  • lat (float) – point latitude

  • lon (float) – point longitude

  • radius (float, optional) – radius around point [km]. Defaults to 50.0 km.

  • limit (int, optional) – maximum number of states to get (0=all). Defaults to 0 (all).

Returns:

list of aircraft states near point

Return type:

list[State]

async get_track(callsign: str, duration: str, limit: int = 0) list[State]#

Get the state history of a specific aircraft

Parameters:
  • callsign (str) – aircraft callsign (ICAO)

  • duration (str) – duration of track (i.e. “5h20m” or “10m20s”)

  • limit (int) – maximum number of states to get (latest first, 0=all)

Returns:

list of aircraft states

Return type:

list[State]

async insert_state(state: State) None#

Insert a state in the table

Parameters:

state (State) – state to insert

async insert_states(states: list[State]) None#

Insert a list of states in the table

Parameters:

states (list[State]) – list of states to insert

async search_state(fields: dict[str, Any], limit: int = 0) list[State]#

Search for states matching specific information

Parameters:
  • fields (dict[str, Any]) – field-value pairs to search for

  • limit (int, optional) – maximum number of states to retrieve (0=all). Defaults to 0.

Returns:

list of states matching fields

Return type:

list[State]

TABLE_FIELDS: dict[str, str] = {'aircraft__iata': 'Nullable(FixedString(4))', 'aircraft__icao': 'Nullable(FixedString(4))', 'aircraft__icao24': 'Nullable(FixedString(6))', 'aircraft__registration': 'Nullable(FixedString(10))', 'airline__iata': 'Nullable(FixedString(3))', 'airline__icao': 'Nullable(FixedString(3))', 'airport__arrival_iata': 'Nullable(FixedString(3))', 'airport__arrival_icao': 'Nullable(FixedString(4))', 'airport__departure_iata': 'Nullable(FixedString(3))', 'airport__departure_icao': 'Nullable(FixedString(4))', 'data_source': "Enum('OPENSKY_NETWORK', 'AVIATION_EDGE')", 'flight__iata': 'Nullable(FixedString(7))', 'flight__icao': 'FixedString(8)', 'flight__number': 'Nullable(UInt16)', 'geography__baro_altitude': 'Nullable(FLOAT)', 'geography__geo_altitude': 'Nullable(FLOAT)', 'geography__heading': 'Nullable(FLOAT)', 'geography__is_on_ground': 'BOOLEAN', 'geography__position': 'Point', 'geography__speed_horizontal': 'Nullable(FLOAT)', 'geography__speed_vertical': 'Nullable(FLOAT)', 'status': "Enum('UNKNOWN', 'EN_ROUTE', 'LANDED', 'STARTED')", 'time': "DateTime('UTC')", 'transponder__squawk': 'Nullable(UInt16)', 'transponder__squawk_time': "Nullable(DateTime('UTC'))"}#

column_name - column_type pairs

Type:

dict[str, str]

TABLE_KEYS: tuple[str] = ('flight__icao', 'time')#

keys used in database table

Type:

tuple[str]

TABLE_NAME = 'state'#

name of aircraft state table

Type:

str