main
bel 2023-10-27 07:55:34 -06:00
parent 1e9962d996
commit bbe4b468ef
1 changed files with 5 additions and 47 deletions

View File

@ -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