ana register to contributions

This commit is contained in:
bel
2023-10-26 20:07:23 -06:00
parent d93a3560da
commit 6c31005d24
2 changed files with 66 additions and 0 deletions

View File

@@ -39,10 +39,31 @@ func NewInterestPredictor(namePattern string, currencyPattern string, apy float6
func NewContributionPredictor(reg ledger.Register) Predictor {
monthlyRate := getMonthlyContributionRate(reg)
_ = monthlyRate
return func(given ledger.Balances, delta time.Duration) ledger.Balances {
panic(nil)
}
}
func getMonthlyContributionRate(reg ledger.Register) map[string]ledger.Balance {
panic(nil)
}
func getRecentContributions(reg ledger.Register) map[string][]ledger.Balance {
return getContributions(reg.Between(time.Now().Add(-1*time.Hour*365/2), time.Now()))
}
func getContributions(reg ledger.Register) map[string][]ledger.Balance {
contributions := make(map[string][]ledger.Balance)
for _, date := range reg.Dates() {
for name := range reg[date] {
contributions[name] = append(contributions[name], maps.Clone(reg[date][name]))
if a := contributions[name]; len(a) > 1 {
for k := range a[len(a)-2] {
a[len(a)-1][k] -= a[len(a)-2][k]
}
}
}
}
return contributions
}