diff --git a/For_my.py b/For_my.py index d7acdbc..36a1460 100644 --- a/For_my.py +++ b/For_my.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- + # Created by Roberto Cella # For any question mail me at rob.uniuc@gmail.com @@ -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() @@ -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") @@ -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() diff --git a/summer.py b/summer.py deleted file mode 100644 index ed7567d..0000000 --- a/summer.py +++ /dev/null @@ -1,12 +0,0 @@ -from pathlib import Path -import csv - - -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