Giter Club home page Giter Club logo

winclap's Introduction

Set up:

  1. pip is required
$ sudo apt-get install python-pip
  1. Now that pip is installed we need to install virtualenv
$ sudo pip install virtualenv
  1. Create a virtualenv
$ virtualenv -p python3 env
  1. Activate the virtualenv
$ source env/bin/activate
  1. Install dependencies
$ pip install -r requirements.txt

Once the enviroment is activated:

  1. Run migrations (Only to prevent warning messages from third party libraries. There are no models in the winclap project.)
$ python manage.py migrate
  1. Start the server.
$ python manage.py runserver

1 - Campaigns classificator

For this exercise I decided to build a real API functionality using Django REST Framework. For that, I created:

  1. The campaignclassificator.api.serializers.UserDataSerializer serializer, which allows to automatically validate the incoming parameters and return a 400 error if necessary.

  2. The campaignclassificator.api.views.CurrencyProblemAPIView view that validates the parameters using the serializer and looks for the best campaign match. If there is more than one match it takes one of those at random. It was built this way to allow dynamic parameters instead of using the user.json data alone.

The actual function that tests this view using the user.json file is in the API unit tests file campaignsclassificator.api.tests.py (the test checks if the result is one of the two possible matches for best campaign). Besides that, there are unit tests for checking that a 400 error is raised if a parameter is missing or invalid.

To run the test that sends the user.json data to the API

$ python manage.py test campaignclassificator.api.tests

To test the API endpoint using other parameters

Go to the following URL passing parameters as query string. It will return the best campaign from the given list.

http://127.0.0.1:8000/clasificator/api/best_campaign/?gender=Male&age=16&platform=Android&connection=WiFi

2 - Currency Problem

The code for this exercise is in the currencyproblem.api.views.py file, the dataset used is in currencyproblem.datasets.campaigns.json

Going to the following URL will return a list of campaigns with the profits converted to USD in JSON format.

http://127.0.0.1:8000/currency/api/currency/

3 - Sheep

The code for this exercise is in the sheep.sheep.py file, the dataset used is in sheep.c-input.in

Type in terminal:

$ python winclap/sheep/sheep.py 

winclap's People

Contributors

scorpmarv avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.