Skip to content

Items data

This script provides dataclasses that represent the relational data components in the server.

Aircraft dataclass

Bases: BoundedItem, CoreItem

Aircraft instance.

Parameters:

NameTypeDescriptionDefault
modelstr

Aircraft model and ID

required
seat_capacityint

Seat capacity

required
Source code in src/rmlab/data/items.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
@dataclass
class Aircraft(BoundedItem, CoreItem):
    """Aircraft instance.

    Args:
        model (str): Aircraft model and ID
        seat_capacity (int): Seat capacity
    """

    model: str
    seat_capacity: int

    def __post_init__(self):
        self.seat_capacity = int(self.seat_capacity)

Airline dataclass

Bases: BoundedItem, CoreItem

Airline instance.

Parameters:

NameTypeDescriptionDefault
namestr

Airline name and ID

required
typestr

Airline type (Either 'low-cost' or 'legacy')

'undefined'
Source code in src/rmlab/data/items.py
41
42
43
44
45
46
47
48
49
50
51
@dataclass
class Airline(BoundedItem, CoreItem):
    """Airline instance.

    Args:
        name (str): Airline name and ID
        type (str): Airline type (Either 'low-cost' or 'legacy')
    """

    name: str
    type: str = "undefined"

Airport dataclass

Bases: BoundedItem, CoreItem

Airport instance.

Parameters:

NameTypeDescriptionDefault
namestr

Full airport name

required
city_idstr

City ID of the airport

required
iatastr

IATA code of the airport

required
icaostr

ICAO code of the airport

'undefined'
altitudeint

Location altitude in MAMSL

0
latitudeint

Location latitude

0
longitudeint

Location longitude

0
Source code in src/rmlab/data/items.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
@dataclass
class Airport(BoundedItem, CoreItem):
    """Airport instance.

    Args:
        name (str): Full airport name
        city_id (str): City ID of the airport
        iata (str): IATA code of the airport
        icao (str): ICAO code of the airport
        altitude (int): Location altitude in MAMSL
        latitude (int): Location latitude
        longitude (int): Location longitude
    """

    name: str
    city_id: str
    iata: str
    icao: str = "undefined"
    altitude: int = 0
    latitude: int = 0
    longitude: int = 0

    def __post_init__(self):
        self.altitude = int(self.altitude)
        self.latitude = int(self.latitude)
        self.longitude = int(self.longitude)

City dataclass

Bases: BoundedItem, CoreItem

City instance.

Parameters:

NameTypeDescriptionDefault
namestr

City name and ID

required
country_idstr

Country ID of the city

required
Source code in src/rmlab/data/items.py
87
88
89
90
91
92
93
94
95
96
97
@dataclass
class City(BoundedItem, CoreItem):
    """City instance.

    Args:
        name (str): City name and ID
        country_id (str): Country ID of the city
    """

    name: str
    country_id: str

CityRoute dataclass

Bases: BoundedItem, DerivedItem, CustomersModelHolder, AirlineLocation

Pair of cities with unspecified direction.

Parameters:

NameTypeDescriptionDefault
first_idstr

First city ID of the pair in alphabetical order

required
second_idstr

Second city ID of the pair in alphabetical order

required
Source code in src/rmlab/data/items.py
113
114
115
116
117
118
119
120
121
122
123
@dataclass
class CityRoute(BoundedItem, DerivedItem, CustomersModelHolder, AirlineLocation):
    """Pair of cities with unspecified direction.

    Args:
        first_id (str): First city ID of the pair in alphabetical order
        second_id (str): Second city ID of the pair in alphabetical order
    """

    first_id: str
    second_id: str

CitySector dataclass

Bases: BoundedItem, DerivedItem, CustomersModelHolder, AirlineLocation

Pair of cities with specified direction.

Parameters:

NameTypeDescriptionDefault
origin_idstr

Departure city ID

required
destination_idstr

Arrival city ID

required
Source code in src/rmlab/data/items.py
100
101
102
103
104
105
106
107
108
109
110
@dataclass
class CitySector(BoundedItem, DerivedItem, CustomersModelHolder, AirlineLocation):
    """Pair of cities with specified direction.

    Args:
        origin_id (str): Departure city ID
        destination_id (str): Arrival city ID
    """

    origin_id: str
    destination_id: str

Country dataclass

Bases: BoundedItem, CoreItem

Country instance.

Parameters:

NameTypeDescriptionDefault
namestr

Country name and ID

required
currencyCurrencyKind

Country currency

required
Source code in src/rmlab/data/items.py
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
@dataclass
class Country(BoundedItem, CoreItem):
    """Country instance.

    Args:
        name (str): Country name and ID
        currency (CurrencyKind): Country currency
    """

    name: str
    currency: CurrencyKind

    def __post_init__(self):
        if isinstance(self.currency, str):
            self.currency = CurrencyKind.str_to_enum_value(self.currency)

Flight dataclass

Bases: UnboundedItem, DerivedItem, PricingModelHolder

Flight instance.

Parameters:

NameTypeDescriptionDefault
seat_capacityint

Seat capacity

required
schedule_idstr

Schedule ID

required
sector_idstr

Sector ID

required
citysector_idstr

CitySector ID

required
airline_idstr

Airline ID

required
aircraft_idstr

Aircraft ID

required
flight_numberstr

Flight number identifier

required
onsale_date_timedatetime

Flight is put on sale this date, upto days (year-month-day)

required
departure_date_timedatetime

Departure date and time, upto minutes (year-month-day-hour-minute)

required
faresList[str]

List of fare identifiers

required
lowest_ppsint

Price per seat of the lowest fare in cents

required
highest_ppsint

Price per seat of the highest fare in cents

required
Source code in src/rmlab/data/items.py
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
@dataclass
class Flight(UnboundedItem, DerivedItem, PricingModelHolder):
    """Flight instance.

    Args:
        seat_capacity (int): Seat capacity
        schedule_id (str): Schedule ID
        sector_id (str): Sector ID
        citysector_id (str): CitySector ID
        airline_id (str): Airline ID
        aircraft_id (str): Aircraft ID
        flight_number (str): Flight number identifier
        onsale_date_time (datetime): Flight is put on sale this date, upto days (year-month-day)
        departure_date_time (datetime): Departure date and time, upto minutes (year-month-day-hour-minute)
        fares (List[str]): List of fare identifiers
        lowest_pps (int): Price per seat of the lowest fare in cents
        highest_pps (int): Price per seat of the highest fare in cents
    """

    seat_capacity: int
    schedule_id: str
    sector_id: str
    citysector_id: str
    airline_id: str
    aircraft_id: str
    flight_number: str
    onsale_date_time: datetime
    departure_date_time: datetime
    fares: List[str]
    lowest_pps: int
    highest_pps: int

    def __post_init__(self):
        self.seat_capacity = int(self.seat_capacity)
        self.fares = self.fares.split("-")
        self.lowest_pps = self.lowest_pps
        self.highest_pps = self.highest_pps
        self.onsale_date_time = datetime.strptime(self.onsale_date_time, DateFormat).replace(tzinfo=timezone.utc)
        self.departure_date_time = datetime.strptime(self.departure_date_time, DateTimeMinFormat).replace(tzinfo=timezone.utc)

PModel dataclass

Bases: BoundedItem, CoreItem

Item holding a set of parameters.

Parameters:

NameTypeDescriptionDefault
filenamestr

Name of file storing the parameters

required
hashstr

MD5 hash of the content

required
cntstr

Model content

required
Source code in src/rmlab/data/items.py
26
27
28
29
30
31
32
33
34
35
36
37
38
@dataclass
class PModel(BoundedItem, CoreItem):
    """Item holding a set of parameters.

    Args:
        filename (str): Name of file storing the parameters
        hash (str): MD5 hash of the content
        cnt (str): Model content
    """

    filename: str
    hash: str
    cnt: str

Route dataclass

Bases: BoundedItem, DerivedItem, AirlineLocation

Pair of airports with unspecified direction.

Parameters:

NameTypeDescriptionDefault
first_idstr

First airport ID of the pair in alphabetical order

required
second_idstr

Second airport ID of the pair in alphabetical order

required
Source code in src/rmlab/data/items.py
168
169
170
171
172
173
174
175
176
177
178
179
@dataclass
class Route(BoundedItem, DerivedItem, AirlineLocation):
    """Pair of airports with unspecified direction.

    Args:
        first_id (str): First airport ID of the pair in alphabetical order
        second_id (str): Second airport ID of the pair in alphabetical order
    """

    first_id: str
    second_id: str
    cityroute_id: str

Schedule dataclass

Bases: UnboundedItem, CoreItem

Schedule instance. Template generator for flights in an airline with common aircraft, sector and days of week.

Parameters:

NameTypeDescriptionDefault
airline_idstr

Airline ID

required
aircraft_idstr

Aircraft ID

required
origin_idstr

Departure airport ID

required
destination_idstr

Arrival airport ID

required
days_of_weekList[DayOfWeek]

Days of week

required
departure_timetimedelta

Departure time upto minutes (hour-minutes)

required
durationtimedelta

Flight duration upto minutes (hour-minutes)

required
flight_numberint

Flight number identifier

required
sell_before_daysint

Flights are put on sale these days before departure day

required
from_datedatetime

Start date of the range of flight departures, upto days (year-month-day)

required
to_datedatetime

End date of the range of flight departures, up to days (year-month-day)

required
sector_idstr

Sector ID

required
citysector_idstr

CitySector ID

required
route_idstr

Route ID

required
cityroute_idstr

CityRoute ID

required
from_date_loaddatetime

Start date of the selling period, upto days (year-month-day)

required
to_date_loaddatetime

End date of the selling period, upto days (year-month-day)

required
from_date_departuredatetime

Date of the first departure, upto days (year-month-day)

required
to_date_departuredatetime

Date of the last departure, up to days (year-month-day)

required
Source code in src/rmlab/data/items.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
@dataclass
class Schedule(UnboundedItem, CoreItem):
    """Schedule instance. Template generator for flights in an airline with common aircraft, sector and days of week.

    Args:
        airline_id (str): Airline ID
        aircraft_id (str): Aircraft ID
        origin_id (str): Departure airport ID
        destination_id (str): Arrival airport ID
        days_of_week (List[DayOfWeek]): Days of week
        departure_time (timedelta): Departure time upto minutes (hour-minutes)
        duration (timedelta): Flight duration upto minutes (hour-minutes)
        flight_number (int): Flight number identifier
        sell_before_days (int): Flights are put on sale these days before departure day
        from_date (datetime): Start date of the range of flight departures, upto days (year-month-day)
        to_date (datetime): End date of the range of flight departures, up to days (year-month-day)
        sector_id (str): Sector ID
        citysector_id (str): CitySector ID
        route_id (str): Route ID
        cityroute_id (str): CityRoute ID
        from_date_load (datetime): Start date of the selling period, upto days (year-month-day)
        to_date_load (datetime): End date of the selling period, upto days (year-month-day)
        from_date_departure (datetime): Date of the first departure, upto days (year-month-day)
        to_date_departure (datetime): Date of the last departure, up to days (year-month-day)

    """

    airline_id: str
    aircraft_id: str
    origin_id: str
    destination_id: str
    days_of_week: List[DayOfWeek]
    departure_time: timedelta
    duration: timedelta
    flight_number: str
    sell_before_days: int
    from_date: datetime
    to_date: datetime
    sector_id: str
    citysector_id: str
    route_id: str
    cityroute_id: str
    from_date_load: datetime
    to_date_load: datetime
    from_date_departure: datetime
    to_date_departure: datetime

    def __post_init__(self):

        self.sell_before_days = int(self.sell_before_days)

        if isinstance(self.days_of_week, int):
            self.days_of_week = str(self.days_of_week)

        self.days_of_week = [
            DayOfWeek.int_to_enum_value(int(d))
            for d in self.days_of_week.replace("-", "")
        ]

        self.departure_time = self.departure_time

        if isinstance(self.from_date, str):
            self.from_date = datetime.strptime(self.from_date, DateFormat).replace(tzinfo=timezone.utc)
        elif not isinstance(self.from_date, datetime):
            raise TypeError(f"Expected string or datetime in field `from_date`")
        if isinstance(self.to_date, str):
            self.to_date = datetime.strptime(self.to_date, DateFormat).replace(tzinfo=timezone.utc)
        elif not isinstance(self.to_date, datetime):
            raise TypeError(f"Expected string or datetime in field `to_date`")
        # Expect following datetime fields to be strings since they come from server
        self.from_date_load = datetime.strptime(self.from_date_load, DateFormat).replace(tzinfo=timezone.utc)
        self.to_date_load = datetime.strptime(self.to_date_load, DateFormat).replace(tzinfo=timezone.utc)
        self.from_date_departure = datetime.strptime(self.from_date_departure, DateFormat).replace(tzinfo=timezone.utc)
        self.to_date_departure = datetime.strptime(self.to_date_departure, DateFormat).replace(tzinfo=timezone.utc)

        self.departure_time = timedelta(minutes=int(self.departure_time))
        self.duration = timedelta(minutes=int(self.duration))

Sector dataclass

Bases: BoundedItem, DerivedItem, AirlineLocation

Pair of airports with specified direction.

Parameters:

NameTypeDescriptionDefault
origin_idstr

Departure airport ID

required
destination_idstr

Arrival airport ID

required
Source code in src/rmlab/data/items.py
154
155
156
157
158
159
160
161
162
163
164
165
@dataclass
class Sector(BoundedItem, DerivedItem, AirlineLocation):
    """Pair of airports with specified direction.

    Args:
        origin_id (str): Departure airport ID
        destination_id (str): Arrival airport ID
    """

    origin_id: str
    destination_id: str
    citysector_id: str