This repo represents a stripped down version of our core ideas platform product 'Idea Spotlight'.
We have a customer export script named user_activity_export.sh
which is run manually
and collates all the user activity for a given customer across the
site then emails the resulting data file to a named manager.
Copying the repository
Due to the public nature of forks we suggest you duplicate the repo rather then forking it.
You will need to create your own repo e.g. [your_github_username]/wazoku_test
and then clone
this repo chrispbailey/wazoku_test
and push the code into your new one. You can follow the steps for doing this here: https://help.github.com/articles/duplicating-a-repository/
Before proceeded be aware that this exercise assumes you are using a linux machine with pip and virtualenv installed.
Create a new virtualenv in your checked out repo.
cd /[path_to]/wazoku_test
python3.6 -m venv .
Then install the dependencies:
bin/pip install -r requirements.txt
Set the default django settings file used by all following commands:
export DJANGO_SETTINGS_MODULE=exercise.settings
The code in this repo uses an sqlite database as the persistence layer. You can initialize an sqlite database (this db will be stored in the file ./db.sqlite3
)
bin/python manage.py migrate
There is a simple django populate_db
command which can be used to prime the database with some example data
bin/python manage.py populate_db
The user export script can be run with the following:
bin/python -m scripts.user_activity_export \
-c example.com \
-e [email protected]
There is also a unit test which can be used to validate the code:
bin/python manage.py test tests
Our clients wish to receive a list of inactive users as well as active ones. Given the limitation of the csv format, we propose generating an Excel document instead of a csv file. Use the openpyxl library to modify the code to produce an xlsx document containing two sheets, the first mirrors the csv with a list of active users and their activity, the second sheet contains a list of email addresses for those users with no activity on the site. Feel free to refactor the code any way you see fit.
Please create a pull request for this work.
Although the tests are all passing, after a recent refactoring this code appears to have stopped working as our customers are all reporting they are not receiving the emails when we run the script (although occasionally the wrong manager does receive an email). Please identify and fix the problem and issue a second pull request for your fix.
Bonus marks will be awarded for the addition of tests against your fix
The current script is not particularly efficient against large customers. Can you improve on
the current code and reduce it's complexity from O(N)
to O(1)
. You might want to consider using assertNumQueries to help you confirm this.
Please create a third pull request for this work.