emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH 4/4] org-clock: make clock table respect `org-effort-duration


From: Jan Malakhovski
Subject: [O] [PATCH 4/4] org-clock: make clock table respect `org-effort-durations'
Date: Sun, 27 Dec 2015 15:13:49 +0000

* lisp/org-clock.el (org-clock-time%): Rewrite using 
(org-clocksum-string-to-minutes), document pitfalls.
(org-clock-time%-with-effort): New function.
(org-clocktable-write-default): Fix effort-duration parameter.
* doc/org.texi (The clock table): Update documentation.
---
 doc/org.texi      |  6 ++++++
 lisp/org-clock.el | 49 ++++++++++++++++++++++++++++---------------------
 2 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 92ec29a..c526057 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6687,6 +6687,7 @@ but you can specify your own function using the 
@code{:formatter} parameter.
              @r{As a special case, @samp{:formula %} adds a column with % 
time.}
              @r{If you do not specify a formula here, any existing formula}
              @r{below the clock table will survive updates and be evaluated.}
+:effort-durations @r{Name of a symbol to use as @code{org-effort-durations} 
when preparing the table.}
 :formatter   @r{A function to format clock data and insert it into the buffer.}
 @end example
 To get a clock summary of the current level 1 tree, for the current
@@ -6714,6 +6715,11 @@ A summary of the current subtree with % times would be
 #+BEGIN: clocktable :scope subtree :link t :formula %
 #+END: clocktable
 @end example
+The same thing measured in 8-hour work days would be
address@hidden
+#+BEGIN: clocktable :scope subtree :link t :formula % :effort-durations 
org-effort-durations-8h
+#+END: clocktable
address@hidden example
 A horizontally compact representation of everything clocked during last week
 would be
 @example
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index df993b0..53292ae 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2468,9 +2468,10 @@ from the dynamic block definition."
         (maxlevel (or (plist-get params :maxlevel) 3))
         (emph (plist-get params :emphasize))
         (level-p (plist-get params :level))
-        ;; FIXME: setting this will break `org-clock-time%'
-        (org-time-clocksum-use-effort-durations
-         (plist-get params :effort-durations))
+        (effort-durations (plist-get params :effort-durations))
+        (org-effort-durations (if (null effort-durations)
+                                  org-effort-durations
+                                  (eval effort-durations)))
         (timestamp (plist-get params :timestamp))
         (properties (plist-get params :properties))
         (ntcol (max 1 (or (plist-get params :tcolumns) 100)))
@@ -2641,8 +2642,11 @@ from the dynamic block definition."
                        (if timestamp 1 0)))
          (insert
           (format
-           "\n#+TBLFM: $%d='(org-clock-time%% @%d$%d $%d..$%d);%%.1f"
+           "\n#+TBLFM: $%d='(%s @%d$%d $%d..$%d);%%.1f"
            pcol            ; the column where the % numbers should go
+           (if (null effort-durations)
+               "org-clock-time%"
+               (format "org-clock-time%%-with-effort %s" (symbol-name 
effort-durations)))
            (if (and narrow (not narrow-cut-p)) 3 2) ; row of the total time
            tcol            ; column of the total time
            tcol (1- pcol)  ; range of columns where times can be found
@@ -2858,25 +2862,28 @@ TIME:      The sum of all time spend in this tree, in 
minutes.  This time
   "Compute a time fraction in percent.
 TOTAL s a time string like 10:21 specifying the total times.
 STRINGS is a list of strings that should be checked for a time.
+Strings are parsed using `org-clocksum-string-to-minutes'.
 The first string that does have a time will be used.
-This function is made for clock tables."
-  (let ((re "\\([0-9]+\\):\\([0-9]+\\)")
-       tot s)
-    (save-match-data
+
+This function is made for clock tables.
+
+This function can be broken by setting `org-time-clocksum-format'
+to something that `org-clocksum-string-to-minutes' can not
+parse."
+  (save-match-data
+    (let ((tot (org-clocksum-string-to-minutes total))
+          s cur)
       (catch 'exit
-       (if (not (string-match re total))
-           (throw 'exit 0.)
-         (setq tot (+ (string-to-number (match-string 2 total))
-                      (* 60 (string-to-number (match-string 1 total)))))
-         (if (= tot 0.) (throw 'exit 0.)))
-       (while (setq s (pop strings))
-         (if (string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
-             (throw 'exit
-                    (/ (* 100.0 (+ (string-to-number (match-string 2 s))
-                                   (* 60 (string-to-number
-                                          (match-string 1 s)))))
-                       tot))))
-       0))))
+       (if (= tot 0.) (throw 'exit 0.))
+       (dolist (s strings)
+         (setq cur (org-clocksum-string-to-minutes s))
+         (when cur (throw 'exit (/ (* 100.0 cur) tot))))
+       nil))))
+
+(defun org-clock-time%-with-effort (effort-durations total &rest strings)
+  "A version of `org-clock-time%' that temporary sets `org-effort-durations'."
+  (let ((org-effort-durations effort-durations))
+    (apply 'org-clock-time% total strings)))
 
 ;; Saving and loading the clock
 
-- 
2.6.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]