This commit is contained in:
Bel LaPointe
2023-10-26 07:43:44 -06:00
parent 78297a56a6
commit e1b601a130
3 changed files with 14 additions and 4 deletions

View File

@@ -10,6 +10,10 @@ type Balances map[string]Balance
type Balance map[Currency]float64
func (balances Balances) WithBPIs(bpis BPIs) Balances {
return balances.WithBPIsAt(bpis, "9")
}
func (balances Balances) WithBPIsAt(bpis BPIs, date string) Balances {
result := make(Balances)
for k, v := range balances {
if _, ok := result[k]; !ok {
@@ -18,7 +22,7 @@ func (balances Balances) WithBPIs(bpis BPIs) Balances {
for k2, v2 := range v {
scalar := 1.0
if k2 != USD {
scalar = bpis[k2].Lookup("9")
scalar = bpis[k2].Lookup(date)
}
result[k][USD] += v2 * scalar
}

View File

@@ -7,6 +7,14 @@ import (
type Register map[string]Balances
func (register Register) WithBPIs(bpis BPIs) Register {
result := make(Register)
for d := range register {
result[d] = register[d].WithBPIsAt(bpis, d)
}
return result
}
func (register Register) PushAll(other Register) {
for date := range other {
if _, ok := register[date]; !ok {