Giter Club home page Giter Club logo

npi_calculator's Introduction

NPI Calculator

Overview

The NPI Calculator is a tool designed to perform calculations using Reverse Polish Notation (RPN), also known as postfix notation. This project includes API handling, database interactions, and computation.

Table of Contents

Directory Structure

The project directory is organized as follows:

npi_calculator/
├── .github/
│   └── workflows/
│       └── ci_cd.yaml
├── .venv/
├── data/
│   ├── api_requests.db
│   └── test_api_requests.db
├── output_files/
│   └── test.csv
├── src/
│   ├── api/
│   │   ├── routers/
│   │   │   └── init.py
│   │   └── app.py
│   ├── calculator/
│   │   ├── init.py
│   │   └── npi_calculator.py
│   └── database/
│       ├── init.py
│       └── database.py
├── tests/
│   ├── api/
│   │   └── test.py
│   ├── calculator/
│   │   └── test.py
│   └── database/
│       └── test.py
├── .flake8
├── .gitignore
├── docker-compose.yml
├── Dockerfile
├── README.md
├── requirements.txt

Setup Instructions

To set up the NPI Calculator project, follow these steps:

  1. Clone the repository:
git clone https://github.com/maxpline83/npi_calculator.git
  1. Navigate to the project directory:
cd npi_calculator
  1. Create a virtual environment:
python -m venv .venv
  1. Activate the virtual environment:
source .venv/bin/activate
  1. Install the required dependencies:
pip install -r requirements.txt
  1. Run the application using Docker Compose:
docker-compose -f docker-compose.yml build
docker-compose -f docker-compose.yml up -d
  1. Access the NPI Calculator API at http://localhost:8000 and start performing NPI calculations.

API Endpoints

Overview

The NPI Calculator API provides several endpoints to interact with the calculator and database functionalities. Below are the endpoints available:

Endpoint Details

Compute NPI Expression

  • Endpoint: /npi_calculator/{expression}
  • Method: GET
  • Description: Computes an NPI-related expression and stores the result in the database.
  • Parameters:
    • expression (string): The NPI expression to evaluate.
  • Usage Example:
GET /npi_calculator/1 3 +

Response Example (Success):

{
    "expression": "1 3 +",
    "result": "4"
}

Response Example (Error):

{
    "expression": "1 0 ÷",
    "error": "Division by zero is not allowed"
}

Insert Example Data

  • Endpoint: /database/insert_example_data
  • Method: GET
  • Description: Inserts example data into the database for testing purposes.
  • Usage Example:
GET /database/insert_example_data

Response Example:

{
    "message": "Example data inserted!"
}

Get Calculation History

  • Endpoint: /database/history
  • Method: GET
  • Description: Retrieves the history of calculations stored in the database.
  • Usage Example:
GET /database/history

Response Example:

[
  {
    "query": "5 3 +",
    "result": 8
  },
  {
    "query": "4 2 * 3 +",
    "result": 11
  },
  {
    "query": "10 2 ÷",
    "result": 5
  }
]

Clear Calculation History

  • Endpoint: /database/clear
  • Method: GET
  • Description: Clears all calculation history from the database.
  • Usage Example:
GET /database/clear

Response Example:

{
    "message": "DB Reset!"
}

Export Data to CSV

  • Endpoint: /database/export_to_csv/{filename}
  • Method: GET
  • Description: Exports the calculation history to a CSV file with the specified filename.
  • Parameters:
    • filename (string): The name of the CSV file to export.
  • Usage Example:
GET /database/export_to_csv/test.csv

Response Example:

{
    "message": "Data exported to test.csv"
}

Using curl:

# Compute NPI Expression
curl -X GET http://localhost:8000/npi_calculator/2 5 +

# Insert Example Data
curl -X GET http://localhost:8000/database/insert_example_data

# Get Calculation History
curl -X GET http://localhost:8000/database/history

# Clear Calculation History
curl -X GET http://localhost:8000/database/clear

# Export Data to CSV
curl -X GET http://localhost:8000/database/export_to_csv/test.csv

Testing

Running Tests Locally

The project uses unittest for testing. You can run the tests locally using the following commands:

Calculator Module Tests

To run the tests for the calculator module:

python -m unittest tests.calculator.test

Basic API Tests

To run the basic API tests:

python -m unittest tests.api.test

Calculator API Tests

To run the calculator API tests:

python -m unittest tests.api.test_calculator

API Integration Tests

To run the API integration tests:

python -m unittest tests.api.test_database

Database Tests

To run the database tests:

python -m unittest tests.database.test

CI/CD

The project uses GitHub Actions for continuous integration and deployment. The CI/CD pipeline is defined in .github/workflows/ci_cd.yaml.

npi_calculator's People

Contributors

maxpline83 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.