- D1g1t Back-end Test Assignment
- The solution implemented in this assessment has not been optimized for a live production environment with thousands of transactions per minute.
- The solution has not been implemented using Django async. Even though the progress done by the Django community sounds promising, the performance improvements are still maturing compared to sync wsgi.
- Users can get statistical information over the course of one year.
- Users can be members of more than one Team.
- Users who are not members of a team won't be able to do a daily check-in
The method chosen to measure Happiness was The Satisfaction with Life Scale (SWLS) uses a scale of 1 to 7, where 1 represents "strongly disagree," and 7 represents "strongly agree" for statements such as "In most ways, my life is close to my ideal."
- 31 - 35 Extremely happy
- 26 - 30 happy
- 21 - 25 Slightly happy
- 20 Neutral
- 15 - 19 Slightly unhappy
- 10 - 14 unhappy
- 5 - 9 Extremely unhappy
You need to install Docker Desktop and Docker Compose before following the instructions below.
To install Docker Desktop on Windows Home, please follow the instructions.
To clone the repository, run the following command
git clone https://github.com/ridiaz/d1g1t-backend-assignment.gitTo enable live code reloading. Without this, Docker Compose will not start:
- Windows/MacOS: Add the cloned d1g1t-backend-assignment directory to Docker shared directories (Preferences -> Resources -> File sharing)
- Linux: No action is required, sharing is already enabled and memory for the Docker engine is not limited.
cd d1g1t-backend-assignmentdocker-compose builddocker-compose up db -d && sleep 3 && docker-compose run --rm api python3 manage.py migrate
Create super user with the following command, to access the Django web Admin
docker-compose run --rm api python3 manage.py createsuperuser
docker-compose up
Now you can access the Django web Admin on http://localhost:9001/admin
docker-compose run --rm api python3 pytest
In order to access the API endpoints that require authentication, you should include the access token in the header of all requests. JSON Web Token Authentication
curl --request POST \
--url http://localhost:9001/api/token/ \
--header 'Content-Type: application/json' \
--data '{
"username": "<username>",
"password": "<password>"
}'
{
"refresh": "<generated token>",
"access": "<generated token>"
}- __ In most ways my life is close to my ideal.
- __ The conditions of my life are excellent.
- __ I am satisfied with my life.
- __ So far I have gotten the important things I want in life.
- __ If I could live my life over, I would change almost nothing.
- 7 - Strongly agree
- 6 - Agree
- 5 - Slightly agree
- 4 - Neither agree nor disagree
- 3 - Slightly disagree
- 2 - Disagree
- 1 - Strongly disagree
curl --request POST \
--url http://localhost:9001/daily/v1/api/ \
--header 'Authorization: Bearer <generated token>' \
--header 'Content-Type: application/json' \
--data '{
"responses": [6,6,6,5,6]
}'
curl --request GET \
--url http://localhost:9001/analytics/v1/api/ \
--header 'Authorization: Bearer <token>'
Returns the list of all user's team statistics
[
{
"name": "team_3",
"team_statistics": [
{
"number_of_people": 1,
"average_happiness": 29.0,
"level_happiness": "Happy"
},
{
"number_of_people": 1,
"average_happiness": 22.0,
"level_happiness": "Slightly Happy"
}
],
"average_happiness": 25.5
}
]Returns average happiness across all teams
curl --request GET \
--url http://localhost:9001/analytics/v1/api/
[
{
"name": "all teams",
"average_happiness": 29.0
}
]- Add cache layer
- Remove signals
- Implement task queue (i.e. Celery) to handle the loading of the data to the Analytics DB
- Writing statistical/analytics calculations with Django ORM could be difficult and inefficient (i.e. unnecessary calls to the database), sometimes is better to write raw SQL queries to take full advantage of the RDBMS engine
- Add Db indexes
- Add more type hints
- Add more tests
- Add logging
- Add support of global exception handling in APIs
- Add rate limiting to the api endpoints
