emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [BUG] Error in data input and output format for org-columns--summary


From: Ihor Radchenko
Subject: Re: [BUG] Error in data input and output format for org-columns--summary-estimate
Date: Mon, 10 Jul 2023 08:57:36 +0000

andrea@fedeli.eu writes:

>    #+PROPERTY: Effort_ALL 0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00
>
>    #+COLUMNS: %30ITEM(Task) %30Effort(Estimated Effort){est+} %CLOCKSUM
>...
>    Originally produces
>    image.png
>    That shows that days and months are wrongly counted the same

Thanks!
Confirmed.

>    > The matter is related to the fact that org-columns--summary-estimate, 
> from org-colview.el, uses function string-to-number to take value on ranges; 
> acting this way

>   Both issues can be very simply addressed by adoption of 
> org-duration-to-minutes as
>
>   input adapted and org-duration-from-minutes as output adapter.
>   A similar concern affects also the simpler case of a single value instead 
> of a range (second pcase branch)

This will not be backwards-compatible.
Some people may abuse this summary type to count something that is not
time, like cost.

We rather need something like the attached diff.
However, this will use `org-duration-format', which may not always be
desirable - the default value will force days even when all the estimates
are months:

3m
3m-4m
---
180d 0:00 - 210d 0:00

diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 7aa5ef645..da9a11104 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -1345,18 +1345,32 @@ (defun org-columns--summary-estimate (estimates _)
 The mean and variance of the result will be the sum of the means
 and variances (respectively) of the individual estimates."
   (let ((mean 0)
-        (var 0))
+        (var 0)
+        (durationp
+         (catch :no-match
+           (dolist (e estimates)
+             (dolist (val (split-string e "-"))
+               (unless (org-duration-p val) (throw :no-match nil))))
+           'all-values-are-durations)))
     (dolist (e estimates)
-      (pcase (mapcar #'string-to-number (split-string e "-"))
+      (pcase (mapcar
+              (if durationp
+                  #'org-duration-to-minutes
+                #'string-to-number)
+              (split-string e "-"))
        (`(,low ,high)
         (let ((m (/ (+ low high) 2.0)))
           (cl-incf mean m)
           (cl-incf var (- (/ (+ (* low low) (* high high)) 2.0) (* m m)))))
        (`(,value) (cl-incf mean value))))
     (let ((sd (sqrt var)))
-      (format "%s-%s"
-             (format "%.0f" (- mean sd))
-             (format "%.0f" (+ mean sd))))))
+      (if durationp
+          (format "%s - %s"
+                  (org-duration-from-minutes (- mean sd))
+                  (org-duration-from-minutes (+ mean sd)))
+        (format "%s-%s"
+               (format "%.0f" (- mean sd))
+               (format "%.0f" (+ mean sd)))))))
 
 
 
-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

reply via email to

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