From d01b3bdc0935779d4dec4c559c8bff7c78ba40db Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 17 Aug 2024 16:07:17 +0200 Subject: [PATCH] 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. --- init.el | 1 + site-lisp/db-org.el | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/init.el b/init.el index d794866..876a351 100644 --- a/init.el +++ b/init.el @@ -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 diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 0563952..9895a18 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -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