Skip to content

Places

MinConnectTime

Bases: BaseModel

Source code in passengersim/config/places.py
class MinConnectTime(BaseModel, extra="forbid", validate_assignment=True):
    domestic_domestic: int
    """Minimum connect time for domestic to domestic connections in minutes."""

    domestic_international: int
    """Minimum connect time for domestic to international connections in minutes."""

    international_domestic: int
    """Minimum connect time for international to domestic connections in minutes."""

    international_international: int
    """Minimum connect time for international to international connects in minutes."""

domestic_domestic instance-attribute

domestic_domestic: int

Minimum connect time for domestic to domestic connections in minutes.

domestic_international instance-attribute

domestic_international: int

Minimum connect time for domestic to international connections in minutes.

international_domestic instance-attribute

international_domestic: int

Minimum connect time for international to domestic connections in minutes.

international_international instance-attribute

international_international: int

Minimum connect time for international to international connects in minutes.

Place

Bases: BaseModel

Source code in passengersim/config/places.py
class Place(BaseModel, extra="forbid", validate_assignment=True):
    name: str
    """Identifying code for this place.

    For airports, typically the three letter code."""

    label: str
    """A descriptive label for this place."""

    country: str | None = None
    """Country code.

    Recommended to use ISO 3166-1 alpha-2 codes, ie. US / GB / AU / MX / etc."""

    state: str | None = None
    """State code"""

    lat: float | None = None
    """Latitude in degrees."""

    lon: float | None = None
    """Longitude in degrees."""

    time_zone: str | None = None
    """
    The time zone for this location.
    """

    tz_offset: int | None = None
    """Hours offset from GMT"""

    mct: Annotated[
        MinConnectTime | int | None,
        AfterValidator(_inflate_simple_mct),
        BeforeValidator(_reformat_mct),
    ] = None
    """
    Default Minimum Connect Time (MCT) in minutes for this location (Airport).

    This can be given as a single integer, which will be applied to all
    connections, or differentiated by connection type (domestic-domestic,
    domestic-international, etc.).  Connection types can be given using their
    full name (with underscore) or using shorthand codes (DD, DI, ID, II), or
    as a list of 4 integers in the order DD, DI, ID, II.

    Future version of PassengerSim will also allow specific exceptions by
    airline / route / etc.
    """

    @field_validator("time_zone")
    def _valid_time_zone(cls, v: str):
        """Check for valid time zones."""
        if isinstance(v, str):
            ZoneInfo(v)
        return v

    @property
    def time_zone_info(self):
        if self.time_zone is None:
            return None  # No time zone set
        return ZoneInfo(self.time_zone)

country class-attribute instance-attribute

country: str | None = None

Country code.

Recommended to use ISO 3166-1 alpha-2 codes, ie. US / GB / AU / MX / etc.

label instance-attribute

label: str

A descriptive label for this place.

lat class-attribute instance-attribute

lat: float | None = None

Latitude in degrees.

lon class-attribute instance-attribute

lon: float | None = None

Longitude in degrees.

mct class-attribute instance-attribute

mct: Annotated[
    MinConnectTime | int | None,
    AfterValidator(_inflate_simple_mct),
    BeforeValidator(_reformat_mct),
] = None

Default Minimum Connect Time (MCT) in minutes for this location (Airport).

This can be given as a single integer, which will be applied to all connections, or differentiated by connection type (domestic-domestic, domestic-international, etc.). Connection types can be given using their full name (with underscore) or using shorthand codes (DD, DI, ID, II), or as a list of 4 integers in the order DD, DI, ID, II.

Future version of PassengerSim will also allow specific exceptions by airline / route / etc.

name instance-attribute

name: str

Identifying code for this place.

For airports, typically the three letter code.

state class-attribute instance-attribute

state: str | None = None

State code

time_zone class-attribute instance-attribute

time_zone: str | None = None

The time zone for this location.

time_zone_info property

time_zone_info

tz_offset class-attribute instance-attribute

tz_offset: int | None = None

Hours offset from GMT

get_mileage

get_mileage(
    airports: dict[str, Place], orig: str, dest: str
) -> float

Get the distance between two places.

Source code in passengersim/config/places.py
def get_mileage(airports: dict[str, Place], orig: str, dest: str) -> float:
    """Get the distance between two places."""
    if orig not in airports or dest not in airports:
        return 0
    a1 = airports[orig]
    a2 = airports[dest]
    dist = great_circle(a1.latitude, a1.longitude, a2.latitude, a2.longitude)
    return dist

great_circle

great_circle(
    lat1: float, lon1: float, lat2: float, lon2: float
) -> float

Using Haversine formula, to get distance between points in miles.

Source code in passengersim/config/places.py
def great_circle(lat1: float, lon1: float, lat2: float, lon2: float) -> float:
    """Using Haversine formula, to get distance between points in miles."""
    lon1 = math.radians(lon1)
    lat1 = math.radians(lat1)
    lon2 = math.radians(lon2)
    lat2 = math.radians(lat2)
    lon_diff = lon2 - lon1
    lat_diff = lat2 - lat1
    a = math.sin((lat_diff) / 2.0) ** 2.0 + (math.cos(lat1) * math.cos(lat2) * (math.sin((lon_diff) / 2.0) ** 2.0))
    angle2 = 2.0 * math.asin(min(1.0, math.sqrt(a)))
    # Convert back to degrees.
    angle2 = math.degrees(angle2)
    # Each degree on a great circle of Earth is 69.0468 miles. ( 60 nautical miles )
    distance2 = 69.0468 * angle2
    return distance2