Rudolf Adamkovič Personal site


Exercise log

The log is modeled as the function

\[\begin{equation*}
  f : D \to T,
\end{equation*}
\]
where\(d \in D\)is the exercise day,
measured in \(24\)-hour days from the Unix epoch; and
\(t > 0 \in T\)is the total exercise duration on day \(d\),
measured in seconds.

\(f\) is computed, as a hash table, from Org Clock data by

(defun my-exercise-log ()
  "Return a hash map with exercise durations per day."
  (let ((lexical-binding t))
    (save-excursion
      (org-id-goto my-exercise-id)
      (goto-char (org-log-beginning))
      (named-let recur ((days (make-hash-table :test 'equal)))
        (let ((element (org-element-at-point-no-context)))
          (if (eq 'clock (org-element-type element))
              (let* ((day (org-element-property :value element))
                     (day (org-format-timestamp day "%s"))
                     (day (string-to-number day))
                     (day (/ (float day) 60 60 24))
                     (time (org-element-property :duration element))
                     (time (org-duration-to-minutes time))
                     (time (* time 60)))
                (puthash day (+ (gethash day days 0) time) days)
                (org-forward-element)
                (recur days))
            days))))))

where the ‘my-exercise-id’ is

(defcustom my-exercise-id "0DB14413-C66D-41F6-A6C0-17F433F0B740"
  "ID of the Org heading on which all exercises are clocked.")

© 2024 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and the secret alien technologies of yesteryear.