pretty print vs cumulative
cicd / ci (push) Successful in 1m52s
Details
cicd / ci (push) Successful in 1m52s
Details
parent
1a517eb8f2
commit
37f6f47375
|
|
@ -88,7 +88,7 @@ func Main() {
|
||||||
balances = balances.NotLike(notLikePattern)
|
balances = balances.NotLike(notLikePattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
FPrintBalances(os.Stdout, "", balances)
|
FPrintBalances(os.Stdout, "", balances, nil)
|
||||||
case "reg":
|
case "reg":
|
||||||
transactions := deltas.Transactions()
|
transactions := deltas.Transactions()
|
||||||
likes := []ledger.Like{}
|
likes := []ledger.Like{}
|
||||||
|
|
@ -123,27 +123,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)
|
FPrintBalances(os.Stdout, "\t\t", balances, transactions[:i+1].Deltas().Like(likes...).Balances())
|
||||||
|
|
||||||
cumulativeBalances := transactions[:i+1].Deltas().Like(likes...).Balances()
|
|
||||||
cumulativeBalancesKeys := []string{}
|
|
||||||
for k := range cumulativeBalances {
|
|
||||||
cumulativeBalancesKeys = append(cumulativeBalancesKeys, k)
|
|
||||||
}
|
|
||||||
slices.Sort(cumulativeBalancesKeys)
|
|
||||||
|
|
||||||
relevantCumulativeBalances := make(ledger.Balances)
|
|
||||||
for _, k := range cumulativeBalancesKeys {
|
|
||||||
m, ok := balances[k]
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
relevantCumulativeBalances[k] = make(ledger.Balance)
|
|
||||||
for k2 := range m {
|
|
||||||
relevantCumulativeBalances[k][k2] = cumulativeBalances[k][k2]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Printf("\t\t(%+v)\n", relevantCumulativeBalances.Nonzero())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
@ -151,7 +131,7 @@ func Main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FPrintBalances(w io.Writer, linePrefix string, balances ledger.Balances) {
|
func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger.Balances) {
|
||||||
keys := []string{}
|
keys := []string{}
|
||||||
for k := range balances {
|
for k := range balances {
|
||||||
keys = append(keys, k)
|
keys = append(keys, k)
|
||||||
|
|
@ -165,7 +145,7 @@ func FPrintBalances(w io.Writer, linePrefix string, balances ledger.Balances) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
format := fmt.Sprintf("%s%%-%ds\t%%s%%.2f\n", linePrefix, max)
|
format := fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.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] {
|
||||||
|
|
@ -178,7 +158,15 @@ func FPrintBalances(w io.Writer, linePrefix string, balances ledger.Balances) {
|
||||||
if printableCurrency != "$" {
|
if printableCurrency != "$" {
|
||||||
printableCurrency += " "
|
printableCurrency += " "
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, format, key, printableCurrency, balances[key][currency])
|
|
||||||
|
cumulative := balances[key][currency]
|
||||||
|
if balance, ok := cumulatives[key]; !ok {
|
||||||
|
} else if value, ok := balance[currency]; !ok {
|
||||||
|
} else {
|
||||||
|
cumulative = value
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(w, format, key, printableCurrency, balances[key][currency], printableCurrency, cumulative)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue