new draw
parent
76f6cf1016
commit
49a77c5424
|
|
@ -1,41 +1,4 @@
|
|||
#! /bin/bash
|
||||
|
||||
cd "$(dirname "$(realpath "$BASH_SOURCE")")"
|
||||
|
||||
go run . \
|
||||
-json \
|
||||
-group-date ^20..-.. \
|
||||
-group-name '^[^:]*:[^:]*' \
|
||||
-like-name '(AssetAccount|Debts|Stock|Retirement)' \
|
||||
-foo reg \
|
||||
"$@" ./macro.d/* \
|
||||
| jq -c '.[] | {label: .name, x: .delta.Date, y: .balance[(.delta.Currency)], z: .delta.Currency}' \
|
||||
| grep '"z":"\$"' \
|
||||
| python3 -c '
|
||||
# line chart
|
||||
import matplotlib.pyplot as plt
|
||||
import json
|
||||
from sys import stdin
|
||||
|
||||
fig = plt.figure()
|
||||
plot = fig.add_subplot()
|
||||
|
||||
label_z_x_y = {}
|
||||
for line in stdin.readlines():
|
||||
if not line:
|
||||
continue
|
||||
d = json.loads(line)
|
||||
if not d["label"] in label_z_x_y:
|
||||
label_z_x_y[d["label"]] = {}
|
||||
if not d["z"] in label_z_x_y[d["label"]]:
|
||||
label_z_x_y[d["label"]][d["z"]] = {}
|
||||
label_z_x_y[d["label"]][d["z"]][d["x"]] = d["y"]
|
||||
for label in label_z_x_y:
|
||||
for z in label_z_x_y[label]:
|
||||
xs = sorted([i for i in label_z_x_y[label][z].keys()])
|
||||
ys = [label_z_x_y[label][z][x] for x in xs]
|
||||
plot.plot(xs, ys, label=f"{label} ({z})")
|
||||
|
||||
plot.legend()
|
||||
plt.show()
|
||||
'
|
||||
go run . -http=:8080 -foo reg -like-after 1023-08 -group-date ^....-.. -group-name '^[^:]*:[^:]*' -like-name '(AssetAccount|Stock|Retirement)' macro.d/*
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/go-echarts/go-echarts/charts"
|
||||
"gogs.inhome.blapointe.com/ana-ledger/ledger"
|
||||
"gogs.inhome.blapointe.com/local/gziphttp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -53,13 +54,15 @@ func main() {
|
|||
}
|
||||
|
||||
if *httpOutput != "" {
|
||||
deltas = deltas.Like(like...)
|
||||
switch *foo {
|
||||
case "reg":
|
||||
foo := func(w http.ResponseWriter, r *http.Request) {
|
||||
register := deltas.Like(like...).Register()
|
||||
|
||||
nameCurrencyDateValue := map[string]map[ledger.Currency]map[string]float64{}
|
||||
dates := []string{}
|
||||
for date, balances := range register {
|
||||
dates = append(dates, date)
|
||||
for name, balance := range balances {
|
||||
for currency, value := range balance {
|
||||
if _, ok := nameCurrencyDateValue[name]; !ok {
|
||||
|
|
@ -72,10 +75,23 @@ func main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if gziphttp.Can(r) {
|
||||
w = gziphttp.New(w)
|
||||
slices.Sort(dates)
|
||||
|
||||
line := charts.NewLine()
|
||||
line.AddXAxis(dates)
|
||||
for name, currencyDateValue := range nameCurrencyDateValue {
|
||||
for currency, dateValue := range currencyDateValue {
|
||||
series := make([]int, len(dates))
|
||||
for i, date := range dates {
|
||||
series[i] = int(dateValue[date])
|
||||
}
|
||||
key := fmt.Sprintf("%s (%s)", name, currency)
|
||||
line.AddYAxis(key, series)
|
||||
}
|
||||
}
|
||||
if err := line.Render(w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
json.NewEncoder(w).Encode(nameCurrencyDateValue)
|
||||
}
|
||||
log.Println("listening on", *httpOutput)
|
||||
if err := http.ListenAndServe(*httpOutput, http.HandlerFunc(foo)); err != nil {
|
||||
|
|
|
|||
1
go.mod
1
go.mod
|
|
@ -3,6 +3,7 @@ module gogs.inhome.blapointe.com/ana-ledger
|
|||
go 1.21.1
|
||||
|
||||
require (
|
||||
github.com/go-echarts/go-echarts v1.0.0 // indirect
|
||||
github.com/go-echarts/go-echarts/v2 v2.3.1 // indirect
|
||||
gogs.inhome.blapointe.com/local/gziphttp v0.0.0-20230508014052-4ccd700640fc // indirect
|
||||
)
|
||||
|
|
|
|||
13
go.sum
13
go.sum
|
|
@ -1,4 +1,17 @@
|
|||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-echarts/go-echarts v1.0.0 h1:n181E4iXwj4zrU9VYmdM2m8dyhERt2w9k9YhHqdp6A8=
|
||||
github.com/go-echarts/go-echarts v1.0.0/go.mod h1:qbmyAb/Rl1f2w7wKba1D4LoNq4U164yO4/wedFbcWyo=
|
||||
github.com/go-echarts/go-echarts/v2 v2.3.1 h1:Yw0HVjVTxpYm48l974dMjRzx8ni2ql0kKi/kawSgxFE=
|
||||
github.com/go-echarts/go-echarts/v2 v2.3.1/go.mod h1:56YlvzhW/a+du15f3S2qUGNDfKnFOeJSThBIrVFHDtI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
gogs.inhome.blapointe.com/local/gziphttp v0.0.0-20230508014052-4ccd700640fc h1:ayxolpOV9uIm8rGdmtz03d5JlnbSmFF8daKjmwrZZ1o=
|
||||
gogs.inhome.blapointe.com/local/gziphttp v0.0.0-20230508014052-4ccd700640fc/go.mod h1:Sdj/NB9h3xrzPDqViQAHoDhA5gmpHkrWRXUauvLSA74=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
|||
Loading…
Reference in New Issue