From 297f05842d7bccfc2838cacbf75e0f6b8b7aa0a3 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 27 Jun 2023 17:56:09 -1000 Subject: [PATCH] ;examples: self-tracking --- examples/self-tracking/README.md | 116 +++++++++++++++++++++++++++++ examples/self-tracking/a.dat | 3 + examples/self-tracking/a.tsv | 3 + examples/self-tracking/b.dat | 3 + examples/self-tracking/c.tsv | 3 + examples/self-tracking/c.tsv.rules | 10 +++ 6 files changed, 138 insertions(+) create mode 100644 examples/self-tracking/README.md create mode 100644 examples/self-tracking/a.dat create mode 100644 examples/self-tracking/a.tsv create mode 100644 examples/self-tracking/b.dat create mode 100644 examples/self-tracking/c.tsv create mode 100644 examples/self-tracking/c.tsv.rules diff --git a/examples/self-tracking/README.md b/examples/self-tracking/README.md new file mode 100644 index 000000000..be82fa2d8 --- /dev/null +++ b/examples/self-tracking/README.md @@ -0,0 +1,116 @@ +Some examples of working with the https://www.gibney.org/a_syntax_for_self-tracking logging format +(discussion: https://news.ycombinator.com/item?id=36492033). + +If you have a.dat: + +``` +2020-05-28 18:41 Eat Pizza +2020-05-29 09:00 Slept with the window open +2020-05-29 09:00 Headaches +``` + +This is close enough to hledger's timedot format to do some reporting. +Each line is interpreted as an empty transaction: + +``` +$ hledger -f timedot:a.dat print +2020-05-28 * 18:41 Eat Pizza + +2020-05-29 * 09:00 Slept with the window open + +2020-05-29 * 09:00 Headaches + +``` + +And you could query those by date or description: + +``` +$ hledger -f timedot:a.dat print date:2020/5/28 +2020-05-28 * 18:41 Eat Pizza + +$ hledger -f timedot:a.dat print desc:eat +2020-05-28 * 18:41 Eat Pizza + +``` + +Or by tag, if you added tags like so: + +``` +2020-05-28 18:41 Eat Pizza ; food: +2020-05-29 09:00 Slept with the window open ; body:, sleep: +2020-05-29 09:00 Headaches ; body: +``` +``` +$ hledger -f timedot:b.dat print tag:sleep +2020-05-29 * 09:00 Slept with the window open ; body:, sleep: + +``` + +You could transform your format to a plain text accounting format with quantities. +Eg, make it TSV or CSV: + +``` +$ perl -pe '$c=0; $c++ while $c < 2 && s/ /\t/' a.dat > c.tsv +$ cat c.tsv +2020-05-28 18:41 Eat Pizza +2020-05-29 09:00 Slept with the window open +2020-05-29 09:00 Headaches +``` + +and use hledger CSV conversion rules to customise and enrich it: +``` +$ cat c.tsv.rules +fields date, time, description + +# save the time as a tag +comment time:%time + +# count each item as one "event" by default +account1 (events) +amount1 1 + +# special cases +if pizza + account1 (food) + amount1 200 cal +``` + +Now you have a (single entry) accounting journal: +``` +$ hledger -f c.tsv print + +2020-05-28 Eat Pizza ; time:18:41 + (food) 200 cal + +2020-05-29 Slept with the window open ; time:09:00 + (events) 1 + +2020-05-29 Headaches ; time:09:00 + (events) 1 + +``` + +Allowing quantity reports: +``` +$ hledger -f c.tsv balance -MATS cur:cal + +Balance changes in 2020-05: + + || May Total Average +======++=========================== + food || 200 cal 200 cal 200 cal +------++--------------------------- + || 200 cal 200 cal 200 cal +``` +``` +$ hledger -f c.tsv activity -D desc:headache +2020-05-28 +2020-05-29 * +``` +``` +$ hledger-bar -v -f c.tsv cur:cal +2020-05 200 ++ +``` +``` +$ hledger-ui --all -f c.tsv # explore with a TUI +``` diff --git a/examples/self-tracking/a.dat b/examples/self-tracking/a.dat new file mode 100644 index 000000000..6aa7c79c9 --- /dev/null +++ b/examples/self-tracking/a.dat @@ -0,0 +1,3 @@ +2020-05-28 18:41 Eat Pizza +2020-05-29 09:00 Slept with the window open +2020-05-29 09:00 Headaches diff --git a/examples/self-tracking/a.tsv b/examples/self-tracking/a.tsv new file mode 100644 index 000000000..e68873573 --- /dev/null +++ b/examples/self-tracking/a.tsv @@ -0,0 +1,3 @@ +2020-05-28 18:41 Eat Pizza +2020-05-29 09:00 Slept with the window open +2020-05-29 09:00 Headaches diff --git a/examples/self-tracking/b.dat b/examples/self-tracking/b.dat new file mode 100644 index 000000000..5366f22f1 --- /dev/null +++ b/examples/self-tracking/b.dat @@ -0,0 +1,3 @@ +2020-05-28 18:41 Eat Pizza ; food: +2020-05-29 09:00 Slept with the window open ; body:, sleep: +2020-05-29 09:00 Headaches ; body: diff --git a/examples/self-tracking/c.tsv b/examples/self-tracking/c.tsv new file mode 100644 index 000000000..e68873573 --- /dev/null +++ b/examples/self-tracking/c.tsv @@ -0,0 +1,3 @@ +2020-05-28 18:41 Eat Pizza +2020-05-29 09:00 Slept with the window open +2020-05-29 09:00 Headaches diff --git a/examples/self-tracking/c.tsv.rules b/examples/self-tracking/c.tsv.rules new file mode 100644 index 000000000..cfafafd34 --- /dev/null +++ b/examples/self-tracking/c.tsv.rules @@ -0,0 +1,10 @@ +fields date, time, description + +comment time:%time + +account1 (events) +amount1 1 + +if pizza + account1 (food) + amount1 200 cal