Skip to content

HandBoy/work-at-olist

 
 

Repository files navigation

Work at Olist - Test Implementation

The project is an API responsible for:

  • Register phone starts and ends calls
  • Generate monthly bill

Description

A REST API that receives call records and generate monthly bills for a given telephone number. This fork is a test resolution for a job application at Olist as Python Web Developer.

Installation

From the route of the repository: # Install virtual environment sudo pip install virtualenv

# Create the virtual environment
virtualenv <folder_env_name>

# discover python3 path 
which python3
/usr/bin/python3

# Seting python3 in virtualenv 
virtualenv --python='/usr/bin/python3' <folder_env_name>

# Activate the environment
source <folder_env_name>/bin/activate

# Install requirements
env/bin/pip install -r requirements.txt

# Clone repository
git clone https://github.com/HandBoy/work-at-olist.git

# Install Project Requirements
pip install -r requirements.txt

# Creating a superuser
python manage.py createsuperuser

# Run the project
python manage.py runserver 127.0.0.1:8000

Note: You do not need a database or to run migrate.

Viewing DRF Docs

Once you install and run the project go to http://127.0.0.1:8000/docs/.

Deployed instance

The project was deployed on Heroku.

Tests

Tests can be executed using the Django built-in test tool:

python manage.py test api/tests/

Tests each file separately

python manage.py test api/tests/ --pattern="tests_calc_price.py"
python manage.py test api/tests/ --pattern="tests_datetime_utils.py"
python manage.py test api/tests/ --pattern="tests_models.py"
python manage.py test api/tests/ --pattern="tests_views.py"

Tests coverage

coverage run --source='.' manage.py test api/tests/
coverage report
coverage html

Used environment

The following environment was used to develop the project:

  • Desktop: AMD A4-3310MX APU with Radeon(tm) HD Graphics × 2, 3.8 GB DDR2
  • Ubuntu 16.04
  • Visual Studio Code
  • Python 3.5
  • Django 2.0.7
  • Django Rest Framework 3.8.2
  • coverage 4.5.1 for covarage tests
  • python-decouple 3.1 for separation of settings from code

Work at Olist

Olist is a company that offers an integration platform for sellers and marketplaces allowing them to sell their products across multiple channels.

The Olist development team consists of developers who loves what they do. Our agile development processes and our search for the best development practices provide a great environment for professionals who like to create quality software in good company.

We are always looking for good programmers who love to improve their work. We give preference to small teams with qualified professionals over large teams with average professionals.

This repository contains a problem used to evaluate the candidate skills. It's important to notice that satisfactorily solving the problem is just a part of what will be evaluated. We also consider other programming disciplines like documentation, testing, commit timeline, design and coding best practices.

Hints:

  • Carefully read the specification to understand all the problem and artifact requirements before start.
  • Check the recommendations and reference material at the end of this specification.

How to participate

  1. Make a fork of this repository on Github. If you can't create a public fork of this project, make a private repository (bitbucket offers free private repos) and add read permission for the user @tech-hiring on project;
  2. Follow the instructions of README.md (this file);
  3. Deploy your project on a host service (we recommend Heroku or gigalixir);
  4. Apply for the position at our career page with:
    • Link to the fork on Github (or bitbucket.org);
    • Link to the project in a the deployed host service.

Specification

You should implement an application that receives call detail records and calculates monthly bills for a given telephone number.

There are a plenty of telecommunications platform technologies that will consume this application. Some of them have weird behaviours when something goes wrong. That said it's not safe to believe in received data correctness, consistency nor expect some order in their requests. The application should have flexibility in receiving information to avoid record loss or inconsistency.

This application must provide a HTTP REST API to attend the requirements.

1. Receive telephone call detail records

There are two call detailed record types: Call Start Record and Call End Record. To get all information of a telephone call you should use the records pair.

Call Start Record information:

  • record type: Indicate if it's a call start or end record;
  • record timestamp: The timestamp of when the event occured;
  • call identifier: Unique for each call record pair;
  • origin phone number: The subscriber phone number that originated the call;
  • destination phone number: The phone number receiving the call.

The Call End Record has the same information excepting origin and destination fields.

The phone number format is AAXXXXXXXXX, where AA is the area code and XXXXXXXXX is the phone number. The phone number is composed of 8 or 9 digits.

Examples

  1. Call Start Record
{
  "id":  // Record unique identificator;
  "type":  // Indicate if it's a call "start" or "end" record;
  "timestamp":  // The timestamp of when the event occured;
  "call_id":  // Unique for each call record pair;
  "source":  // The subscriber phone number that originated the call;
  "destination":  // The phone number receiving the call.
}
  1. Call End Record
{
   "id":  // Record unique identificator;
   "type":  // Indicate if it's a call "start" or "end" record;
   "timestamp":  // The timestamp of when the event occured;
   "call_id":  // Unique for each call record pair.
}

2. Get telephone bill

To get a telephone bill we need two information: the subscriber telephone number (required); the reference period (month/year) (optional). If the reference period is not informed the system will consider the last closed period. In other words it will get the previous month. It's only possible to get a telephone bill after the reference period has ended.

The telephone bill itself is composed by subscriber and period attributes and a list of all call records of the period. A call record belongs to the period in which the call has ended (eg. A call that started on January 31st and finished in February 1st belongs to February period).

Each telephone bill call record has the fields:

  • destination
  • call start date
  • call start time
  • call duration (hour, minute and seconds): e.g. 0h35m42s
  • call price: e.g. R$ 3,96

3. Pricing rules

The call price depends on fixed charges, call duration and the time of the day that the call was made. There are two tariff times:

  1. Standard time call - between 6h00 and 22h00 (excluding):

    • Standing charge: R$ 0,36 (fixed charges that are used to pay for the cost of the connection);
    • Call charge/minute: R$ 0,09 (there is no fractioned charge. The charge applies to each completed 60 seconds cycle).
  2. Reduced tariff time call - between 22h00 and 6h00 (excluding):

    • Standing charge: R$ 0,36
    • Call charge/minute: R$ 0,00 (hooray!)

It's important to notice that the price rules can change from time to time, but an already calculated call price can not change.

Examples

  1. For a call started at 21:57:13 and finished at 22:10:56 we have:

    • Standing charge: R$ 0,36
    • Call charge:
      • minutes between 21:57:13 and 22:00 = 2
      • price: 2 * R$ 0,09 = R$ 0,18
    • Total: R$ 0,18 + R$ 0,36 = R$ 0,54

4. Sample data

Insert the following calls to your app after it is deployed to a working environment (eg. Heroku, gigalixir). This sample data will be used in your evaluation, so do this as the last step before submitting the project.

These calls are between the numbers 99988526423 (source) and 9993468278 (destination).

  • call_id: 70, started at 2016-02-29T12:00:00Z and ended at 2016-02-29T14:00:00Z.
  • call_id: 71, started at 2017-12-12T15:07:13Z and ended at 2017-12-12T15:14:56Z.
  • call_id: 72, started at 2017-12-12T22:47:56Z and ended at 2017-12-12T22:50:56Z.
  • call_id: 73, started at 2017-12-12T21:57:13Z and ended at 2017-12-12T22:10:56Z.
  • call_id: 74, started at 2017-12-12T04:57:13Z and ended at 2017-12-12T06:10:56Z.
  • call_id: 75, started at 2017-12-12T21:57:13Z and ended at 2017-12-13T22:10:56Z.
  • call_id: 76, started at 2017-12-12T15:07:58Z and ended at 2017-12-12T15:12:56Z.
  • call_id: 77, started at 2018-02-28T21:57:13Z and ended at 2018-03-01T22:10:56Z.

Project Requirements:

  • Provide a working environment with your project (eg. Heroku, )
  • Application must be written in Python, Elixir or Go.
  • Python
    • Use Python >= 3.5
    • Choose any Python web framework you want to solve the problem
    • Use PEP-8 for code style
    • Python Coding Style
  • Elixir
  • Go
  • Every text or code must be in English
  • Write the project documentation containing:
    • Description;
    • Installing and testing instructions;
    • Brief description of the work environment used to run this project (Computer/operating system, text editor/IDE, libraries, etc).
  • Provide an API documentation (in english);
  • Variables, code and strings must be all in English.

Recommendations

Have fun!

About

Apply for a job at Olist's Development Team: https://bit.ly/olist-webdev

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.4%
  • HTML 1.6%