To run the app locally:
-
Run the virtualev and install the requirements listed in requirements.txt.
-
Activate the server.
$ python runserver.py
Make sure it runs runs on port 5000. Wait for the cache to load. This is repeated twice on startup because of the reloader which monitors changes on source files to help with development. This can be deactivated using the use_reloader=False option in Flask's app.run() function.
- Activate the client.
$ cd client
$ python -m SimpleHTTPServer
Make sure it runs on port 8000.
- Use the app.
To run the tests:
-
Make sure all requirements are installed.
-
run :
$ cd tests
$ ./run_tests_with_coverage
To run with the profiler: Follow the steps above but replace step 2. with :
$ python run_with_profiler.py
At every request, profiling information should appear on the terminal.
The purpose of this exercise is to build an API that returns the most popular products from shops near you.
- A server boilerplate using
Flask
. To run the server:
$ python runserver.py
- A rudimentary client so you can visualize the results more easily. The client does not have any way to communicate with the API so you will need to implement that. To run the client:
$ cd client
$ python -m SimpleHTTPServer
- Four datasets in CSV format:
shops.csv
: shops with their coordinatesproducts.csv
: products per shop along available quantity and global popularitytags.csv
: a bunch of tagstaggings.csv
: what tags each shop has
-
Create a Python virtualenv and install the requirements:
$ pip install virtualenvwrapper $ mkvirtualenv $ pip install -r requirements.txt
-
Implement the
Searcher.search()
method in the client so it can communicate with your API. We've includedjQuery
on the page so you can use that if you like. -
Build the
/search
endpoint which returns the N most popular products across all shops near the user. The endpoint should receive:- the number (N) of products to return
- a pair of coordinates (the user position)
- a search radius (how far the search should extend)
- optionally, some tags (what types of shops the user wants to see)
If tags are provided, a shop needs to have at least one of them to be considered a candidate. You can use any Python library to your aid but you can't use any external databases or search engines (e.g PostGIS, Elasticsearch, etc). You should build your solution as if the data is static and cannot be updated by any external processes.
-
Write some tests. A test foundation is provided for you in
tests/conftest.py
. -
Briefly think about and answer the questions in THOUGHTS.md.
You should deliver your solution as a git
repository, preferably hosted on GitHub.
In a nutshell we're looking for correctness, good code design and sensible choices when it comes to performance. Imagine that your API will be used by a lot of people – how does that affect your design? Also, imagine that your code will be read by other developers in your team – keep them happy :-)
Flask
: http://flask.pocoo.org/pytest
: http://pytest.org/latest/virtualenvwrapper
: https://virtualenvwrapper.readthedocs.io/en/latest/