From 6638ee2dab7d7440c6cec36cfd9175a08ce38a56 Mon Sep 17 00:00:00 2001 From: "Cal.W" <20716204+calw20@users.noreply.github.com> Date: Sun, 28 Jun 2020 22:29:00 +1000 Subject: [PATCH] Fixed? the netBalance calculation --- bankView.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bankView.py b/bankView.py index 6829107..918c6ca 100644 --- a/bankView.py +++ b/bankView.py @@ -133,13 +133,13 @@ def calculateStats(transactions, yearRangeVal=None, monthRangeVal=None, otherFel periodTransactions = sorted(periodTransactions, reverse = True, key = lambda x: x[1]) stats = { - "credits" : round(sum([abs(x[2]) for x in periodTransactions if x[2] > 0]), 2) if len([abs(x[2]) for x in periodTransactions if x[2] > 0]) > 0 else float(0), - "debits" : round(sum([abs(x[2]) for x in periodTransactions if x[2] < 0]), 2) if len([abs(x[2]) for x in periodTransactions if x[2] < 0]) > 0 else float(0), + "totalCredits" : round(sum([abs(x[2]) for x in periodTransactions if x[2] > 0]), 2) if len([abs(x[2]) for x in periodTransactions if x[2] > 0]) > 0 else float(0), + "totalDebits" : round(sum([abs(x[2]) for x in periodTransactions if x[2] < 0]), 2) if len([abs(x[2]) for x in periodTransactions if x[2] < 0]) > 0 else float(0), "largestCredit" : max(periodTransactions, key=lambda x: x[2]) if len(periodTransactions) > 0 else (datetime.now(), datetime.now(), 0, "", 0, "", ""), "largestDebit" : min(periodTransactions, key=lambda x: x[2]) if len(periodTransactions) > 0 else (datetime.now(), datetime.now(), 0, "", 0, "", ""), "averageCredit" : round(statistics.fmean([abs(x[2]) for x in periodTransactions if x[2] > 0]), 2) if len([abs(x[2]) for x in periodTransactions if x[2] > 0]) > 0 else float(0), "averageDebit" : round(statistics.fmean([abs(x[2]) for x in periodTransactions if x[2] < 0]), 2) if len([abs(x[2]) for x in periodTransactions if x[2] < 0]) > 0 else float(0), - "netBalance" : round(sum([x[4] for x in periodTransactions]), 2) if len(periodTransactions) > 0 else float(0), + "netBalance" : round(sum([x[2] for x in periodTransactions]), 2) if len(periodTransactions) > 0 else float(0), "averageBalance" : round(statistics.fmean([x[4] for x in periodTransactions]), 2) if len(periodTransactions) > 0 else float(0), "highestBalance" : float(max(periodTransactions, key=lambda x: x[4])[4]) if len(periodTransactions) > 0 else float(0), "lowestBalance" : float(min(periodTransactions, key=lambda x: x[4])[4]) if len(periodTransactions) > 0 else float(0), @@ -157,11 +157,14 @@ def foo(transactions): for year in years: pass +import pprint + +#[TODO] Net balance and averages seem funny / dont line up with excell :/ if __name__ == "__main__": trans = loadTransactionData() - stats = calculateStats(trans) - print(stats['averageBalance']) + stats = calculateStats(trans, 2020, 1) + pprint.pprint(stats, indent=4) #calculateStats(trans)