From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin Subject: [PATCH] Smart inference of task progress when exporting to TJ3 Date: Thu, 02 May 2013 23:24:57 +0200 Message-ID: <0LlWCR-1TzVer28MZ-00b7Lb@smtp.web.de> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: Received: from eggs.gnu.org ([208.118.235.92]:51122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UY14p-0003PD-SM for emacs-orgmode@gnu.org; Thu, 02 May 2013 17:30:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UY14m-00086b-Tk for emacs-orgmode@gnu.org; Thu, 02 May 2013 17:30:07 -0400 Received: from mout.web.de ([212.227.15.4]:53752) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UY14m-00083f-Li for emacs-orgmode@gnu.org; Thu, 02 May 2013 17:30:04 -0400 Received: from HyperZal.web.de ([93.135.70.242]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0Lk8ko-1U0K4S1WXK-00cTr8 for ; Thu, 02 May 2013 23:25:02 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org * 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'. TINYCHANGE --- contrib/lisp/ox-taskjuggler.el | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/contrib/lisp/ox-taskjuggler.el b/contrib/lisp/ox-taskjuggler.el index 3458e06..a97c075 100644 --- a/contrib/lisp/ox-taskjuggler.el +++ b/contrib/lisp/ox-taskjuggler.el @@ -780,6 +780,16 @@ 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 +801,24 @@ 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))) ;; check ranges and don't set complete=100 until state=DONE + ))) (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 +849,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