emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jan Malakhovski <oxij@oxij.org>
To: emacs-orgmode@gnu.org
Cc: Jan Malakhovski <oxij@oxij.org>
Subject: [PATCH 4/4] org-clock: make clock table respect `org-effort-durations'
Date: Sun, 27 Dec 2015 15:13:49 +0000	[thread overview]
Message-ID: <1451229229-18973-5-git-send-email-oxij@oxij.org> (raw)
In-Reply-To: <1451229229-18973-1-git-send-email-oxij@oxij.org>

* 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
+@example
+#+BEGIN: clocktable :scope subtree :link t :formula % :effort-durations org-effort-durations-8h
+#+END: clocktable
+@end 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

      parent reply	other threads:[~2015-12-27 15:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-27 15:13 [PATCH v3 part3 0/4] fixing org-clock-time% Jan Malakhovski
2015-12-27 15:13 ` [PATCH 1/4] org: move `org-duration-string-to-minutes' to a better place Jan Malakhovski
2015-12-27 15:13 ` [PATCH 2/4] rename `org-duration-string-to-minutes' to `org-clocksum-string-to-minutes' everywhere Jan Malakhovski
2015-12-27 15:13 ` [PATCH 3/4] simplify and document `org-effort-durations'-related code Jan Malakhovski
2015-12-27 15:13 ` Jan Malakhovski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1451229229-18973-5-git-send-email-oxij@oxij.org \
    --to=oxij@oxij.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).