printing normalize appends factor and real delta
All checks were successful
cicd / ci (push) Successful in 58s
All checks were successful
cicd / ci (push) Successful in 58s
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -126,9 +127,15 @@ func Main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly, normalized bool, date string) {
|
func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly, normalized bool, date string) {
|
||||||
|
maxes := map[ledger.Currency]float64{}
|
||||||
keys := []string{}
|
keys := []string{}
|
||||||
for k := range balances {
|
for k, v := range balances {
|
||||||
keys = append(keys, k)
|
keys = append(keys, k)
|
||||||
|
for k2, v2 := range v {
|
||||||
|
if math.Abs(v2) > math.Abs(maxes[k2]) {
|
||||||
|
maxes[k2] = math.Abs(v2)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
slices.Sort(keys)
|
slices.Sort(keys)
|
||||||
|
|
||||||
@@ -143,7 +150,7 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger
|
|||||||
|
|
||||||
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 {
|
if normalized {
|
||||||
format = fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f (%%.2f @%%.2f))\n", linePrefix, max)
|
format = fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f (%%.2f @%%.2f (%%s%%.0f)))\n", linePrefix, max)
|
||||||
}
|
}
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
currencies := []ledger.Currency{}
|
currencies := []ledger.Currency{}
|
||||||
@@ -172,7 +179,8 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger
|
|||||||
fmt.Fprintf(w, format, key, printableCurrency, balances[key][currency], printableCurrency, cumulative)
|
fmt.Fprintf(w, format, key, printableCurrency, balances[key][currency], printableCurrency, cumulative)
|
||||||
} else {
|
} else {
|
||||||
factor := normalizer.NormalizeFactor(ledger.Delta{Name: key, Date: date})
|
factor := normalizer.NormalizeFactor(ledger.Delta{Name: key, Date: date})
|
||||||
fmt.Fprintf(w, format, key, printableCurrency, balances[key][currency], printableCurrency, cumulative, cumulative*factor, factor)
|
trailingMax := maxes[currency] - math.Abs(balances[key][currency])
|
||||||
|
fmt.Fprintf(w, format, key, printableCurrency, balances[key][currency], printableCurrency, cumulative, cumulative*factor, factor, printableCurrency, factor*trailingMax)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user