Refactor and tweak output of Chronometrist query

This commit is contained in:
contrapunctus 2022-02-06 17:35:16 +05:30
parent 5fd4be9f85
commit 68d7aee35c
1 changed files with 9 additions and 6 deletions

View File

@ -2441,6 +2441,7 @@ What if...
An example of querying the Chronometrist file data - finding out how much time I've spent on tasks matching a certain criteria.
#+BEGIN_SRC emacs-lisp :tangle no :load no
;; XXX - day count is incorrect
(cl-loop for plist in (chronometrist-to-list (chronometrist-active-backend))
with count = 0
when (and (equal (plist-get plist :name) "Composing")
@ -2470,8 +2471,9 @@ An example of querying the Chronometrist file data - finding out how much time I
**** Unique key-values for task "Exercise"
#+BEGIN_SRC emacs-lisp :tangle no :load no
(cl-loop for plist in (chronometrist-to-list (chronometrist-active-backend))
when (equal (plist-get plist :name) "Exercise")
(cl-loop with task = "Exercise"
for plist in (chronometrist-to-list (chronometrist-active-backend))
when (equal (plist-get plist :name) task)
collect (chronometrist-plist-key-values plist) into key-values
finally do
(let ((buffer (get-buffer-create (generate-new-buffer-name "chronometrist-query"))))
@ -2507,15 +2509,16 @@ An example of querying the Chronometrist file data - finding out how much time I
(distance-int (car distance))
(distance-km (/ (float distance-int) 1000))
(duration-hours (/ (float duration-seconds) 60 60))
(distance-string (format "%s %s" distance-int (cdr distance))))
(format "%s%s in %s (%s)\n"
(distance-string (format "% 4s %s" distance-int (cdr distance)))
(speed-string (format "%.2f" (/ distance-km duration-hours))))
(format "%s%s in %s (% 5s kmph)\n"
(if (not first-line)
(make-string (+ 3 (length date-iso)) ?\s)
(setq first-line nil)
(concat date-iso " - "))
distance-string
(ts-human-format-duration duration-seconds)
(format "%.2f kmph" (/ distance-km duration-hours)))))
(format-seconds "%m:%02s" duration-seconds)
speed-string)))
collect it into lists
;; Add indices for each date, and indentation when there are >1
;; instances of running in a date