no predict contributions if less than 2 balances
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"maps"
|
||||
"net/http"
|
||||
"os"
|
||||
"slices"
|
||||
@@ -77,40 +78,50 @@ func main() {
|
||||
}
|
||||
|
||||
register := deltas.Like(foolike...).Register()
|
||||
bpis := maps.Clone(bpis)
|
||||
|
||||
// MODIFIERS
|
||||
if predictionMonths, err := strconv.ParseInt(r.URL.Query().Get("predictionMonths"), 10, 8); err == nil && predictionMonths > 0 {
|
||||
predictionDuration := time.Hour * 24 * 365 / 12 * time.Duration(predictionMonths)
|
||||
if r.URL.Query().Get("predictContributions") != "" {
|
||||
register, err = ledger.RegisterWithContributionPrediction(register, predictionDuration)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
for _, nameRate := range r.URL.Query()["predictCompoundingInterest"] {
|
||||
name := strings.Split(nameRate, "=")[0]
|
||||
rate, err := strconv.ParseFloat(strings.Split(nameRate, "=")[1], 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
register, err = ledger.RegisterWithCompoundingInterestPrediction(register, predictionDuration, name, rate)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
for _, currencyRate := range r.URL.Query()["predictFixedGrowth"] {
|
||||
currency := strings.Split(currencyRate, "=")[0]
|
||||
rate, err := strconv.ParseFloat(strings.Split(currencyRate, "=")[1], 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
bpis, err = ledger.BPIsWithFixedGrowthPrediction(bpis, predictionDuration, currency, rate)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if r.URL.Query().Get("bpi") != "" {
|
||||
for date := range register {
|
||||
register[date] = register[date].WithBPIs(bpis)
|
||||
}
|
||||
}
|
||||
if predictionMonths, err := strconv.ParseInt(r.URL.Query().Get("predictionMonths"), 10, 8); err == nil && predictionMonths > 0 {
|
||||
predictionDuration := time.Hour * 24 * 365 / 12 * time.Duration(predictionMonths)
|
||||
if r.URL.Query().Get("predictContributions") != "" {
|
||||
register = ledger.RegisterWithContributionPrediction(register, predictionDuration)
|
||||
}
|
||||
for _, nameRate := range r.URL.Query()["predictCompoundingInterest"] {
|
||||
splits := strings.Split(nameRate, "=")
|
||||
if len(splits) != 2 {
|
||||
panic(splits)
|
||||
}
|
||||
name := splits[0]
|
||||
rate, err := strconv.ParseFloat(splits[1], 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
register = ledger.RegisterWithCompoundingInterestPrediction(register, predictionDuration, name, rate)
|
||||
}
|
||||
}
|
||||
// /MODIFIERS
|
||||
|
||||
nameCurrencyDateValue := map[string]map[ledger.Currency]map[string]float64{}
|
||||
dates := []string{}
|
||||
names := []string{}
|
||||
for date, balances := range register {
|
||||
dates = append(dates, date)
|
||||
for name, balance := range balances {
|
||||
names = append(names, name)
|
||||
for currency, value := range balance {
|
||||
if _, ok := nameCurrencyDateValue[name]; !ok {
|
||||
nameCurrencyDateValue[name] = make(map[ledger.Currency]map[string]float64)
|
||||
@@ -122,13 +133,14 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
slices.Sort(dates)
|
||||
slices.Sort(names)
|
||||
|
||||
chart := NewChart("line")
|
||||
if v := r.URL.Query().Get("chart"); v != "" {
|
||||
chart = NewChart(v)
|
||||
}
|
||||
|
||||
dates := register.Dates()
|
||||
names := register.Names()
|
||||
chart.AddX(dates)
|
||||
|
||||
switch r.URL.Path {
|
||||
|
||||
Reference in New Issue
Block a user