Coder Social home page Coder Social logo

interviewassessement's Introduction

Interview Assessment - Ye Shi

This repository contains deliverables for an interview assessment of Ye Shi.

Repository Contents

project/
├── app/
│   ├── __init__.py        # Initialization of the Flask app
│   ├── app.py             # Source code of the Flask app
├── data.json              # Data file
├── run.py                 # Main script to run the Flask app
├── test_app.py            # Unit tests for the project
├── requirements.txt       # Python packages required for the project
├── README.md              # This file

Project Description

The project is a Flask app that serves the data in the data.json file. The project has the following endpoints:

  1. POST /validate: Accepts a JSON payload and validates the data.
  2. POST /get_factors: Accepts a JSON payload, maps the factors, and returns the results in JSON format.

The port number is set to 5000 and localhost (127.0.0.1) by default.

Examples

Example 1

Input for /validate and /get_factors:

{
    "data": [
        {"var_name": "country", "category": "UK"},
        {"var_name": "age_group", "category": "30-50"}
    ]
}

Output for /validate:

{
    "results": "success",
    "message": "Validation successful"
}

Output for /get_factors:

{
    "results": [
        {"var_name": "country", "factor": "UK", "factor_value": 0.5},
        {"var_name": "age_group", "factor": "30-50", "factor_value": 0.3}
    ]
}

Example 2

Input for /validate and /get_factors:

{
    "data": [
        {"var_name": "country", "category": "UK"},
        {"var_name": "age_group", "category": "Invalid Category"}
    ]
}

Output for /validate:

{
    "results": "failed",
    "message": "Validation failed. The return errors are invalid data:",
    "errors": [
        {"var_name": "age_group", "category": "Invalid Category"}
    ]
}

Output for /get_factors:

{
    "results": [
        {"var_name": "country", "factor": "UK", "factor_value": 0.5},
        {"var_name": "age_group", "factor": "Invalid Category", "factor_value": "N/A"}
    ]
}

Example 3

Input for /validate and /get_factors:

{
    "data": []
}

Output for /validate:

{
   "results": "failed",
   "message": "No data provided"
}

Output for /get_factors:

{
    "results": [],
    "message": "No data provided"
}

Environment

This project was developed in Python 3.12.3 with the following packages:

  • flask == 3.0.3
  • pytest == 8.2.2
  • pytest-flask == 0.8.1

It is recommended to set up a virtual environment to run the project by using the following command:

python3 -m venv /path/to/new/virtual/environment

How to Set Up the Project

  1. Clone the repository to your local machine.
    git clone https://github.com/supershiye/InterviewAssessement.git
  2. Install the required packages by running:
    pip install -r requirements.txt
  3. Navigate to the downloaded repository directory.
    cd /path/to/downloaded/folder/InterviewAssessement
  4. Run the Flask app by running:
    python run.py
  5. The Flask app will be running on http://127.0.0.1:5000/ by default.
  6. Note: The debug mode is set to True in the run.py file. Please change it to False in production.

How to Test the Project

  1. Repeat steps 1 to 3 from the setup instructions to set up the project if you haven't already.
  2. Run the unit tests by running:
    pytest
  3. Tests are written in the test_app.py file.

Usage of Git and Git Commands

This project is developed in Visual Studio Code with Git integrated. The basic Git workflow is to create a branch for each feature or bug fix and merge it back to the main branch after testing. The following Git commands are used to manage the project:

1. `git init` to initialize the repository.
2. `git checkout -b {branch name}` to create a new branch and switch to it.
3. `git add .` to stage all the changes.
4. `git commit -m "{commit message}"` to commit the changes.
5. `git push origin {branch name}` to push the changes to the remote repository.
6. `git checkout main` to switch to the main branch.
7. `git pull origin main` to pull the changes from the remote repository.
8. `git merge {branch name}` to merge the changes from the branch to the main branch.

interviewassessement's People

Contributors

supershiye avatar

Watchers

 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.