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.
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
To set up the NPI Calculator project, follow these steps:
- Clone the repository:
git clone https://github.com/maxpline83/npi_calculator.git
- Navigate to the project directory:
cd npi_calculator
- Create a virtual environment:
python -m venv .venv
- Activate the virtual environment:
source .venv/bin/activate
- Install the required dependencies:
pip install -r requirements.txt
- Run the application using Docker Compose:
docker-compose -f docker-compose.yml build
docker-compose -f docker-compose.yml up -d
- Access the NPI Calculator API at
http://localhost:8000
and start performing NPI calculations.
The NPI Calculator API provides several endpoints to interact with the calculator and database functionalities. Below are the endpoints available:
- 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"
}
- 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!"
}
- 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
}
]
- Endpoint:
/database/clear
- Method:
GET
- Description: Clears all calculation history from the database.
- Usage Example:
GET /database/clear
Response Example:
{
"message": "DB Reset!"
}
- 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"
}
# 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
The project uses unittest
for testing. You can run the tests locally using the following commands:
To run the tests for the calculator module:
python -m unittest tests.calculator.test
To run the basic API tests:
python -m unittest tests.api.test
To run the calculator API tests:
python -m unittest tests.api.test_calculator
To run the API integration tests:
python -m unittest tests.api.test_database
To run the database tests:
python -m unittest tests.database.test
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
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.