Fixed? the netBalance calculation

This commit is contained in:
Cal.W 2020-06-28 22:29:00 +10:00
parent ccd1b813a4
commit 6638ee2dab

View File

@ -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)