dashtail / sales-pipeline

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sales-pipeline

This project was for an interview

Setup

Python 3.7+ is required.

It is necessary to install the dependencies found in the requirements.txt file. Open your terminal and run the command:

pip install -r requiriments.txt

Test

To run the tests, run the command on the repository root

python -m unittest

Sample

I have written a script that runs the prospecting service that returns a person and their personal information. Along with personal information, we can also see the score generated by the service and whether the person has become a potential customer or not.

run:

python sample.py

output example:

{
    'NIN': '00112233', 
    'birth_date': '1992/07/25', 
    'first_name': 'Peter', 
    'last_name': 'Monteiro', 
    'email': 'peter.monteiro@example.com', 
    'prospect': True, 
    'score': 68
}

Decisions/Assumptions

This app has 2 external packages:

requests > - Where I used para to simulate the request in external systems. mock-requests

  • It was used to simulate the return of requests from external systems. I chose this library because with it I can simulate the return of requests, defining url, status_code, data, etc. So when I use the requests library to access these APIs, I get a response like a real API.

The initial idea was to separate what belongs to the external and internal systems. For external systems I created a directory called externals, and for the internal system I created a directory called core.

So, as it says in the PDF, we would have two external systems on which we must perform HTTP requests, so I created for each of these services a class responsible for managing these requests.

As the idea was not to implement these external services, for the National Registry service I simulated a GET where we passed the national identification number (NIN) of the person, and returned the equivalent data for that number, which is used to buy with the data from the database. And to check the judicial records, we use the same approach, but we just check the records for that NIN, and return whether any records were found or not

For the internal system, I separated what would be entities, services, and utilities.

For entities, I created a class called Person where it contains personal information, score, prospect. As we are not using a database, I created some contacts simulating database records. These constants will be used to simulate queries, and support for unit testing.

In services, I created a class responsible for handling the pipeline flow, which is to query the 2 external APIs in parallel and then get the outputs from the APIs and call the internal service to generate the score, validate the personal data and register the person became a potential customer

To perform the queries in parallel, I used the asyncio library available in the version of python 3.7+. To ensure that the two requests on external systems are executed at the same time, I'm using the gather function which is responsible for executing them at the same time

About


Languages

Language:Python 100.0%