balances can accept delta pushes for FAST
This commit is contained in:
@@ -34,11 +34,10 @@ func main() {
|
||||
sort.Slice(deltas, func(i, j int) bool {
|
||||
return deltas[i].Debug() < deltas[j].Debug()
|
||||
})
|
||||
deltasSoFar := make(ledger.Deltas, 0)
|
||||
balancesSoFar := make(ledger.Balances)
|
||||
for i := range deltas {
|
||||
deltasSoFar = append(deltasSoFar, deltas[i])
|
||||
bal, _ := deltasSoFar.Like(ledger.LikeName("^" + deltas[i].Name + "$")).Balances()
|
||||
fmt.Printf("%s (%+v)\n", deltas[i].Debug(), bal[deltas[i].Name].Debug())
|
||||
balancesSoFar.Push(deltas[i])
|
||||
fmt.Printf("%s (%+v)\n", deltas[i].Debug(), balancesSoFar[deltas[i].Name].Debug())
|
||||
}
|
||||
case "bal":
|
||||
balances, err := deltas.Balances()
|
||||
|
||||
@@ -9,6 +9,20 @@ type Balances map[string]Balance
|
||||
|
||||
type Balance map[Currency]float64
|
||||
|
||||
func (balances Balances) Push(d Delta) {
|
||||
if _, ok := balances[d.Name]; !ok {
|
||||
balances[d.Name] = make(Balance)
|
||||
}
|
||||
balances[d.Name].Push(d)
|
||||
}
|
||||
|
||||
func (balance Balance) Push(d Delta) {
|
||||
if _, ok := balance[d.Currency]; !ok {
|
||||
balance[d.Currency] = 0
|
||||
}
|
||||
balance[d.Currency] += d.Value
|
||||
}
|
||||
|
||||
func (balances Balances) Debug() string {
|
||||
result := []string{}
|
||||
for k, v := range balances {
|
||||
|
||||
Reference in New Issue
Block a user