Skip to content

Commit

Permalink
Added docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
luisgdev committed Jun 23, 2023
1 parent 7496535 commit f2f31f0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
""" Main module """

import views
from models import Compound, Simple

Expand Down
18 changes: 15 additions & 3 deletions src/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
""" Models module """

from typing import Callable, List, TypedDict


Expand Down Expand Up @@ -99,18 +101,28 @@ def __init__(self, cap: float, days: int, cycles: int):
self.days = days
self.cycles = cycles
self.spent_gas: float
self._yield: float
self.yield_: float
self.profit: float
self.roi: float
self.dif_profit: float
self.dif_gas: float

def set_gas(self, gas: float) -> None:
"""
Set gas fee.
:param gas: Gas fee.
:return: None.
"""
self.spent_gas = self.cycles * gas

def set_interest(self, interest: float) -> None:
self._yield = (self.cap * (1 + interest) ** self.cycles) - self.cap
self.profit = self._yield - self.spent_gas
"""
Set interest rate.
:param gas: Float with interest rate.
:return: None.
"""
self.yield_ = (self.cap * (1 + interest) ** self.cycles) - self.cap
self.profit = self.yield_ - self.spent_gas
self.roi = (self.profit / self.cap) * 100


Expand Down
26 changes: 24 additions & 2 deletions src/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import List, TypedDict
""" Views module """

from typing import List

from rich import box
from rich.console import Console
Expand Down Expand Up @@ -29,11 +31,21 @@


def print_markdown(text: str) -> None:
"""
Print the text in markwdown format.
:params text: String with the text.
:return: None.
"""
markdown_formatted_text: Markdown = Markdown(text)
CONSOLE.print(markdown_formatted_text)


def simple_interest(simple: Simple) -> None:
"""
Print the simple interest table.
:params simple: Simple interest object.
:return: None.
"""
print_markdown("***")
table: Table = Table(title="Interes Simple", box=box.SIMPLE)
header: List[str] = ["Period", "Income ($)", "ROI (%)"]
Expand All @@ -53,6 +65,11 @@ def simple_interest(simple: Simple) -> None:


def compound_interest(comp: Compound) -> None:
"""
Print the compound interest table.
:params comp: Compound interest object.
:return: None.
"""
print_markdown("---")
title = f"Interes Compuesto por {comp.periods[0].days} días"
table = Table(title=title, box=box.SIMPLE)
Expand All @@ -62,7 +79,7 @@ def compound_interest(comp: Compound) -> None:
for row in comp.periods:
table.add_row(
str(row.days),
str(round(row._yield, 4)),
str(round(row.yield_, 4)),
str(round(row.spent_gas, 4)),
str(round(row.profit, 4)),
str(round(row.dif_profit, 4)),
Expand All @@ -80,6 +97,11 @@ def compound_interest(comp: Compound) -> None:


def best_comp(best_pds: List[Period]) -> None:
"""
Print a table with the best periods to do compund.
:params best_pds: List of Period object.
:return: None.
"""
print_markdown("___")
table = Table(title="Frecuencias Óptimas", box=box.SIMPLE)
header = ["Period", "ROI ($)", "Profit (%)"]
Expand Down

0 comments on commit f2f31f0

Please sign in to comment.