From 8d8be105a9f0f9ccea3f1cbed8a2767e138db819 Mon Sep 17 00:00:00 2001 From: bel Date: Wed, 25 Oct 2023 16:49:15 -0600 Subject: [PATCH] wip --- ledger/register.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/ledger/register.go b/ledger/register.go index 83c6e9e..dd4e7b6 100644 --- a/ledger/register.go +++ b/ledger/register.go @@ -28,23 +28,35 @@ func RegisterWithContributionPrediction(reg map[string]Balances, windowAsPercent }() log.Print(datesToPredict) - namesDatesContributions := func() map[string]map[string]Balances { - panic("todo") + namesDatesBalance := func() map[string]map[string]Balance { + result := make(map[string]map[string]Balance) + for date, balances := range reg { + for name, balance := range balances { + if _, ok := result[name]; !ok { + result[name] = make(map[string]Balance) + } + result[name][date] = balance + } + } + return result }() result := make(map[string]Balances) - for name, datesContributions := range namesDatesContributions { + for name, datesBalance := range namesDatesBalance { result[name] = func() Balances { dates := func() []string { result := make([]string, 0) - for k := range datesContributions { + for k := range datesBalance { result = append(result, k) } return result }() slices.Sort(dates) - //var half, threeQuarter, sevenEighths string - panic(fmt.Sprint(name, dates)) + half := dates[len(dates)/2] + threeQuarter := dates[int(3.0*(len(dates)/4.0))] + sevenEighths := dates[int(7.0*(len(dates)/8.0))] + sum:= func(start, stop string) balance + panic(fmt.Sprintf("%s: %s .. %s .. %s (%v)", name, half, threeQuarter, sevenEighths, dates)) }() } return result, nil