project-root/
│
├── app/
│
├── assets/
│
├── db/
│
├── scripts/
│
├── .env
│
├── docker-compose.yml
│
├── readme.md
│
└── start_services.sh
-
app: Contains the api code.
-
assets: Directory for all CSVs, including
airports_w_wiki.csv
-
db: Database-related files.
-
scripts: Utility and setup scripts.
eval.py
: Provided file for testing.filterAirportsWithWk.py
: Filtering the airports with wiki links on fileassets/airports.csv
.getUsers.py
: Getting users from 42Hacks api and generate the fileassets/user_locations.csv
.transformCSVToSQL.py
: Read the files./assets/user_closest_airports.csv
and./assets/airports_w_wiki.csv
to generate the fileinit.sql
that will be responsible for populate the database.userClosestAirport.py
: Read the files/assets/user_locations.csv
and/assets/airports_w_wiki.csv
to generate the file/assets/user_closest_airports.csv
that constains the closest file to each user.
-
.env: Environment variables for configuration. Should be not versionated but it is for convinence.
-
docker-compose.yml: Docker Compose file for setting up services.
-
start_services.sh: Script to start services.
For convinence all the files that need to be generated or downloaded are already included in this repo, so it is possible to just run the service. But I leave here a guide for how generate each one of them.
-
Clone the repository: TODO
git clone https://github.com/mfenerich/42Hacks.git cd 42Hacks
-
Give permission to scripts:
chmod +x start_services.sh chmod +x db/init_db.sh
-
Get all the users and its locations: (It my take a while)
docker-compose run --rm script_runner_get_users
-
Filter out all airports with no wikipedia link:
docker-compose run --rm script_runner_filter_airports_with_wk
-
Find all closest airport to each user:
docker-compose run --rm script_runner_find_user_closest_airport
-
Once everything is generated, start the api:
./start_services.sh
Once you run this command, if you have a database it will be deleted a new file
init.sql
will be generated to populate the database with required data. -
Now you can test the accuracy of the project by running:
docker-compose run --rm script_runner_eval
HTTP Method | Endpoint | Description | Request Parameters | Response | Status Codes |
---|---|---|---|---|---|
GET | /nearest_airports/<user_id> |
Retrieve the nearest airport ID for a given user. | user_id : integer (path parameter), The unique ID of the user. |
{ 'airport_id': integer } |
200: OK - Success 404: Not Found - User not found or has no closest airport |
GET | /nearest_airports_wikipedia/<user_id> |
Retrieve the Wikipedia link for the nearest airport to a given user. | user_id : integer (path parameter), The unique ID of the user. |
{ 'wikipedia_link': string } |
200: OK - Success 404: Not Found - User not found or airport not found |