printing normalize appends factor and real delta
cicd / ci (push) Successful in 58s
Details
cicd / ci (push) Successful in 58s
Details
parent
5cc9b141b9
commit
fe98fa67f3
|
|
@ -4,6 +4,7 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
|
|
@ -126,9 +127,15 @@ func Main() {
|
|||
}
|
||||
|
||||
func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly, normalized bool, date string) {
|
||||
maxes := map[ledger.Currency]float64{}
|
||||
keys := []string{}
|
||||
for k := range balances {
|
||||
for k, v := range balances {
|
||||
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)
|
||||
|
||||
|
|
@ -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)
|
||||
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 {
|
||||
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)
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue