Add clocktable formatter to filter entries with small clocking time

Whenever I try to check what I actually in the past couple of days, I
try to use a clocktable for this.  However, those clocktables are
usually littered with small entries, i.e. entries where I only spent a
couple of minutes on (example: a quick chat with a colleague).  Those
entries clutter the view for the relevant entries, making it hard to
make sense of past activities.

Restricting the clocktable to a certain depth somehow helps, but major
single tasks are hidden this way, and I usually want to see those.

The custom formatter added in this commit tries to alleviate this
situation by providing a mechanism to filter out those entries using a
minimum clocktime threshold.  Let's see how this feature plays out.
This commit is contained in:
Daniel Borchmann 2024-08-17 16:07:17 +02:00
parent 3ccb13ce53
commit d01b3bdc09
No known key found for this signature in database
GPG Key ID: 784AA8DF0CCDF625
2 changed files with 26 additions and 0 deletions

View File

@ -548,6 +548,7 @@
db/org-cleanup-continuous-clocks
db/find-csv-in-org
db/org-mark-current-default-task
db/org-clocktable-write-with-threshold
db/export-diary
db/org-insert-checklist
db/org-copy-body-from-item-to-point

View File

@ -518,6 +518,31 @@ Work task and home task are determined by the current values of
(message "Setting default task to: %s" (org-link-display-format (org-entry-get (point) "ITEM")))
(org-clock-mark-default-task)))))
(defun db/org-clocktable-write-with-threshold (ipos tables params)
"A clocktable formatter to filter entries by minimal clock time.
The arguments IPOS, TABLES, and PARAMS are as for the default
clocktable formatter `org-clocktable-write-default'. The only
difference is that PARAMS may include an additional property
called `:clocktime-treshold' with a non-negative integer value.
If such a value is given, each table entry in TABLES whose TIME
value is below this threshold is removed before formatting the
clocktable (see `org-clock-get-table-data' for the meaning of
TIME)."
(let ((tables tables)) ; necessary?
(when-let ((threshold (plist-get params :clocktime-threshold)))
(unless (and (integerp threshold) (>= threshold 0))
(user-error "Clocktime threshold must be a non-negative integer, but is %s"
threshold))
(setq tables (-map (pcase-lambda (`(,file-name ,file-time ,entries))
(list file-name
file-time
(-filter (pcase-lambda (`(_ _ _ _ ,time _))
(>= time threshold))
entries)))
tables)))
(org-clocktable-write-default ipos tables params)))
;;; Workload Reports