WAY faster doing cumulative balances over summing [0,i] every reg loop
cicd / ci (push) Successful in 1m39s Details

main
bel 2025-04-06 10:05:42 -06:00
parent 058874b566
commit 9352ca82de
1 changed files with 5 additions and 3 deletions

View File

@ -107,8 +107,8 @@ func Main() {
FPrintBalances(w, "", balances, nil, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02")) FPrintBalances(w, "", balances, nil, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02"))
case "reg": case "reg":
transactions := deltas.Transactions() transactions := deltas.Transactions()
cumulative := make(ledger.Balances)
for i, transaction := range transactions { for _, transaction := range transactions {
balances := ledger.Deltas(transaction).Like(q).Group(group).Balances().WithBPIsAt(bpis, transaction[0].Date).Nonzero() balances := ledger.Deltas(transaction).Like(q).Group(group).Balances().WithBPIsAt(bpis, transaction[0].Date).Nonzero()
shouldPrint := false shouldPrint := false
shouldPrint = shouldPrint || len(balances) > 2 shouldPrint = shouldPrint || len(balances) > 2
@ -121,8 +121,10 @@ func Main() {
shouldPrint = shouldPrint || len(balances) > 0 shouldPrint = shouldPrint || len(balances) > 0
} }
if shouldPrint { if shouldPrint {
cumulative.PushAll(balances)
cumulative = cumulative.Nonzero()
fmt.Fprintf(w, "%s\t%s\n", transaction[0].Date, transaction[0].Description) fmt.Fprintf(w, "%s\t%s\n", transaction[0].Date, transaction[0].Description)
FPrintBalances(w, "\t\t", balances, transactions[:i+1].Deltas().Like(q).Group(group).Balances().WithBPIsAt(bpis, transaction[0].Date).Nonzero(), config.Query.USDOnly, config.Query.Normalize, transaction[0].Date) FPrintBalances(w, "\t\t", balances, cumulative, config.Query.USDOnly, config.Query.Normalize, transaction[0].Date)
} }
} }
default: default: