emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Martin Becker <vbmazter@web.de>
To: Daimrod <daimrod@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] Smart inference of task progress when exporting to TJ3
Date: Fri, 03 May 2013 13:26:11 +0200	[thread overview]
Message-ID: <51839ED3.6070609@web.de> (raw)
In-Reply-To: <87r4hobgna.fsf@tanger.home>

[-- Attachment #1: Type: text/plain, Size: 771 bytes --]

Dear Daimrod,

Thank you for these remarks, next time I know.
I attached a "clean" patch.


On 03.05.2013 10:40, Daimrod wrote:
> Martin <vbmazter@web.de> writes:
>
> Hello Martin,
>
> Thanks for your patch. I will only make a few stylistic remarks.
>
> 1. Could you add `contrib/lisp/ox-taskjuggler.el:' to the subject? (The
>     first line of the commit message)
>     
> 2. IIUC you don't need the TINYCHANGE cookie because the changes are
>     made in contrib/ which doesn't require copyright assignment.
>     Furthermore, I don't think your changes could be considered `tiny'
>     (it changes more than 20 lines and doesn't look like a rewrite).
>
> 3. Could you reformat a bit your code so it fit in 80 column? (You can
>     often use M-q for the comments)
>


[-- Attachment #2: 0001-contrib-lisp-ox-taskjuggler.el-Smart-inference-of-ta.patch --]
[-- Type: text/x-patch, Size: 3700 bytes --]

From ec5076f93678a3ca5d0944cd777a0d87c74dfeee Mon Sep 17 00:00:00 2001
From: Martin Becker <vbmazter@web.de>
Date: Thu, 2 May 2013 23:08:40 +0200
Subject: [PATCH] contrib/lisp/ox-taskjuggler.el: Smart inference of task
 progress when exporting to TJ3

* contrib/lisp/ox-taskjuggler.el: Extend variable `complete' to respect clock times if
  no other information is given.

There are three possibilities for setting a task's progress when exporting to TJ3:
 1) If TODO state equals "done" => 100%
 2) If property "complete" is explicitly given => use that.
 3) Otherwise get the clocksum of the task and set the progress by comparing to
    `effort'.
---
 contrib/lisp/ox-taskjuggler.el |   36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/contrib/lisp/ox-taskjuggler.el b/contrib/lisp/ox-taskjuggler.el
index 3458e06..97c4aae 100644
--- a/contrib/lisp/ox-taskjuggler.el
+++ b/contrib/lisp/ox-taskjuggler.el
@@ -780,6 +780,17 @@ channel."
    ;; Closing report.
    "}\n"))
 
+
+(defun org-taskjuggler--clocksum-task (task)
+  "Return the clocksum of a parsed subtree => does not verify
+whether the parsed duration matches the start and end times"
+  (let* ((tsum 0))
+    (org-element-map (org-element-contents task) 'clock
+      (lambda (hl) (setq tsum (+ tsum (org-duration-string-to-minutes 
+	(org-element-property :duration hl))))))
+    tsum
+    ))
+
 (defun org-taskjuggler--build-task (task info)
   "Return a task declaration.
 
@@ -791,11 +802,28 @@ a property \"task_id\" it will be used as the id for this task.
 Otherwise it will use the ID property.  If neither is defined
 a unique id will be associated to it."
   (let* ((allocate (org-element-property :ALLOCATE task))
+         (effort (org-element-property :EFFORT task))
+         ;; smart completeness inference: 
+	 ;; - if state=done => 100% 
+	 ;; - if explicit property for "complete" => take that value 
+	 ;; - otherwise get clocksum of this task and relate to the
+         ;;   effort, whilst limiting values to [0,99] 
+	 ;; => 100% possible if and only if state=DONE. 
+         ;;    Overbooking does stop at 99%.
+         (complete-explicit (org-element-property :COMPLETE task))
          (complete
-          (if (eq (org-element-property :todo-type task) 'done) "100"
-            (org-element-property :COMPLETE task)))
+          ;; state=done => complete=100
+          (if (eq (org-element-property :todo-type task) 'done) 100.0
+            ;; else if explicit property => use that
+            (if complete-explicit (string-to-number complete-explicit)
+              ;; else guess the completeness from clocksum              
+              (let* ((clocked (org-taskjuggler--clocksum-task task))
+                     (complete-guess 
+		      (and effort (/ (* 100 clocked) 
+		       (org-duration-string-to-minutes effort)))))
+                (and complete-guess (max (min 99 complete-guess) 0)))
+	      )))
          (depends (org-taskjuggler-resolve-dependencies task info))
-         (effort (org-element-property :EFFORT task))
          (milestone
           (or (org-element-property :MILESTONE task)
               (not (or (org-element-map (org-element-contents task) 'headline
@@ -826,7 +854,7 @@ a unique id will be associated to it."
                   (if (>= org-taskjuggler-target-version 3.0) "allocate"
                     "allocations")
                   allocate))
-     (and complete (format "  complete %s\n" complete))
+     (and complete (format "  complete %.1f\n" complete))
      (and effort
           (format "  effort %s\n"
                   (let* ((minutes (org-duration-string-to-minutes effort))
-- 
1.7.9.5


  reply	other threads:[~2013-05-03 11:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-02 21:24 [PATCH] Smart inference of task progress when exporting to TJ3 Martin
2013-05-03  8:40 ` Daimrod
2013-05-03 11:26   ` Martin Becker [this message]
2013-05-03 15:08     ` Christian Egli
2013-05-03 17:05       ` Martin Becker
2013-05-03 20:25         ` Christian Egli
2013-05-03 23:06           ` Martin Becker
2013-05-07 10:08       ` Bastien
2013-05-07 10:57         ` Bastien

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=51839ED3.6070609@web.de \
    --to=vbmazter@web.de \
    --cc=daimrod@gmail.com \
    --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).