From 9ab9212c3351750a0c4926514204580652f5dc2c Mon Sep 17 00:00:00 2001 From: filza2112 Date: Fri, 21 Jul 2023 12:55:25 +0530 Subject: [PATCH] PPF Calculator --- DOCUMENTATION.md | 4 ++++ ENDPOINTS.md | 20 +++++++++++++++++++- helpers/functions.py | 8 ++++++++ main.py | 11 +++++++++++ tasks/PPFCalculator.py | 12 ++++++++++++ validators/request_validators.py | 7 ++++++- 6 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 tasks/PPFCalculator.py diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 4429a0ec..53b5c3b5 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -66,3 +66,7 @@ The initial price of the product or service. | | | | - `ending_inventory` (float): The final amount of accounts payable ending the cycle. | | | | - `total_credit_purchases` (float): The amount of purchases on credit during the cycle. | |-----------------------------|----------------------------------------|---------------------------------------------------------------------| +|---------------------------|----------------------------------------|---------------------------------------------------------| +| GET /ppf_calculator | Calculate Public Provident Fund(PPF) | - `depos` (int): Annual Deposit. | +| | | - `tenure` (int): Total years of investment. | +| | | - `interest` (float): percentage interest rate. | \ No newline at end of file diff --git a/ENDPOINTS.md b/ENDPOINTS.md index 356104ed..ad2c6987 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -2250,4 +2250,22 @@ Sample Output "Average Accounts Payable": 102500, "Average Payment Period": "33.7days", } -``` \ No newline at end of file +``` + +**POST** `/ppf_calculator` + +- Request body : `{ + "depos": 500, + "tenure": 15, + "interest": 7.1 +}` +- Sample output + +```py +{ + "Tag": "PPF Calcultor", + "Amount Anually deposited": 500, + "No. of Years": 15, + "percentage interst Rate": 7.1, + "Total Value of PPF": "13560" +} \ No newline at end of file diff --git a/helpers/functions.py b/helpers/functions.py index 5c84c479..8e3f734a 100644 --- a/helpers/functions.py +++ b/helpers/functions.py @@ -2055,3 +2055,11 @@ def average_payment_period(beginning_accounts_payable: float, ending_accounts_pa app = average_accounts_payable / (total_credit_purchases / 365) return app +# Function to Calculate PPF + +def ppf_calculator(depos:int, + tenure:int, + interest:float): + a=1+interest/100 + total_value= depos*(((a**tenure) - 1)/(interest/100))*a + return total_value diff --git a/main.py b/main.py index e387738b..69315f2c 100644 --- a/main.py +++ b/main.py @@ -139,6 +139,7 @@ from tasks.financialAssestRatio import financial_assest_ratio from tasks.PriceElasticity import calculate_price_elasticity from tasks.average_payment_period import average_payment_period_task +from tasks.PPFCalculator import ppf_calculator # Creating the app app = FastAPI( @@ -271,6 +272,7 @@ def index(): "/profit_percent": "Calculates the profit percentage", "/loss_percent": "Calculates the loss percentage", "/average_payment_period": "Calculate Average Payment Period a metric that allows a business to see how long it takes on average to pay its vendors." + "/ppf_calculator": "Calculates Public Provident Fund(PPF)" }, } @@ -1966,3 +1968,12 @@ def average_payment_period(request: AveragePaymentPeriod): return average_payment_period_task(request.beginning_accounts_payable , request.ending_accounts_payable , request.total_credit_purchases) +#Endpoint to Calculate Public Provident Fund(PPF) + +@app.post( + "/ppf_calculator", + tags=["ppf_calculator"], + description="Calculates Public Provident Fund(PPF)", +) +def simple_interest_rate(request: PPFCalculator): + return simple_interest_rate_task(request.depos, request.tenure, request.interest) \ No newline at end of file diff --git a/tasks/PPFCalculator.py b/tasks/PPFCalculator.py new file mode 100644 index 00000000..b0da2da1 --- /dev/null +++ b/tasks/PPFCalculator.py @@ -0,0 +1,12 @@ +def ppf_calculator(depos:int,tenure:int,interest:float): + try: + rate = functions.ppf_calculator(depos, tenure, interest) + return { + "Tag": "PPF Calculator", + "Total amount invested annualy": depos, + "No. of years": tenure, + "percentage interst rate": interest, + "Final Total value": f"{total_value}", + } + except: + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file diff --git a/validators/request_validators.py b/validators/request_validators.py index cd4f5867..06efcc82 100644 --- a/validators/request_validators.py +++ b/validators/request_validators.py @@ -647,4 +647,9 @@ class PriceElasticity(BaseModel): class AveragePaymentPeriod(BaseModel): beginning_accounts_payable: float ending_accounts_payable: float - total_credit_purchases: float \ No newline at end of file + total_credit_purchases: float + +class PPFcalculator(BaseModel): + depos:int + tenure:int + interest:float \ No newline at end of file