Skip to content

Commit

Permalink
Major improvements and readability fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rob93c committed May 16, 2019
1 parent 2064af5 commit 6c153bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
38 changes: 30 additions & 8 deletions For_my.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# Created by Roberto Cella
# For any question mail me at [email protected]

Expand All @@ -21,14 +22,13 @@
import pandas as pd
from pathlib import Path
from pynput.keyboard import Key, Controller
from summer import summer
from functools import lru_cache


class For_my:

@lru_cache(maxsize=64)
def main(self):
# Windows requires a precise file path, i.e.
# Path("C:\\Users\\user\\Desktop\\For_my\\data.csv")
path = Path("data.csv")
sys.tracebacklimit = 0
keyboard = Controller()
Expand All @@ -53,12 +53,13 @@ def main(self):
"Quanto hai guadagnato questa settimana? ")
])
elif choice == "2": # cronologia spese
print(f"\nLe spese totali sono state di {summer(1)}€.")
print(f"\nLe spese totali sono state di {Summer.summer(1)}€.")
elif choice == "3": # cronologia latte
print(f"\nHai usato un totale di {summer(2)} litri.")
elif choice == "4": # entrate
gain = summer(3) - summer(1) - summer(2) * 0.4
print(f"\nHai guadagnato un netto di {gain}0€")
print(f"\nHai usato un totale di {Summer.summer(2)} litri.")
elif choice == "4": # entrate nette
gain = Summer.summer(3) - Summer.summer(1) - \
Summer.summer(2) * 0.4
print(f"\nHai guadagnato un netto di {Summer.nicegain(gain)}€")
elif choice == "5": # grafico
df = pd.read_csv("data.csv")

Expand Down Expand Up @@ -97,4 +98,25 @@ def main(self):
break


class Summer:

# takes an index and sums every number at that index in a csv file
def summer(index: int) -> int:
tot = 0
with Path("data.csv").open("r") as op:
reader = csv.reader(op, delimiter=",")
data = [line[index] for line in reader if line[index].isdigit()]
for value in data:
tot += int(value)
return tot

# Windows requires a precise file path, i.e.
# Path("C:\\Users\\user\\Desktop\\For_my\\data.csv")

# Takes a float with 13 decimal numbers and returns just the first 2
def nicegain(num: float) -> float:
strnum = str(num)
return float(strnum[:-11])


For_my().main()
12 changes: 0 additions & 12 deletions summer.py

This file was deleted.

0 comments on commit 6c153bc

Please sign in to comment.