Fixed? the netBalance calculation
This commit is contained in:
parent
ccd1b813a4
commit
6638ee2dab
13
bankView.py
13
bankView.py
@ -133,13 +133,13 @@ def calculateStats(transactions, yearRangeVal=None, monthRangeVal=None, otherFel
|
|||||||
periodTransactions = sorted(periodTransactions, reverse = True, key = lambda x: x[1])
|
periodTransactions = sorted(periodTransactions, reverse = True, key = lambda x: x[1])
|
||||||
|
|
||||||
stats = {
|
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),
|
"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),
|
||||||
"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),
|
"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, "", ""),
|
"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, "", ""),
|
"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),
|
"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),
|
"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),
|
"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),
|
"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),
|
"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:
|
for year in years:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
import pprint
|
||||||
|
|
||||||
|
#[TODO] Net balance and averages seem funny / dont line up with excell :/
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
trans = loadTransactionData()
|
trans = loadTransactionData()
|
||||||
stats = calculateStats(trans)
|
stats = calculateStats(trans, 2020, 1)
|
||||||
print(stats['averageBalance'])
|
pprint.pprint(stats, indent=4)
|
||||||
|
|
||||||
#calculateStats(trans)
|
#calculateStats(trans)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user