normalize
cicd / ci (push) Successful in 1m0s Details

main
bel 2025-04-03 23:04:08 -06:00
parent 266af7353a
commit 5cc9b141b9
2 changed files with 28 additions and 17 deletions

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"slices" "slices"
"strings" "strings"
"time"
"gogs.inhome.blapointe.com/ana-ledger/src/ana" "gogs.inhome.blapointe.com/ana-ledger/src/ana"
"gogs.inhome.blapointe.com/ana-ledger/src/ledger" "gogs.inhome.blapointe.com/ana-ledger/src/ledger"
@ -98,7 +99,7 @@ func Main() {
KindaLike(q). KindaLike(q).
KindaGroup(group). KindaGroup(group).
Nonzero() Nonzero()
FPrintBalances(os.Stdout, "", balances, nil, config.Query.USDOnly) FPrintBalances(os.Stdout, "", balances, nil, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02"))
case "reg": case "reg":
transactions := deltas.Transactions() transactions := deltas.Transactions()
@ -116,7 +117,7 @@ func Main() {
} }
if shouldPrint { if shouldPrint {
fmt.Printf("%s\t%s\n", transaction[0].Date, transaction[0].Description) fmt.Printf("%s\t%s\n", transaction[0].Date, transaction[0].Description)
FPrintBalances(os.Stdout, "\t\t", balances, transactions[:i+1].Deltas().Like(q).Group(group).Balances().WithBPIsAt(bpis, transaction[0].Date).Nonzero(), config.Query.USDOnly) FPrintBalances(os.Stdout, "\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)
} }
} }
default: default:
@ -124,7 +125,7 @@ func Main() {
} }
} }
func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly bool) { func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly, normalized bool, date string) {
keys := []string{} keys := []string{}
for k := range balances { for k := range balances {
keys = append(keys, k) keys = append(keys, k)
@ -138,7 +139,12 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger
} }
} }
normalizer := ana.NewDefaultNormalizer()
format := fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f)\n", linePrefix, max) format := fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f)\n", linePrefix, max)
if normalized {
format = fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f (%%.2f @%%.2f))\n", linePrefix, max)
}
for _, key := range keys { for _, key := range keys {
currencies := []ledger.Currency{} currencies := []ledger.Currency{}
for currency := range balances[key] { for currency := range balances[key] {
@ -162,7 +168,12 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger
cumulative = value cumulative = value
} }
if !normalized {
fmt.Fprintf(w, format, key, printableCurrency, balances[key][currency], printableCurrency, cumulative) fmt.Fprintf(w, format, key, printableCurrency, balances[key][currency], printableCurrency, cumulative)
} else {
factor := normalizer.NormalizeFactor(ledger.Delta{Name: key, Date: date})
fmt.Fprintf(w, format, key, printableCurrency, balances[key][currency], printableCurrency, cumulative, cumulative*factor, factor)
}
} }
} }
} }

View File

@ -19,19 +19,19 @@ type normalize struct {
func NewDefaultNormalizer() Normalizer { func NewDefaultNormalizer() Normalizer {
return NewNormalizer(). return NewNormalizer().
With("^Zach:", "2023-10-05", 139). // to turtle With("^Zach", "2023-10-05", 139). // to turtle
With("^Zach:", "2021-12-30", 135). // at pluralsight With("^Zach", "2021-12-30", 135). // at pluralsight
With("^Zach:", "2020-07-30", 120). // to pluralsight With("^Zach", "2020-07-30", 120). // to pluralsight
With("^Zach:", "2019-07-16", 77). // at fedex With("^Zach", "2019-07-16", 77). // at fedex
With("^Zach:", "2017-02-16", 49). // to fedex With("^Zach", "2017-02-16", 49). // to fedex
With("^Bel:", "2023-12-05", 190). // to render With("^Bel", "2023-12-05", 190). // to render
With("^Bel:", "2022-12-31", 154). // at q With("^Bel", "2022-12-31", 154). // at q
With("^Bel:", "2022-06-30", 148). // at q With("^Bel", "2022-06-30", 148). // at q
With("^Bel:", "2021-12-31", 122). // at q With("^Bel", "2021-12-31", 122). // at q
With("^Bel:", "2020-12-31", 118). // at q With("^Bel", "2020-12-31", 118). // at q
With("^Bel:", "2019-12-31", 111). // at q With("^Bel", "2019-12-31", 111). // at q
With("^Bel:", "2018-12-31", 92). // at q With("^Bel", "2018-12-31", 92). // at q
With("^Bel:", "2018-02-16", 86) // to q With("^Bel", "2018-02-16", 86) // to q
} }
func NewNormalizer() Normalizer { func NewNormalizer() Normalizer {