emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-clock.el: clocktable ':formula %' now includes per-file time pct
@ 2021-01-31 21:49 Alan D. Salewski
  2021-05-01  9:52 ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Alan D. Salewski @ 2021-01-31 21:49 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Alan D. Salewski

* lisp/org-clock.el (org-clocktable-write-default): When ':formula %'
  is in-effect, show the per-file time percentage in the '%' column.

This change only has an effect when multiple files are contributing
to a given clocktable (such as when ':scope agenda' has been
specified).  The existing behavior is that such tables have an extra
'File' column, and each individual file that contributes has its own
summary line with the headline value '*File time*'.  Those summary
rows also produce a rollup time value for the file in the 'Time'
column.

Prior to this change, the built-in '%' formula does not produce a
calculation for those per-file times in the '%' column (the relevant
cells in the '%' column were blank).  With this change, the
percentage contribution of each individual file time to the total
time is shown.

The more agenda files you have, the more useful this behavior
becomes.

TINYCHANGE

Signed-off-by: Alan D. Salewski <ads@salewski.email>
---
 lisp/org-clock.el | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index cfd112ec3..8e91609c2 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2697,7 +2697,18 @@ from the dynamic block definition."
 	     (format (concat "| %s %s | %s%s%s"
 			     (format org-clock-file-time-cell-format
 				     (org-clock--translate "File time" lang))
-			     " | *%s*|\n")
+
+			     ;; The file-time rollup value goes in the first time
+			     ;; column (of which there is always at least one)...
+			     " | *%s*|"
+			     ;; ...and the remaining file time cols (if any) are blank.
+			     (make-string (max 0 (1- time-columns)) ?|)
+
+			     ;; Optionally show the percentage contribution of "this"
+			     ;; file time to the total time.
+			     (if (eq formula '%) " %s |" "")
+			     "\n")
+
 		     (file-name-nondirectory file-name)
 		     (if level?    "| " "") ;level column, maybe
 		     (if timestamp "| " "") ;timestamp column, maybe
@@ -2705,7 +2716,12 @@ from the dynamic block definition."
 		     (if properties	    ;properties columns, maybe
 			 (make-string (length properties) ?|)
 		       "")
-		     (org-duration-from-minutes file-time)))) ;time
+		     (org-duration-from-minutes file-time) ;time
+
+		     (cond ((not (eq formula '%)) "")	   ;time percentage, maybe
+			   ((or (not total-time) (= total-time 0)) "0.0")
+			   (t
+			    (format "%.1f" (* 100 (/ file-time (float total-time)))))))))
 
 	  ;; Get the list of node entries and iterate over it
 	  (when (> maxlevel 0)
-- 
a l a n   d.   s a l e w s k i
ads@salewski.email
salewski@att.net
https://github.com/salewski


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] org-clock.el: clocktable ':formula %' now includes per-file time pct
  2021-01-31 21:49 [PATCH] org-clock.el: clocktable ':formula %' now includes per-file time pct Alan D. Salewski
@ 2021-05-01  9:52 ` Bastien
  2021-05-01 14:43   ` [PATCH] etc/ORG-NEWS: Announce clocktable per-file time percentages (':formula %') Alan D. Salewski
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien @ 2021-05-01  9:52 UTC (permalink / raw)
  To: Alan D. Salewski; +Cc: Alan D. Salewski, emacs-orgmode

Hi Alan,

applied in master as commit 9aa9f3b1f.

Thanks you very much!

Can you announce this by providing a patch for etc/ORG-NEWS?

-- 
 Bastien


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] etc/ORG-NEWS: Announce clocktable per-file time percentages (':formula %')
  2021-05-01  9:52 ` Bastien
@ 2021-05-01 14:43   ` Alan D. Salewski
  2021-05-01 14:56     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Alan D. Salewski @ 2021-05-01 14:43 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode mailing list

On Sat, May 1, 2021, at 05:52, Bastien wrote:
> Hi Alan,
> 
> applied in master as commit 9aa9f3b1f.
> 
> Thanks you very much!

Great, and thank /you/ for all the work you do on org-mode!


> Can you announce this by providing a patch for etc/ORG-NEWS?
> 
> -- 
>  Bastien

Sure thing; included below.

----8<----

* etc/ORG-NEWS: New entry announcing clocktable calculation and
display of per-file time percentages, when ':formula %' is used.

TINYCHANGE

Signed-off-by: Alan D. Salewski <ads@salewski.email>
---
 etc/ORG-NEWS | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 0c822d029..d08e3f68f 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -235,6 +235,23 @@ tags including from both buffer local and user defined persistent
 global list (~org-tag-alist~ and ~org-tag-persistent-alist~).  Now
 option ~org-complete-tags-always-offer-all-agenda-tags~ is honored.
 
+*** Clocktable option =:formula %= now shows the per-file time percentages
+
+This change only has an effect when multiple files are contributing to
+a given clocktable (such as when =:scope agenda= has been specified).
+The existing behavior is that such tables have an extra 'File' column,
+and each individual file that contributes has its own summary line
+with the headline value '*File time*'.  Those summary rows also
+produce a rollup time value for the file in the 'Time' column.
+
+Prior to this change, the built-in =%= formula did not produce a
+calculation for those per-file times in the '%' column (the relevant
+cells in the '%' column were blank).  With this change, the
+percentage contribution of each individual file time to the total
+time is shown.
+
+The more agenda files you have, the more useful this behavior becomes.
+
 ** Miscellaneous
 *** Missing or empty placeholders in "eval" macros are now nil
 They used to be the empty string.

-- 
a l a n   d.   s a l e w s k i
ads@salewski.email
salewski@att.net
https://github.com/salewski


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] etc/ORG-NEWS: Announce clocktable per-file time percentages (':formula %')
  2021-05-01 14:43   ` [PATCH] etc/ORG-NEWS: Announce clocktable per-file time percentages (':formula %') Alan D. Salewski
@ 2021-05-01 14:56     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2021-05-01 14:56 UTC (permalink / raw)
  To: Alan D. Salewski; +Cc: emacs-orgmode mailing list

Hi Alan,

"Alan D. Salewski" <ads@salewski.email> writes:

> Sure thing; included below.

Applied in master as commit a2403321a, thanks!

-- 
 Bastien


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-01 14:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-31 21:49 [PATCH] org-clock.el: clocktable ':formula %' now includes per-file time pct Alan D. Salewski
2021-05-01  9:52 ` Bastien
2021-05-01 14:43   ` [PATCH] etc/ORG-NEWS: Announce clocktable per-file time percentages (':formula %') Alan D. Salewski
2021-05-01 14:56     ` Bastien

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).