diff --git a/cmd/clitest/main.go b/cmd/clitest/main.go index d058161..046b5c9 100644 --- a/cmd/clitest/main.go +++ b/cmd/clitest/main.go @@ -83,52 +83,16 @@ func main() { // MODIFIERS if predictionMonths, err := strconv.ParseInt(r.URL.Query().Get("predictionMonths"), 10, 16); err == nil && predictionMonths > 0 { - for _, whatIf := range r.URL.Query()["predictWhatIf"] { // ?whatIf=2023-01=AssetAccount:Cash=$=-1.00 - date := strings.Split(whatIf, "=")[0] - name := strings.Split(whatIf, "=")[1] - currency := ledger.Currency(strings.Split(whatIf, "=")[2]) - delta, err := strconv.ParseFloat(strings.Split(whatIf, "=")[3], 64) - if err != nil { - panic(err) - } - mostRecentDateBefore := "" - for _, d := range register.Dates() { - if _, ok := register[d][name]; !ok { - continue - } else if d > date { - continue - } - mostRecentDateBefore = d - } - balanceWouldBe := maps.Clone(register[mostRecentDateBefore][name]) - balanceWouldBe[currency] += delta - register[date][name] = balanceWouldBe - } - predictionDuration := time.Hour * 24 * 365 / 12 * time.Duration(predictionMonths) - if r.URL.Query().Get("predictContributions") != "" { - register, err = ana.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 = ana.RegisterWithCompoundingInterestPrediction(register, predictionDuration, name, rate) - if err != nil { - panic(err) - } - } + window := time.Hour * 24.0 * 365.0 / 12.0 * time.Duration(predictionMonths) + // TODO whatif + // TODO ana.Prediction 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 = ana.BPIsWithFixedGrowthPrediction(bpis, predictionDuration, currency, rate) + bpis, err = ana.BPIsWithFixedGrowthPrediction(bpis, window, currency, rate) if err != nil { panic(err) } @@ -138,13 +102,7 @@ func main() { register = register.WithBPIs(bpis) } if zoomStart, err := time.ParseInLocation("2006-01", r.URL.Query().Get("zoomStart"), time.Local); err == nil { - result := make(ledger.Register) - for d := range register { - if d >= zoomStart.Format("2006-01") { - result[d] = register[d] - } - } - register = result + register = register.Between(zoomStart, time.Now().Add(time.Hour*24*365*100)) } // /MODIFIERS