/api/trends has PIES
cicd / ci (push) Successful in 1m36s
Details
cicd / ci (push) Successful in 1m36s
Details
parent
6be00d6423
commit
6df7171057
|
|
@ -124,12 +124,14 @@ func (router Router) APITrends(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
recent := time.Hour * 24 * 365 / 2
|
||||
|
||||
pie := func(title, groupName string, min int) {
|
||||
recentHouseRelatedDeltas := deltas.
|
||||
Like(ledger.LikeTransactions(
|
||||
deltas.Like(ledger.LikeName(`^House`))...,
|
||||
)).
|
||||
Like(ledger.LikeAfter(time.Now().Add(-1 * recent).Format("2006-01"))).
|
||||
Group(ledger.GroupName(`Withdrawal:[0-9]*:[^:]*`)).
|
||||
Group(ledger.GroupName(groupName)).
|
||||
Group(ledger.GroupDate(`^[0-9]*-[0-9]*`)).
|
||||
Like(ledger.LikeNotName(`^$`))
|
||||
|
||||
|
|
@ -160,16 +162,21 @@ func (router Router) APITrends(w http.ResponseWriter, r *http.Request) {
|
|||
slices.Sort(month)
|
||||
median := month[len(month)/2]
|
||||
ttl += median
|
||||
if median > 50 {
|
||||
if median > min {
|
||||
chart.AddY(cat, []int{median})
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(w, "<!DOCTYPE html><h2>Median Spending ($", ttl, ")</h2>")
|
||||
fmt.Fprintln(w, "<!DOCTYPE html><h2>", title, "($", ttl, ")</h2>")
|
||||
if err := chart.Render(w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
pie("Median Spending", `Withdrawal:[0-9]*`, 50)
|
||||
pie("Median Spending (detailed)", `Withdrawal:[0-9]*:[^:]*`, 25)
|
||||
pie("Median Spending (MORE detailed)", `Withdrawal:[0-9]*:[^:]*:[^:]*`, 10)
|
||||
}
|
||||
|
||||
func (router Router) APIAmend(w http.ResponseWriter, r *http.Request) {
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue