-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiles_tables.py
More file actions
125 lines (110 loc) · 4.13 KB
/
miles_tables.py
File metadata and controls
125 lines (110 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""Miles accrual tables for CX Marco Polo and SQ KrisFlyer."""
from __future__ import annotations
# ---------------------------------------------------------------------------
# Fare class earn multipliers
# ---------------------------------------------------------------------------
# CX Marco Polo Club — tier miles multiplier per fare class
# Source: Cathay Pacific Marco Polo Club earning table
MARCO_POLO_MULTIPLIERS: dict[str, float] = {
"F": 1.5, # First
"A": 1.5, # First (promo)
"J": 1.25, # Business
"C": 1.25, # Business
"D": 1.25, # Business
"I": 1.0, # Business (lower)
"W": 0.0, # Premium Economy (no tier miles)
"R": 0.0, # Premium Economy (no tier miles)
"E": 0.0, # Premium Economy (no tier miles)
"Y": 1.0, # Economy full fare
"B": 1.0, # Economy
"H": 0.75, # Economy
"K": 0.5, # Economy
"M": 0.5, # Economy
"L": 0.25, # Economy
"V": 0.0, # Economy (no tier miles)
"G": 0.0, # Economy (no tier miles)
"S": 0.0, # Economy (no tier miles)
"O": 0.0, # Economy (no tier miles)
"Q": 0.25, # Economy
"N": 0.25, # Economy
"T": 0.0, # Economy (no tier miles)
"X": 0.0, # Economy (no tier miles)
"P": 0.0, # Economy (no tier miles)
}
# SQ KrisFlyer — tier miles (PPS Value) multiplier per fare class
# Source: Singapore Airlines KrisFlyer earning table
KRISFLYER_MULTIPLIERS: dict[str, float] = {
"F": 1.5, # First / Suites
"P": 1.5, # First (promo)
"J": 1.25, # Business
"C": 1.25, # Business
"D": 1.25, # Business
"U": 1.0, # Business (lower)
"Z": 1.0, # Business (lower)
"W": 0.75, # Premium Economy
"R": 0.75, # Premium Economy
"E": 0.75, # Premium Economy
"T": 0.75, # Premium Economy
"Y": 1.0, # Economy full fare
"B": 1.0, # Economy
"G": 0.75, # Economy
"S": 0.75, # Economy
"H": 0.75, # Economy
"Q": 0.5, # Economy
"K": 0.5, # Economy
"M": 0.5, # Economy
"L": 0.25, # Economy
"V": 0.25, # Economy
"A": 0.0, # Economy (no tier miles)
"N": 0.0, # Economy (no tier miles)
"O": 0.0, # Economy (no tier miles)
}
# ---------------------------------------------------------------------------
# Route distances (air miles, statute miles)
# ---------------------------------------------------------------------------
ROUTE_DISTANCES_MI: dict[frozenset[str], int] = {
frozenset({"HKG", "NRT"}): 2894,
frozenset({"HKG", "TYO"}): 2894, # alias
frozenset({"HKG", "SIN"}): 1597,
frozenset({"HKG", "LHR"}): 5986,
frozenset({"HKG", "LAX"}): 7260,
frozenset({"HKG", "SFO"}): 6905,
frozenset({"HKG", "SYD"}): 4587,
frozenset({"HKG", "ICN"}): 1309,
frozenset({"HKG", "BKK"}): 1072,
frozenset({"SIN", "LHR"}): 6764,
frozenset({"SIN", "NRT"}): 3321,
frozenset({"SIN", "SYD"}): 3908,
frozenset({"SIN", "LAX"}): 8753,
frozenset({"HKG", "SFO"}): 6905,
frozenset({"HKG", "ORD"}): 7797,
frozenset({"HKG", "JFK"}): 8054,
frozenset({"HKG", "CDG"}): 5980,
frozenset({"HKG", "FRA"}): 5737,
}
# ---------------------------------------------------------------------------
# Multiplier table lookup by airline
# ---------------------------------------------------------------------------
_AIRLINE_MULTIPLIER_TABLES: dict[str, dict[str, float]] = {
"CX": MARCO_POLO_MULTIPLIERS,
"SQ": KRISFLYER_MULTIPLIERS,
}
def calculate_miles(airline: str, fare_class: str, origin: str, dest: str) -> int | None:
"""Calculate estimated tier miles for a given flight.
Returns None if:
- Airline not in supported tables
- Route not in distance table
- fare_class earns 0 multiplier (still returns 0, not None)
Returns None only for unknown route or unsupported airline.
"""
table = _AIRLINE_MULTIPLIER_TABLES.get(airline.upper())
if table is None:
return None
route_key = frozenset({origin.upper(), dest.upper()})
distance = ROUTE_DISTANCES_MI.get(route_key)
if distance is None:
return None
multiplier = table.get(fare_class.upper(), None)
if multiplier is None:
return None
return round(distance * multiplier)