Fetch Emergency incidents with additional data.
- Download and Setup environment
- Create Weather API Interface
- Create Incident Report Interface
- Create Endpoints for API requests
- Document installation process
- Create Integration tests for API
- Security considerations
- Data storage considerations
- Possible Improvements
These are the installation instructions for Ubuntu 20.04 but it could work for other distributions either way Python3.6+ is required.
There are two ways to install and run the application. One is to install and run with a virtual environment like pipenv (Recommended). Option Two, is to install everything with pip and then run everything from the command line normally.
- Python3.6+
- pip installation
- Pipenv installation (optional, but recommended)
- MongoDB Community Edition installation
With Pipenv:
-
In
./Pipfile
, under the[requires]
header, check to make sure that thepython_version
is the same as your local version (your local python version:python3 --version
). -
If the
python_version
is not the same and you need to change it then that is fine but you also should delete./Pipfile.lock
, also if there are any issues with the Lock file it might be usefull to delete the lock then try installing again. -
Then simply run
pipenv install
.
Without Pipenv:
- Simply install with
pip install -r requirements.txt
.
-
If you have
pipenv
then you can start your shell withpipenv shell
, also if you havepipenv
then you can run the commands normally but just pre-appendpipenv run
(i.e.pipenv run uvicorn main:app
). -
Make sure that mongodb is running locally and if you want to setup the DB with some data you can use the
init_db.py
tool. By default it loads data from./tests/data
into the DB. But you can easily add more json reports by runningpython3 init_db.py -f /path/to/report.json
. -
To start the API simply run
uvicorn main:app
. (you can learn more aboutuvicorn
andFastAPI
from the "Additional Dependencies information" below) -
Next you can make requests to the localhost server: http://127.0.0.1:8000/
-
And you can view the endpoint documentation (SwaggerUI) here: http://127.0.0.1:8000/docs or the ReDoc version: http://127.0.0.1:8000/redoc
To run the integration tests simply run pytest
from the main directory (or if you have pipenv then run pipenv run pytest
).
Here are some things I would have done if I had more time:
- Clean up the code base and add more descriptions for each method/class.
- Expand and improve the Data validation models. Both
Query
andField
havedescription
attributes, I probably would have started there. - I would improve my data storage and data model. I think I would store the weather data with the incident reports or if I was using SQL I would've created a table for the weather objects that join to the incident reports.
- Of course I would have expanded on my tests and I would've added unit test sweeps as well.
- Finally I would have added security features like Authorization Tokens.
Time spent:
8am - 9am
: researching libraries and reading documentation.9am - 10am
: Installing and setting up the env. Implenting the weather service. Adding documentation.10am - 12pm
: Setting up a database and getting the Incident service to query the DB for resutls.2pm - 4pm
: Connecting the API components with the Weather and incident services.7pm - 8pm
: Integration tests and any remaining docs.