This code creates an API that fetches and persists heart rate data to a mongodb database. The assignement outline can be found here.
To get the API up and running, perform the following commands in the root directory of this repository:
- create a virtual environment:
virtualenv env
- start the virtual environment:
source env/bin/activate
- install all requirements:
pip install -r requirements.txt
NOTE: the use of screens is helpful for the following steps - run
docker run -v $PWD/db:/data/db -p 27017:27017 mongo
- run
gunicorn --bind 0.0.0.0:5003 api:app
(you can select the port you'd like gunicorn to listen to requests on - this repo defaults to 5003)
Note: all endpoints return additional info when an error is thrown. This info is to help the end user deduce the issue(s) that cause the request to fail.
POST /api/heart_rate
withreturns:{ "user_email": REQUIRED, "user_age": REQUIRED, // in years "heart_rate": REQUIRED }
{ "success": 1 OR 0 }
GET /api/heart_rate/<user_email>
returns all heart rate measurements for given user:{ "status": 1 OR 0, "user_data": { "age": int, "email": string, "hr_readings": array, "readings_ts": array } }
GET /api/heart_rate/average/<user_email>
returns the user's average heart rate over all measurements:{ "status": 1 OR 0, "user_data": { "age": int, "email": string, "hr_average": float, "is_user_tachycaric": boolean, "num_readings": int } }
POST /api/heart_rate/interval_average
withreturns the average heart rate for the user since the time specified:{ "user_email": REQUIRED, "heart_rate_average_since": REQUIRED // date string }
{ "status": 1 OR 0, "user_data": { "age": int, "datetime_threshold": date string, "email": string, "hr_average": float, "is_user_tachycaric": boolean, "num_readings": int } }
GET /api/get_users
returns all users with at least one heart rate reading:{ "success": 1 OR 0, "emails": array }