-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI_Python_1.0.0.py
More file actions
53 lines (44 loc) · 1.76 KB
/
Copy pathAPI_Python_1.0.0.py
File metadata and controls
53 lines (44 loc) · 1.76 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
#!/usr/bin/env python
# coding: utf-8
# import statements
from fastapi import FastAPI, HTTPException
import json
import numpy as np
import pickle
import datetime
# Import the airport encodings file
f = open('airport_encodings.json')
# returns JSON object as a dictionary
airports = json.load(f)
def create_airport_encoding(airport: str, airports: dict) -> np.array:
"""
create_airport_encoding is a function that creates an array the length of all arrival airports from the chosen
departure aiport. The array consists of all zeros except for the specified arrival airport, which is a 1.
Parameters
----------
airport : str
The specified arrival airport code as a string
airports: dict
A dictionary containing all of the arrival airport codes served from the chosen departure airport
Returns
-------
np.array
A NumPy array the length of the number of arrival airports. All zeros except for a single 1
denoting the arrival airport. Returns None if arrival airport is not found in the input list.
This is a one-hot encoded airport array.
"""
temp = np.zeros(len(airports))
if airport in airports:
temp[airports.get(airport)] = 1
temp = temp.T
return temp
else:
return None
# TODO: write the back-end logic to provide a prediction given the inputs
# requires finalized_model.pkl to be loaded
# the model must be passed a NumPy array consisting of the following:
# (polynomial order, encoded airport array, departure time as seconds since midnight, arrival time as seconds since midnight)
# the polynomial order is 1 unless you changed it during model training in Task 2
# YOUR CODE GOES HERE
# TODO: write the API endpoints.
# YOUR CODE GOES HERE