new draw
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user