Skip to content

Upload API Core items

Interface for core data uploading.

APIUploadCore

Bases: APIUploadInternal

Exposes functions for uploading local data to the server.

Source code in src/rmlab/api/upload/core.py
 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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
259
260
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
class APIUploadCore(APIUploadInternal):
    """Exposes functions for uploading local data to the server."""

    async def upload_aircrafts(self, scen_id: int, items: Union[str, list]) -> None:
        """Upload a set of aircrafts defined in a file.


        Args:
            scen_id (int): Scenario ID
            items (str): Filename `.csv` or `.json` defining the aircrafts

        Where `items` can refer to:

        * a **CSV file**, for instance:
        ```csv
        Model,Seat capacity
        Airbus A320-a,174
        Airbus A320-b,180
        ```

        * a **JSON file**, for instance:
        ```json
        [
            {"model": "Airbus A320-a", "seat_capacity": 174},
            {"model": "Airbus A320-b", "seat_capacity": 180},
        ]

        * a **JSON list** like the previous.
        ```

        Raises:
            ValueError: If file extension is invalid
            FileNotFoundError: If file does not exist
        """

        await self._upload_bounded_items(
            scen_id=scen_id, category=Aircraft, items=items
        )

    async def upload_airlines(self, scen_id: int, items: Union[str, list]) -> None:
        """Upload a set of airlines defined in a file.

        Args:
            scen_id (int): Scenario ID
            items (str): Filename `.csv` or `.json` defining the airlines

        Where `items` can refer to:

        * a **CSV file**, for instance:
        ```csv
        Name,Type
        MyCarrier,low-cost
        AnotherCarrier,low-cost
        MyLegacyCarrier,legacy
        ```

        * a **JSON file**, for instance:
        ```json
        [
            {"name": "MyCarrier", "type": "low-cost"},
            {"name": "AnotherCarrier", "type": "low-cost"},
            {"name": "MyLegacyCarrier", "type": "legacy"},
        ]

        * a **JSON list** like the previous.
        ```

        Raises:
            ValueError: If file extension is invalid
            FileNotFoundError: If file does not exist
        """

        await self._upload_bounded_items(
            scen_id=scen_id, category=Airline, items=items
        )

    async def upload_airports(self, scen_id: int, items: Union[str, list]) -> None:
        """Upload a set of airports defined in a file.

        Args:
            scen_id (int): Scenario ID
            items (str): Filename `.csv` or `.json` defining the airports

        Where `items` can refer to:

        * a **CSV file**, for instance:
        ```csv
        Name,City,Altitude,Latitude,Longitude,ICAO,IATA
        Geneva,Geneva,431,46.238,6.109,LSGG,GVA
        Madrid,Madrid,619,40.294,-3.724,LEMD,MAD
        London Gatwick,London,60,51.148,-0.19,EGKK,LGW
        London Heathrow,London,25,51.477,-0.461,EGLL,LHR
        ```

        * a **JSON file**, for instance:
        ```json
        [
            {"name": "Geneva", "city": "Geneva", "altitude": 431, "latitude": 46.238, "longitude": 6.109, "icao": "LSGG", "iata": "GVA"},
            {"name": "Madrid", "city": "Madrid", "altitude": 619, "latitude": 40.294, "longitude": -3.724, "icao": "LEMD", "iata": "MAD"},
            {"name": "London Gatwick", "city": "London", "altitude": 60, "latitude": 51.148, "longitude": -0.19, "icao": "EGKK", "iata": "LGW"},
            {"name": "London Heathrow", "city": "London", "altitude": 25, "latitude": 51.477, "longitude": -0.461, "icao": "EGLL", "iata": "LHR"},
        ]

        * a **JSON list** like the previous.
        ```

        * **NOTE**: Airport *cities* must reference previously uploaded ``City`` items with the same `City.name`.

        Raises:
            ValueError: If file extension is invalid
            FileNotFoundError: If file does not exist
            rmlab_errors.ClientError: If any of the referenced cities does not exist in server
        """

        await self._upload_bounded_items(
            scen_id=scen_id, category=Airport, items=items
        )

    async def upload_cities(self, scen_id: int, items: Union[str, list]) -> None:
        """Upload a set of cities defined in a file.

        Args:
            scen_id (int): Scenario ID
            items (str): Filename `.csv` or `.json` defining the cities

        Where ``items`` can refer to:

        * a **CSV file**, for instance:
        ```csv
        Name,Country
        Geneva,Swizterland
        Madrid,Spain
        London,United Kingdom
        ```

        * a **JSON file**, for instance:
        ```json
        [
            {"name": "Geneva", "country": "Switzerland"},
            {"name": "Madrid", "country": "Spain"},
            {"name": "London", "country": "United Kingdom"},
        ]

        * a **JSON list** like the previous.
        ```

        * **NOTE**: City *countries* must reference previously uploaded ``Country`` items with the same `Country.name`.

        Raises:
            ValueError: If file extension is invalid
            FileNotFoundError: If file does not exist
            rmlab_errors.ClientError: If any of the referenced countries does not exist in server
        """

        await self._upload_bounded_items(
            scen_id=scen_id, category=City, items=items
        )

    async def upload_countries(self, scen_id: int, items: Union[str, list]) -> None:
        """Upload a set of countries defined in a file.

        Args:
            scen_id (int): Scenario ID
            items (str): Filename `.csv` or `.json` defining the countries

        Where `items` can refer to:

        * a **CSV file**, for instance:
        ```csv
        Name,Currency
        Swizterland,chf
        Spain,eur
        United Kingdom,gbp
        ```

        * a **JSON file**, for instance:
        ```json
        [
            {"name": "Switzerland", "currency": "chf"},
            {"name": "Spain", "currency": "eur"},
            {"name": "United Kingdom", "currency": "gbp"},
        ]

        * a **JSON list** like the previous.
        ```

        Raises:
            ValueError: If file extension is invalid
            FileNotFoundError: If file does not exist
        """

        await self._upload_bounded_items(
            scen_id=scen_id, category=Country, items=items
        )

    async def upload_schedules(
        self,
        scen_id: int,
        items: Union[str, list],
        *,
        citysector_id: Optional[str] = None,
        sector_id: Optional[str] = None,
    ) -> None:
        """Upload a set of flights schedules defined in a file.

        Args:
            scen_id (int): Scenario ID
            items (str): Filename `.csv` or `.json` defining the schedules
            citysector_id (Optional[str], optional): A citysector ID if all schedules belong to the same citysector. Defaults to None.
            sector_id (Optional[str], optional): A sector ID if all schedules belong to the same sector. Defaults to None.

        Arguments `citysector_id` and `sector_id` are always optional. If provided, concurrent uploads of schedules
            files belonging to different citysectors/sectors are allowed.

        Where `items` can refer to:

        * a **CSV file**, for instance:
        ```csv
        Airline,Aircraft,Origin,Destination,Days of Week,Departure time,Duration,Flight number,Sell before days,From Date,To Date
        MyCarrier,Airbus A320-b,MAD,GVA,-2-4-6-,T08:00,T02:00,2277,15,2022-04-01,2022-05-31
        MyCarrier,Airbus A320-a,MAD,GVA,1-3-5-7,T16:00,T02:00,2278,15,2022-04-01,2022-05-31
        MyCarrier,Airbus A320-b,GVA,MAD,-2-4-6-,T10:30,T01:30,2377,15,2022-04-01,2022-05-31
        MyCarrier,Airbus A320-a,GVA,MAD,1-3-5-7,T18:30,T01:30,2378,15,2022-04-01,2022-05-31
        ```

        * a **JSON file**, for instance:
        ```json
        [
            {"airline": "MyCarrier", "aircraft": "Airbus A320-b", "origin": "MAD", "destination": "GVA", "days_of_week": "-2-4-6-", "departure_time": "T08:00", "duration": "T02:00", "flight_number": "2277", "sell_before_days": 45, "from_date": "2022-04-01", "to_date": "2022-05-31"},
            {"airline": "MyCarrier", "aircraft": "Airbus A320-b", "origin": "MAD", "destination": "GVA", "days_of_week": "1-3-5-7", "departure_time": "T16:00", "duration": "T02:00", "flight_number": "2278", "sell_before_days": 45, "from_date": "2022-04-01", "to_date": "2022-05-31"},
            {"airline": "MyCarrier", "aircraft": "Airbus A320-b", "origin": "GVA", "destination": "MAD", "days_of_week": "-2-4-6-", "departure_time": "T10:30", "duration": "T01:30", "flight_number": "2377", "sell_before_days": 45, "from_date": "2022-04-01", "to_date": "2022-05-31"},
            {"airline": "MyCarrier", "aircraft": "Airbus A320-b", "origin": "GVA", "destination": "MAD", "days_of_week": "1-3-5-7", "departure_time": "T10:30", "duration": "T01:30", "flight_number": "2378", "sell_before_days": 45, "from_date": "2022-04-01", "to_date": "2022-05-31"},
        ]

        * a **JSON list** like the previous.
        ```

        * **NOTE**: Schedule *airlines* must reference previously uploaded ``Airline`` items with the same `Airline.name`.
        * **NOTE**: Schedule *aircrafts* must reference previously uploaded ``Aircraft`` items with the same `Aircraft.model`.
        * **NOTE**: Schedule *origins* must reference previously uploaded ``Airport`` items with the same `Airport.iata`.
        * **NOTE**: Schedule *destinations* must reference previously uploaded ``Airport`` items with the same `Airport.iata`.
        * **NOTE**: No two schedules with overlapping date ranges (*from_date*, *to_date*), and overlapping days of week, with the same *flight_number* are allowed.


        Raises:
            ValueError: If file extension is invalid
            FileNotFoundError: If file does not exist
            rmlab_errors.ClientError: If any of the previous Notes are not satisfied
        """

        await self._upload_unbounded_items(
            scen_id,
            Schedule,
            items,
            citysector_id=citysector_id,
            sector_id=sector_id,
        )

    async def upload_batch_core(
        self,
        scen_id: int,
        *,
        aircraft_items: Optional[Union[str,list]] = None,
        airline_items: Optional[Union[str,list]] = None,
        airport_items: Optional[Union[str,list]] = None,
        city_items: Optional[Union[str,list]] = None,
        country_items: Optional[Union[str,list]] = None,
        schedule_items: Optional[Union[str,list]] = None,
    ):
        """Upload a set of items defined in files to server.

        Args:
            scen_id (int): Scenario ID
            aircraft_items (Optional[Union[str,list]], optional): Aircraft items. Defaults to None.
            airline_items (Optional[Union[str,list]], optional): Airline items. Defaults to None.
            airport_items (Optional[Union[str,list]], optional): Airport items. Defaults to None.
            city_items (Optional[Union[str,list]], optional): City items. Defaults to None.
            country_items (Optional[Union[str,list]], optional): Country items. Defaults to None.
            schedule_items (Optional[Union[str,list]], optional): Flights schedule items. Defaults to None.

        Raises:
            FileNotFoundError: If a file with items doesn't exist
            TypeError: If non-file items are not list-typed.
            MultipleError: If several errors happened.
        """

        not_existing_fns = [
            FileNotFoundError(items_fn)
            for items_fn in [
                aircraft_items,
                airline_items,
                airport_items,
                city_items,
                country_items,
                schedule_items,
            ]
            if isinstance(items_fn, str) and (not os.path.exists(items_fn))
        ]

        invalid_types = [
            TypeError(name)
            for name, items in [
                ("aircraft_items", aircraft_items),
                ("airline_items", airline_items),
                ("airport_items", airport_items),
                ("city_items", city_items),
                ("country_items", country_items),
                ("schedule_items", schedule_items),
            ]
            if (not isinstance(items, list)) and (not isinstance(items, str))
        ]

        raise_from_list(not_existing_fns + invalid_types)

        if airline_items:
            await self._upload_bounded_items(scen_id, Airline, items=airline_items)

        if aircraft_items:
            await self._upload_bounded_items(scen_id, Aircraft, items=aircraft_items)

        if country_items:
            await self._upload_bounded_items(scen_id, Country, items=country_items)

        if city_items:
            await self._upload_bounded_items(scen_id, City, items=city_items)

        if airport_items:
            await self._upload_bounded_items(scen_id, Airport, items=airport_items)

        if schedule_items:
            await self._upload_unbounded_items(scen_id, Schedule, items=schedule_items)

upload_aircrafts(scen_id, items) async

Upload a set of aircrafts defined in a file.

Parameters:

NameTypeDescriptionDefault
scen_idint

Scenario ID

required
itemsstr

Filename .csv or .json defining the aircrafts

required

Where items can refer to:

  • a CSV file, for instance:

    Model,Seat capacity
    Airbus A320-a,174
    Airbus A320-b,180
    

  • a JSON file, for instance:

    [
        {"model": "Airbus A320-a", "seat_capacity": 174},
        {"model": "Airbus A320-b", "seat_capacity": 180},
    ]
    
    * a **JSON list** like the previous.
    

Raises:

TypeDescription
ValueError

If file extension is invalid

FileNotFoundError

If file does not exist

Source code in src/rmlab/api/upload/core.py
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
async def upload_aircrafts(self, scen_id: int, items: Union[str, list]) -> None:
    """Upload a set of aircrafts defined in a file.


    Args:
        scen_id (int): Scenario ID
        items (str): Filename `.csv` or `.json` defining the aircrafts

    Where `items` can refer to:

    * a **CSV file**, for instance:
    ```csv
    Model,Seat capacity
    Airbus A320-a,174
    Airbus A320-b,180
    ```

    * a **JSON file**, for instance:
    ```json
    [
        {"model": "Airbus A320-a", "seat_capacity": 174},
        {"model": "Airbus A320-b", "seat_capacity": 180},
    ]

    * a **JSON list** like the previous.
    ```

    Raises:
        ValueError: If file extension is invalid
        FileNotFoundError: If file does not exist
    """

    await self._upload_bounded_items(
        scen_id=scen_id, category=Aircraft, items=items
    )

upload_airlines(scen_id, items) async

Upload a set of airlines defined in a file.

Parameters:

NameTypeDescriptionDefault
scen_idint

Scenario ID

required
itemsstr

Filename .csv or .json defining the airlines

required

Where items can refer to:

  • a CSV file, for instance:

    Name,Type
    MyCarrier,low-cost
    AnotherCarrier,low-cost
    MyLegacyCarrier,legacy
    

  • a JSON file, for instance:

    [
        {"name": "MyCarrier", "type": "low-cost"},
        {"name": "AnotherCarrier", "type": "low-cost"},
        {"name": "MyLegacyCarrier", "type": "legacy"},
    ]
    
    * a **JSON list** like the previous.
    

Raises:

TypeDescription
ValueError

If file extension is invalid

FileNotFoundError

If file does not exist

Source code in src/rmlab/api/upload/core.py
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
async def upload_airlines(self, scen_id: int, items: Union[str, list]) -> None:
    """Upload a set of airlines defined in a file.

    Args:
        scen_id (int): Scenario ID
        items (str): Filename `.csv` or `.json` defining the airlines

    Where `items` can refer to:

    * a **CSV file**, for instance:
    ```csv
    Name,Type
    MyCarrier,low-cost
    AnotherCarrier,low-cost
    MyLegacyCarrier,legacy
    ```

    * a **JSON file**, for instance:
    ```json
    [
        {"name": "MyCarrier", "type": "low-cost"},
        {"name": "AnotherCarrier", "type": "low-cost"},
        {"name": "MyLegacyCarrier", "type": "legacy"},
    ]

    * a **JSON list** like the previous.
    ```

    Raises:
        ValueError: If file extension is invalid
        FileNotFoundError: If file does not exist
    """

    await self._upload_bounded_items(
        scen_id=scen_id, category=Airline, items=items
    )

upload_airports(scen_id, items) async

Upload a set of airports defined in a file.

Parameters:

NameTypeDescriptionDefault
scen_idint

Scenario ID

required
itemsstr

Filename .csv or .json defining the airports

required

Where items can refer to:

  • a CSV file, for instance:

    Name,City,Altitude,Latitude,Longitude,ICAO,IATA
    Geneva,Geneva,431,46.238,6.109,LSGG,GVA
    Madrid,Madrid,619,40.294,-3.724,LEMD,MAD
    London Gatwick,London,60,51.148,-0.19,EGKK,LGW
    London Heathrow,London,25,51.477,-0.461,EGLL,LHR
    

  • a JSON file, for instance:

    [
        {"name": "Geneva", "city": "Geneva", "altitude": 431, "latitude": 46.238, "longitude": 6.109, "icao": "LSGG", "iata": "GVA"},
        {"name": "Madrid", "city": "Madrid", "altitude": 619, "latitude": 40.294, "longitude": -3.724, "icao": "LEMD", "iata": "MAD"},
        {"name": "London Gatwick", "city": "London", "altitude": 60, "latitude": 51.148, "longitude": -0.19, "icao": "EGKK", "iata": "LGW"},
        {"name": "London Heathrow", "city": "London", "altitude": 25, "latitude": 51.477, "longitude": -0.461, "icao": "EGLL", "iata": "LHR"},
    ]
    
    * a **JSON list** like the previous.
    

  • NOTE: Airport cities must reference previously uploaded City items with the same City.name.

Raises:

TypeDescription
ValueError

If file extension is invalid

FileNotFoundError

If file does not exist

rmlab_errors.ClientError

If any of the referenced cities does not exist in server

Source code in src/rmlab/api/upload/core.py
 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
126
127
128
129
130
131
132
133
async def upload_airports(self, scen_id: int, items: Union[str, list]) -> None:
    """Upload a set of airports defined in a file.

    Args:
        scen_id (int): Scenario ID
        items (str): Filename `.csv` or `.json` defining the airports

    Where `items` can refer to:

    * a **CSV file**, for instance:
    ```csv
    Name,City,Altitude,Latitude,Longitude,ICAO,IATA
    Geneva,Geneva,431,46.238,6.109,LSGG,GVA
    Madrid,Madrid,619,40.294,-3.724,LEMD,MAD
    London Gatwick,London,60,51.148,-0.19,EGKK,LGW
    London Heathrow,London,25,51.477,-0.461,EGLL,LHR
    ```

    * a **JSON file**, for instance:
    ```json
    [
        {"name": "Geneva", "city": "Geneva", "altitude": 431, "latitude": 46.238, "longitude": 6.109, "icao": "LSGG", "iata": "GVA"},
        {"name": "Madrid", "city": "Madrid", "altitude": 619, "latitude": 40.294, "longitude": -3.724, "icao": "LEMD", "iata": "MAD"},
        {"name": "London Gatwick", "city": "London", "altitude": 60, "latitude": 51.148, "longitude": -0.19, "icao": "EGKK", "iata": "LGW"},
        {"name": "London Heathrow", "city": "London", "altitude": 25, "latitude": 51.477, "longitude": -0.461, "icao": "EGLL", "iata": "LHR"},
    ]

    * a **JSON list** like the previous.
    ```

    * **NOTE**: Airport *cities* must reference previously uploaded ``City`` items with the same `City.name`.

    Raises:
        ValueError: If file extension is invalid
        FileNotFoundError: If file does not exist
        rmlab_errors.ClientError: If any of the referenced cities does not exist in server
    """

    await self._upload_bounded_items(
        scen_id=scen_id, category=Airport, items=items
    )

upload_batch_core(scen_id, *, aircraft_items=None, airline_items=None, airport_items=None, city_items=None, country_items=None, schedule_items=None) async

Upload a set of items defined in files to server.

Parameters:

NameTypeDescriptionDefault
scen_idint

Scenario ID

required
aircraft_itemsOptional[Union[str, list]]

Aircraft items. Defaults to None.

None
airline_itemsOptional[Union[str, list]]

Airline items. Defaults to None.

None
airport_itemsOptional[Union[str, list]]

Airport items. Defaults to None.

None
city_itemsOptional[Union[str, list]]

City items. Defaults to None.

None
country_itemsOptional[Union[str, list]]

Country items. Defaults to None.

None
schedule_itemsOptional[Union[str, list]]

Flights schedule items. Defaults to None.

None

Raises:

TypeDescription
FileNotFoundError

If a file with items doesn't exist

TypeError

If non-file items are not list-typed.

MultipleError

If several errors happened.

Source code in src/rmlab/api/upload/core.py
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
async def upload_batch_core(
    self,
    scen_id: int,
    *,
    aircraft_items: Optional[Union[str,list]] = None,
    airline_items: Optional[Union[str,list]] = None,
    airport_items: Optional[Union[str,list]] = None,
    city_items: Optional[Union[str,list]] = None,
    country_items: Optional[Union[str,list]] = None,
    schedule_items: Optional[Union[str,list]] = None,
):
    """Upload a set of items defined in files to server.

    Args:
        scen_id (int): Scenario ID
        aircraft_items (Optional[Union[str,list]], optional): Aircraft items. Defaults to None.
        airline_items (Optional[Union[str,list]], optional): Airline items. Defaults to None.
        airport_items (Optional[Union[str,list]], optional): Airport items. Defaults to None.
        city_items (Optional[Union[str,list]], optional): City items. Defaults to None.
        country_items (Optional[Union[str,list]], optional): Country items. Defaults to None.
        schedule_items (Optional[Union[str,list]], optional): Flights schedule items. Defaults to None.

    Raises:
        FileNotFoundError: If a file with items doesn't exist
        TypeError: If non-file items are not list-typed.
        MultipleError: If several errors happened.
    """

    not_existing_fns = [
        FileNotFoundError(items_fn)
        for items_fn in [
            aircraft_items,
            airline_items,
            airport_items,
            city_items,
            country_items,
            schedule_items,
        ]
        if isinstance(items_fn, str) and (not os.path.exists(items_fn))
    ]

    invalid_types = [
        TypeError(name)
        for name, items in [
            ("aircraft_items", aircraft_items),
            ("airline_items", airline_items),
            ("airport_items", airport_items),
            ("city_items", city_items),
            ("country_items", country_items),
            ("schedule_items", schedule_items),
        ]
        if (not isinstance(items, list)) and (not isinstance(items, str))
    ]

    raise_from_list(not_existing_fns + invalid_types)

    if airline_items:
        await self._upload_bounded_items(scen_id, Airline, items=airline_items)

    if aircraft_items:
        await self._upload_bounded_items(scen_id, Aircraft, items=aircraft_items)

    if country_items:
        await self._upload_bounded_items(scen_id, Country, items=country_items)

    if city_items:
        await self._upload_bounded_items(scen_id, City, items=city_items)

    if airport_items:
        await self._upload_bounded_items(scen_id, Airport, items=airport_items)

    if schedule_items:
        await self._upload_unbounded_items(scen_id, Schedule, items=schedule_items)

upload_cities(scen_id, items) async

Upload a set of cities defined in a file.

Parameters:

NameTypeDescriptionDefault
scen_idint

Scenario ID

required
itemsstr

Filename .csv or .json defining the cities

required

Where items can refer to:

  • a CSV file, for instance:

    Name,Country
    Geneva,Swizterland
    Madrid,Spain
    London,United Kingdom
    

  • a JSON file, for instance:

    [
        {"name": "Geneva", "country": "Switzerland"},
        {"name": "Madrid", "country": "Spain"},
        {"name": "London", "country": "United Kingdom"},
    ]
    
    * a **JSON list** like the previous.
    

  • NOTE: City countries must reference previously uploaded Country items with the same Country.name.

Raises:

TypeDescription
ValueError

If file extension is invalid

FileNotFoundError

If file does not exist

rmlab_errors.ClientError

If any of the referenced countries does not exist in server

Source code in src/rmlab/api/upload/core.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
async def upload_cities(self, scen_id: int, items: Union[str, list]) -> None:
    """Upload a set of cities defined in a file.

    Args:
        scen_id (int): Scenario ID
        items (str): Filename `.csv` or `.json` defining the cities

    Where ``items`` can refer to:

    * a **CSV file**, for instance:
    ```csv
    Name,Country
    Geneva,Swizterland
    Madrid,Spain
    London,United Kingdom
    ```

    * a **JSON file**, for instance:
    ```json
    [
        {"name": "Geneva", "country": "Switzerland"},
        {"name": "Madrid", "country": "Spain"},
        {"name": "London", "country": "United Kingdom"},
    ]

    * a **JSON list** like the previous.
    ```

    * **NOTE**: City *countries* must reference previously uploaded ``Country`` items with the same `Country.name`.

    Raises:
        ValueError: If file extension is invalid
        FileNotFoundError: If file does not exist
        rmlab_errors.ClientError: If any of the referenced countries does not exist in server
    """

    await self._upload_bounded_items(
        scen_id=scen_id, category=City, items=items
    )

upload_countries(scen_id, items) async

Upload a set of countries defined in a file.

Parameters:

NameTypeDescriptionDefault
scen_idint

Scenario ID

required
itemsstr

Filename .csv or .json defining the countries

required

Where items can refer to:

  • a CSV file, for instance:

    Name,Currency
    Swizterland,chf
    Spain,eur
    United Kingdom,gbp
    

  • a JSON file, for instance:

    [
        {"name": "Switzerland", "currency": "chf"},
        {"name": "Spain", "currency": "eur"},
        {"name": "United Kingdom", "currency": "gbp"},
    ]
    
    * a **JSON list** like the previous.
    

Raises:

TypeDescription
ValueError

If file extension is invalid

FileNotFoundError

If file does not exist

Source code in src/rmlab/api/upload/core.py
175
176
177
178
179
180
181
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
async def upload_countries(self, scen_id: int, items: Union[str, list]) -> None:
    """Upload a set of countries defined in a file.

    Args:
        scen_id (int): Scenario ID
        items (str): Filename `.csv` or `.json` defining the countries

    Where `items` can refer to:

    * a **CSV file**, for instance:
    ```csv
    Name,Currency
    Swizterland,chf
    Spain,eur
    United Kingdom,gbp
    ```

    * a **JSON file**, for instance:
    ```json
    [
        {"name": "Switzerland", "currency": "chf"},
        {"name": "Spain", "currency": "eur"},
        {"name": "United Kingdom", "currency": "gbp"},
    ]

    * a **JSON list** like the previous.
    ```

    Raises:
        ValueError: If file extension is invalid
        FileNotFoundError: If file does not exist
    """

    await self._upload_bounded_items(
        scen_id=scen_id, category=Country, items=items
    )

upload_schedules(scen_id, items, *, citysector_id=None, sector_id=None) async

Upload a set of flights schedules defined in a file.

Parameters:

NameTypeDescriptionDefault
scen_idint

Scenario ID

required
itemsstr

Filename .csv or .json defining the schedules

required
citysector_idOptional[str]

A citysector ID if all schedules belong to the same citysector. Defaults to None.

None
sector_idOptional[str]

A sector ID if all schedules belong to the same sector. Defaults to None.

None

Arguments citysector_id and sector_id are always optional. If provided, concurrent uploads of schedules files belonging to different citysectors/sectors are allowed.

Where items can refer to:

  • a CSV file, for instance:

    Airline,Aircraft,Origin,Destination,Days of Week,Departure time,Duration,Flight number,Sell before days,From Date,To Date
    MyCarrier,Airbus A320-b,MAD,GVA,-2-4-6-,T08:00,T02:00,2277,15,2022-04-01,2022-05-31
    MyCarrier,Airbus A320-a,MAD,GVA,1-3-5-7,T16:00,T02:00,2278,15,2022-04-01,2022-05-31
    MyCarrier,Airbus A320-b,GVA,MAD,-2-4-6-,T10:30,T01:30,2377,15,2022-04-01,2022-05-31
    MyCarrier,Airbus A320-a,GVA,MAD,1-3-5-7,T18:30,T01:30,2378,15,2022-04-01,2022-05-31
    

  • a JSON file, for instance:

    [
        {"airline": "MyCarrier", "aircraft": "Airbus A320-b", "origin": "MAD", "destination": "GVA", "days_of_week": "-2-4-6-", "departure_time": "T08:00", "duration": "T02:00", "flight_number": "2277", "sell_before_days": 45, "from_date": "2022-04-01", "to_date": "2022-05-31"},
        {"airline": "MyCarrier", "aircraft": "Airbus A320-b", "origin": "MAD", "destination": "GVA", "days_of_week": "1-3-5-7", "departure_time": "T16:00", "duration": "T02:00", "flight_number": "2278", "sell_before_days": 45, "from_date": "2022-04-01", "to_date": "2022-05-31"},
        {"airline": "MyCarrier", "aircraft": "Airbus A320-b", "origin": "GVA", "destination": "MAD", "days_of_week": "-2-4-6-", "departure_time": "T10:30", "duration": "T01:30", "flight_number": "2377", "sell_before_days": 45, "from_date": "2022-04-01", "to_date": "2022-05-31"},
        {"airline": "MyCarrier", "aircraft": "Airbus A320-b", "origin": "GVA", "destination": "MAD", "days_of_week": "1-3-5-7", "departure_time": "T10:30", "duration": "T01:30", "flight_number": "2378", "sell_before_days": 45, "from_date": "2022-04-01", "to_date": "2022-05-31"},
    ]
    
    * a **JSON list** like the previous.
    

  • NOTE: Schedule airlines must reference previously uploaded Airline items with the same Airline.name.

  • NOTE: Schedule aircrafts must reference previously uploaded Aircraft items with the same Aircraft.model.
  • NOTE: Schedule origins must reference previously uploaded Airport items with the same Airport.iata.
  • NOTE: Schedule destinations must reference previously uploaded Airport items with the same Airport.iata.
  • NOTE: No two schedules with overlapping date ranges (from_date, to_date), and overlapping days of week, with the same flight_number are allowed.

Raises:

TypeDescription
ValueError

If file extension is invalid

FileNotFoundError

If file does not exist

rmlab_errors.ClientError

If any of the previous Notes are not satisfied

Source code in src/rmlab/api/upload/core.py
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
async def upload_schedules(
    self,
    scen_id: int,
    items: Union[str, list],
    *,
    citysector_id: Optional[str] = None,
    sector_id: Optional[str] = None,
) -> None:
    """Upload a set of flights schedules defined in a file.

    Args:
        scen_id (int): Scenario ID
        items (str): Filename `.csv` or `.json` defining the schedules
        citysector_id (Optional[str], optional): A citysector ID if all schedules belong to the same citysector. Defaults to None.
        sector_id (Optional[str], optional): A sector ID if all schedules belong to the same sector. Defaults to None.

    Arguments `citysector_id` and `sector_id` are always optional. If provided, concurrent uploads of schedules
        files belonging to different citysectors/sectors are allowed.

    Where `items` can refer to:

    * a **CSV file**, for instance:
    ```csv
    Airline,Aircraft,Origin,Destination,Days of Week,Departure time,Duration,Flight number,Sell before days,From Date,To Date
    MyCarrier,Airbus A320-b,MAD,GVA,-2-4-6-,T08:00,T02:00,2277,15,2022-04-01,2022-05-31
    MyCarrier,Airbus A320-a,MAD,GVA,1-3-5-7,T16:00,T02:00,2278,15,2022-04-01,2022-05-31
    MyCarrier,Airbus A320-b,GVA,MAD,-2-4-6-,T10:30,T01:30,2377,15,2022-04-01,2022-05-31
    MyCarrier,Airbus A320-a,GVA,MAD,1-3-5-7,T18:30,T01:30,2378,15,2022-04-01,2022-05-31
    ```

    * a **JSON file**, for instance:
    ```json
    [
        {"airline": "MyCarrier", "aircraft": "Airbus A320-b", "origin": "MAD", "destination": "GVA", "days_of_week": "-2-4-6-", "departure_time": "T08:00", "duration": "T02:00", "flight_number": "2277", "sell_before_days": 45, "from_date": "2022-04-01", "to_date": "2022-05-31"},
        {"airline": "MyCarrier", "aircraft": "Airbus A320-b", "origin": "MAD", "destination": "GVA", "days_of_week": "1-3-5-7", "departure_time": "T16:00", "duration": "T02:00", "flight_number": "2278", "sell_before_days": 45, "from_date": "2022-04-01", "to_date": "2022-05-31"},
        {"airline": "MyCarrier", "aircraft": "Airbus A320-b", "origin": "GVA", "destination": "MAD", "days_of_week": "-2-4-6-", "departure_time": "T10:30", "duration": "T01:30", "flight_number": "2377", "sell_before_days": 45, "from_date": "2022-04-01", "to_date": "2022-05-31"},
        {"airline": "MyCarrier", "aircraft": "Airbus A320-b", "origin": "GVA", "destination": "MAD", "days_of_week": "1-3-5-7", "departure_time": "T10:30", "duration": "T01:30", "flight_number": "2378", "sell_before_days": 45, "from_date": "2022-04-01", "to_date": "2022-05-31"},
    ]

    * a **JSON list** like the previous.
    ```

    * **NOTE**: Schedule *airlines* must reference previously uploaded ``Airline`` items with the same `Airline.name`.
    * **NOTE**: Schedule *aircrafts* must reference previously uploaded ``Aircraft`` items with the same `Aircraft.model`.
    * **NOTE**: Schedule *origins* must reference previously uploaded ``Airport`` items with the same `Airport.iata`.
    * **NOTE**: Schedule *destinations* must reference previously uploaded ``Airport`` items with the same `Airport.iata`.
    * **NOTE**: No two schedules with overlapping date ranges (*from_date*, *to_date*), and overlapping days of week, with the same *flight_number* are allowed.


    Raises:
        ValueError: If file extension is invalid
        FileNotFoundError: If file does not exist
        rmlab_errors.ClientError: If any of the previous Notes are not satisfied
    """

    await self._upload_unbounded_items(
        scen_id,
        Schedule,
        items,
        citysector_id=citysector_id,
        sector_id=sector_id,
    )