fix
cicd / ci (push) Successful in 1m14s
Details
cicd / ci (push) Successful in 1m14s
Details
parent
0066a267a6
commit
cc546d9b2d
|
|
@ -148,17 +148,23 @@ func Main() {
|
||||||
cumulatives := make(ledger.Balances)
|
cumulatives := make(ledger.Balances)
|
||||||
var sum float64
|
var sum float64
|
||||||
for key := range balances {
|
for key := range balances {
|
||||||
usd, ok := balances[key][ledger.USD]
|
if _, ok := cumulatives[key]; !ok {
|
||||||
if ok {
|
cumulatives[key] = make(ledger.Balance)
|
||||||
cumulatives[key] = ledger.Balance{ledger.USD: usd}
|
}
|
||||||
sum += usd
|
for currency, val := range balances[key] {
|
||||||
|
if currency == ledger.USD {
|
||||||
|
cumulatives[key][currency] = val
|
||||||
|
sum += val
|
||||||
|
} else {
|
||||||
|
cumulatives[key][currency] = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for key := range cumulatives {
|
for key := range cumulatives {
|
||||||
cumulatives[key][ledger.USD] = 100 * cumulatives[key][ledger.USD] / sum
|
cumulatives[key][ledger.USD] = 100 * cumulatives[key][ledger.USD] / sum
|
||||||
}
|
}
|
||||||
|
|
||||||
FPrintBalances(w, "", balances, cumulatives, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02"), false, maxAccW, "%.0f%%%%")
|
FPrintBalances(w, "", balances, cumulatives, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02"), false, maxAccW, "%.0f%%")
|
||||||
case "gra": // graph
|
case "gra": // graph
|
||||||
dateGrouping := "^[0-9]{4}-[0-9]{2}"
|
dateGrouping := "^[0-9]{4}-[0-9]{2}"
|
||||||
if period := config.Query.Period; !period.Empty() {
|
if period := config.Query.Period; !period.Empty() {
|
||||||
|
|
@ -352,9 +358,10 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger
|
||||||
|
|
||||||
normalizer := ana.NewDefaultNormalizer()
|
normalizer := ana.NewDefaultNormalizer()
|
||||||
|
|
||||||
format := fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%"+cumulativeFormat+")\n", linePrefix, max)
|
cumulativeFormat = strings.ReplaceAll(cumulativeFormat, "%", "%%")
|
||||||
|
format := fmt.Sprintf("%s%%-%ds\t%%s%%.2f ("+cumulativeFormat+")\n", linePrefix, max)
|
||||||
if normalized {
|
if normalized {
|
||||||
format = fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f (%%.2f @%%.2f (%"+cumulativeFormat+")))\n", linePrefix, max)
|
format = fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f (%%.2f @%%.2f ("+cumulativeFormat+")))\n", linePrefix, max)
|
||||||
}
|
}
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
printableKey := key
|
printableKey := key
|
||||||
|
|
@ -389,13 +396,10 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger
|
||||||
for _, currency := range currencies {
|
for _, currency := range currencies {
|
||||||
printableCurrency := currency
|
printableCurrency := currency
|
||||||
format := format
|
format := format
|
||||||
printPrintableCurrency := strings.Count(cumulativeFormat, "%s") > 0
|
|
||||||
if printPrintableCurrency {
|
|
||||||
if printableCurrency != "$" {
|
if printableCurrency != "$" {
|
||||||
printableCurrency += " "
|
printableCurrency += " "
|
||||||
format = strings.ReplaceAll(format, "%.2f", "%.3f")
|
format = strings.ReplaceAll(format, "%.2f", "%.3f")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if usdOnly && printableCurrency != "$" {
|
if usdOnly && printableCurrency != "$" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -407,9 +411,14 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger
|
||||||
cumulative = value
|
cumulative = value
|
||||||
}
|
}
|
||||||
|
|
||||||
if printPrintableCurrency {
|
printingPercents := strings.Contains(cumulativeFormat, "%%%%")
|
||||||
|
if !printingPercents {
|
||||||
if !normalized {
|
if !normalized {
|
||||||
fmt.Fprintf(w, format, printableKey, printableCurrency, balances[key][currency], printableCurrency, cumulative)
|
fmt.Fprintf(w, format,
|
||||||
|
printableKey,
|
||||||
|
printableCurrency, balances[key][currency],
|
||||||
|
printableCurrency, cumulative,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
factor := normalizer.NormalizeFactor(key, date)
|
factor := normalizer.NormalizeFactor(key, date)
|
||||||
trailingMax := maxes[currency] - math.Abs(balances[key][currency])
|
trailingMax := maxes[currency] - math.Abs(balances[key][currency])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue