This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"math"
|
||||
"net/http"
|
||||
"os"
|
||||
"slices"
|
||||
@@ -99,17 +100,59 @@ func (router Router) APITransactions(w http.ResponseWriter, r *http.Request) {
|
||||
))
|
||||
recent := time.Hour * 24 * 365 / 6
|
||||
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"deltas": houseRelatedDeltas.
|
||||
Like(ledger.LikeAfter(time.Now().Add(-1 * recent).Format("2006-01"))),
|
||||
"balances": houseRelatedDeltas.Balances().
|
||||
normalizer := ana.NewNormalizer().
|
||||
With("^Zach:", "2023-10-05", 139). // to turtle
|
||||
With("^Zach:", "2021-12-30", 135). // at pluralsight
|
||||
With("^Zach:", "2020-07-30", 120). // to pluralsight
|
||||
With("^Zach:", "2019-07-16", 77). // at fedex
|
||||
With("^Zach:", "2017-02-16", 49). // to fedex
|
||||
With("^Bel:", "2023-12-05", 190). // to render
|
||||
With("^Bel:", "2022-12-31", 154). // at q
|
||||
With("^Bel:", "2022-06-30", 148). // at q
|
||||
With("^Bel:", "2021-12-31", 122). // at q
|
||||
With("^Bel:", "2020-12-31", 118). // at q
|
||||
With("^Bel:", "2019-12-31", 111). // at q
|
||||
With("^Bel:", "2018-12-31", 92). // at q
|
||||
With("^Bel:", "2018-02-16", 86) // to q
|
||||
|
||||
{
|
||||
deltas := houseRelatedDeltas.
|
||||
Like(ledger.LikeAfter(time.Now().Add(-1 * recent).Format("2006-01")))
|
||||
|
||||
balances := houseRelatedDeltas.Balances().
|
||||
Like(`^(Zach|Bel|House[^:]*:Debts:)`).
|
||||
Group(`^[^:]*`).
|
||||
WithBPIs(bpis),
|
||||
"transactions": houseRelatedDeltas.
|
||||
WithBPIs(bpis)
|
||||
|
||||
transactions := houseRelatedDeltas.
|
||||
Like(ledger.LikeAfter(time.Now().Add(-1 * recent).Format("2006-01"))).
|
||||
Transactions(),
|
||||
})
|
||||
Transactions()
|
||||
|
||||
normalized := normalizer.Normalize(houseRelatedDeltas).Balances().
|
||||
Like(`^(Zach|Bel):`).
|
||||
Group(`^[^:]*:`).
|
||||
WithBPIs(bpis)
|
||||
var biggest float64
|
||||
for _, v := range normalized {
|
||||
if v := math.Abs(v["$"]); v > biggest {
|
||||
biggest = v
|
||||
}
|
||||
}
|
||||
for k, v := range normalized {
|
||||
if v := math.Abs(v["$"]); v < biggest {
|
||||
normalizedDelta := biggest - v
|
||||
normalizedFactor := normalizer.NormalizeFactor(ledger.Delta{Name: k, Date: time.Now().Format("2006-01-02")})
|
||||
normalized[fmt.Sprintf(`(%s trailing $)`, k)] = ledger.Balance{"$": normalizedDelta * normalizedFactor}
|
||||
}
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"deltas": deltas,
|
||||
"balances": balances,
|
||||
"normalized": normalized,
|
||||
"transactions": transactions,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (router Router) APITrends(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user