package ledger import ( "fmt" "io" "log" "maps" "time" ) func RegisterWithContributionPrediction(reg map[string]Balances, windowAsPercentOfTotalDuration float64) (map[string]Balances, error) { return reg, io.EOF } func BPIWithFixedGrowthPrediction(reg map[string]Balances, windowAsPercentOfTotalDuration float64, pattern string, rate float64) (map[string]Balances, error) { result := make(map[string]Balances) return result, io.EOF } func RegisterWithCompoundingInterestPrediction(reg map[string]Balances, windowAsPercentOfTotalDuration float64, pattern string, rate float64) (map[string]Balances, error) { nameToLastDate := func() map[string]string { result := map[string]string{} for date, balances := range reg { for name := range balances { if result[name] < date { result[name] = date } } } return result }() firstTime, lastTime := func() (time.Time, time.Time) { var latest time.Time first := time.Now() for _, v := range nameToLastDate { v2, _ := dateToTime(v) if latest.Before(v2) { latest = v2 } if first.Before(v2) { first = v2 } } return first, latest }() log.Println("first", firstTime, "last time", lastTime, "nameToDate", nameToLastDate) lastPrediction := lastTime for lastPrediction.Before(lastTime.Add(lastTime.Sub(firstTime) * time.Duration(windowAsPercentOfTotalDuration))) { lastPrediction = lastPrediction.Add(time.Hour * 24 * (45 - lastPrediction.Day())) TODO ^ } result := maps.Clone(reg) return result, io.EOF } func dateToTime(s string) (time.Time, error) { for _, layout := range []string{ "2006-01-02", "2006-01", } { if t, err := time.ParseInLocation(layout, s, time.Local); err == nil { return t, err } } return time.Time{}, fmt.Errorf("no layout matching %q", s) }