prune
This commit is contained in:
@@ -83,52 +83,16 @@ func main() {
|
|||||||
|
|
||||||
// MODIFIERS
|
// MODIFIERS
|
||||||
if predictionMonths, err := strconv.ParseInt(r.URL.Query().Get("predictionMonths"), 10, 16); err == nil && predictionMonths > 0 {
|
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
|
window := time.Hour * 24.0 * 365.0 / 12.0 * time.Duration(predictionMonths)
|
||||||
date := strings.Split(whatIf, "=")[0]
|
// TODO whatif
|
||||||
name := strings.Split(whatIf, "=")[1]
|
// TODO ana.Prediction
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, currencyRate := range r.URL.Query()["predictFixedGrowth"] {
|
for _, currencyRate := range r.URL.Query()["predictFixedGrowth"] {
|
||||||
currency := strings.Split(currencyRate, "=")[0]
|
currency := strings.Split(currencyRate, "=")[0]
|
||||||
rate, err := strconv.ParseFloat(strings.Split(currencyRate, "=")[1], 64)
|
rate, err := strconv.ParseFloat(strings.Split(currencyRate, "=")[1], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
bpis, err = ana.BPIsWithFixedGrowthPrediction(bpis, predictionDuration, currency, rate)
|
bpis, err = ana.BPIsWithFixedGrowthPrediction(bpis, window, currency, rate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -138,13 +102,7 @@ func main() {
|
|||||||
register = register.WithBPIs(bpis)
|
register = register.WithBPIs(bpis)
|
||||||
}
|
}
|
||||||
if zoomStart, err := time.ParseInLocation("2006-01", r.URL.Query().Get("zoomStart"), time.Local); err == nil {
|
if zoomStart, err := time.ParseInLocation("2006-01", r.URL.Query().Get("zoomStart"), time.Local); err == nil {
|
||||||
result := make(ledger.Register)
|
register = register.Between(zoomStart, time.Now().Add(time.Hour*24*365*100))
|
||||||
for d := range register {
|
|
||||||
if d >= zoomStart.Format("2006-01") {
|
|
||||||
result[d] = register[d]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
register = result
|
|
||||||
}
|
}
|
||||||
// /MODIFIERS
|
// /MODIFIERS
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user