wip ledger/register.go
This commit is contained in:
57
ledger/register.go
Normal file
57
ledger/register.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package ledger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"slices"
|
||||
"time"
|
||||
)
|
||||
|
||||
func RegisterWithContributionPrediction(reg map[string]Balances, windowAsPercentOfTotalDuration float64) (map[string]Balances, error) {
|
||||
times, err := registerTimesInUnix(reg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
windowDuration := time.Second * time.Duration(float64(slices.Max(times)-slices.Min(times))*windowAsPercentOfTotalDuration)
|
||||
log.Println(windowDuration)
|
||||
|
||||
lastReal := time.Unix(slices.Max(times), 0)
|
||||
lastPredicted := lastReal
|
||||
for lastPredicted.Before(lastReal.Add(windowDuration)) {
|
||||
lastPredicted = lastPredicted.Add(time.Hour * 24 * time.Duration((45 - lastPredicted.Day())))
|
||||
log.Println(lastPredicted)
|
||||
}
|
||||
|
||||
result := make(map[string]Balances)
|
||||
return result, io.EOF
|
||||
}
|
||||
|
||||
func RegisterWithCompoundingInterestPrediction(reg map[string]Balances, windowAsPercentOfTotalDuration float64, name string, rate float64) (map[string]Balances, error) {
|
||||
result := make(map[string]Balances)
|
||||
return result, io.EOF
|
||||
}
|
||||
|
||||
func registerTimesInUnix(reg map[string]Balances) ([]int64, error) {
|
||||
result := make([]int64, 0, len(reg))
|
||||
for k := range reg {
|
||||
v, err := registerTime(k)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, v.Unix())
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func registerTime(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)
|
||||
}
|
||||
Reference in New Issue
Block a user