emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: andrea@fedeli.eu
Cc: emacs-orgmode@gnu.org
Subject: Re: [BUG] Error in data input and output format for org-columns--summary-estimate
Date: Mon, 10 Jul 2023 08:57:36 +0000	[thread overview]
Message-ID: <87ilas6t4v.fsf@localhost> (raw)
In-Reply-To: <RXJ9RW$A3C3D79D027C4334488CC937B6873333@fedeli.eu>

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

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-columns-est.diff --]
[-- Type: text/x-patch, Size: 1487 bytes --]

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)))))))
 
 
 \f

[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
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	other threads:[~2023-07-10  8:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-09 12:46 [BUG] Error in data input and output format for org-columns--summary-estimate andrea
2023-07-09 14:17 ` Ihor Radchenko
2023-07-09 14:33   ` andrea
2023-07-10  8:57     ` Ihor Radchenko [this message]
     [not found]       ` <RXR2XJ$F3602788F3665C159BAF986799B1995C@fedeli.eu>
2023-07-14  9:02         ` Ihor Radchenko
2023-07-14 11:39           ` andrea
2023-07-18  9:10             ` Ihor Radchenko
2023-08-15 15:53               ` andrea
2023-08-16 10:15                 ` Ihor Radchenko
2023-08-18  6:20                   ` andrea
2023-08-18  9:29                     ` Ihor Radchenko

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=87ilas6t4v.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=andrea@fedeli.eu \
    --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).