emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* support range durations
@ 2024-09-11 12:01 Guido Stevens
  2024-09-15 12:02 ` Ihor Radchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Guido Stevens @ 2024-09-11 12:01 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi all,

I'm new to this list and joined in order to submit the attached tiny patch.

As per https://orgmode.org/manual/Column-attributes.html I'm using range 
durations to express effort estimations. Those get summarized nicely in 
column views, using the {est+} summarizer. But when I access an agenda 
view that encounters a task that has such a range duration directly set, 
the agenda chokes with an error message:

	org-duration-to-minutes: Invalid duration format: "1d-2d"

Attached patch fixes that error, by

1. Just before throwing that error, checking if this is potentially a 
range duration, of two durations separated by a "-"

2. If so, split the range into two separate <low> and <high> durations, 
convert each of those to minutes, and take the average.

The patch doesn't use a fancy regexp. Instead, it recurses into 
org-duration-to-minutes and reapplies all sanity checks on the 
constituent low/high durations. If you have two valid durations 
connected by a dash (and optionally whitespace), that's a valid range 
duration, and it will be expressed as a float. If not, you'll hit the 
error fallback directly below.

Applying this patch fixes my agenda view when using range durations. 
Since the actual code change is just 2 lines, I opted to forego the FSF 
copyright assignment caroussel by marking this a TINYCHANGE.

Patch is based off e269942a353965dd8bdad57741adc9c53116a08a which is my 
current Doom Emacs checkout of 
https://github.com/emacs-straight/org-mode. I hope that's fine.

Kind regards, Guido.
-- 
     Guido Stevens    |   Cosent   |     https://cosent.nl

     s o c i a l   k n o w l e d g e   t e c h n o l o g y

[-- Attachment #2: 0001-lisp-org-duration.el-support-range-durations.patch --]
[-- Type: text/x-patch, Size: 1544 bytes --]

From 772ca4c915a629a62be0b5ee64005a929bf1bf04 Mon Sep 17 00:00:00 2001
From: "Guido A.J. Stevens" <guido.stevens@cosent.nl>
Date: Wed, 11 Sep 2024 13:24:58 +0200
Subject: [PATCH] lisp/org-duration.el: support range durations

* lisp/org-duration.el (org-duration-to-minutes): Do not choke on
low-high range durations (e.g. "2d-5d") when rendering an agenda. Calculate the average
of the range instead.

Range durations are valid when estimating effort, and supported
elsewhere via the {est+} summarizer.

TINYCHANGE
---
 lisp/org-duration.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/org-duration.el b/lisp/org-duration.el
index 662a94bd5..46771a355 100644
--- a/lisp/org-duration.el
+++ b/lisp/org-duration.el
@@ -283,7 +283,7 @@ When optional argument CANONICAL is non-nil, ignore
 `org-duration-units' and use standard time units value.
 
 A bare number is translated into minutes.  The empty string is
-translated into 0.0.
+translated into 0.0. A low - high range duration is averaged.
 
 Return value as a float.  Raise an error if duration format is
 not recognized."
@@ -311,6 +311,8 @@ not recognized."
 	   (org-duration-to-minutes hms-part))))
      ((string-match-p "\\`[0-9]+\\(\\.[0-9]*\\)?\\'" duration)
       (float (string-to-number duration)))
+     ((string-match-p "-" duration)
+      (pcase-let ((`(,low ,high) (mapcar #'org-duration-to-minutes (split-string duration "-")))) (/ (+ low high) 2)))
      (t (error "Invalid duration format: %S" duration)))))
 
 ;;;###autoload
-- 
2.43.0


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

* Re: support range durations
  2024-09-11 12:01 support range durations Guido Stevens
@ 2024-09-15 12:02 ` Ihor Radchenko
  2024-09-16  8:41   ` Guido Stevens
  0 siblings, 1 reply; 3+ messages in thread
From: Ihor Radchenko @ 2024-09-15 12:02 UTC (permalink / raw)
  To: Guido Stevens; +Cc: emacs-orgmode

Guido Stevens <guido.stevens@cosent.net> writes:

> As per https://orgmode.org/manual/Column-attributes.html I'm using range 
> durations to express effort estimations. Those get summarized nicely in 
> column views, using the {est+} summarizer. But when I access an agenda 
> view that encounters a task that has such a range duration directly set, 
> the agenda chokes with an error message:
>
> 	org-duration-to-minutes: Invalid duration format: "1d-2d"

May you please provide more details on how to trigger the error?

> ...
> * lisp/org-duration.el (org-duration-to-minutes): Do not choke on
> low-high range durations (e.g. "2d-5d") when rendering an agenda. Calculate the average
> of the range instead.
>
> Range durations are valid when estimating effort, and supported
> elsewhere via the {est+} summarizer.

Org mode durations have no notion of ranges. It is completely
org-colview thing. So, modifying `org-duration-to-minutes' is not
appropriate. We need to fix org-colview, not org-duration.

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


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

* Re: support range durations
  2024-09-15 12:02 ` Ihor Radchenko
@ 2024-09-16  8:41   ` Guido Stevens
  0 siblings, 0 replies; 3+ messages in thread
From: Guido Stevens @ 2024-09-16  8:41 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

On 9/15/24 14:02, Ihor Radchenko wrote:
> Guido Stevens <guido.stevens@cosent.net> writes:
> 
>> As per https://orgmode.org/manual/Column-attributes.html I'm using range
>> durations to express effort estimations. Those get summarized nicely in
>> column views, using the {est+} summarizer. But when I access an agenda
>> view that encounters a task that has such a range duration directly set,
>> the agenda chokes with an error message:
>>
>> 	org-duration-to-minutes: Invalid duration format: "1d-2d"
> 
> May you please provide more details on how to trigger the error?

Sure. I'm providing the Doom keybindings for the actions I'm taking.

1. Abbreviated snippet from my Doom config:

(use-package! org
   :defer t
   (setq!
    org-global-properties
    `(("Effort_ALL" . "0 0.5d 0.5d-1d 1d 1d-2d"))))

2. Set estimate "1d-2d" on a task (C-c C-x e)

3. Open an agenda view that contains that task (C-c n a t)

org-duration-to-minutes: Invalid duration format: "1d-2d"


> 
>> ...
>> * lisp/org-duration.el (org-duration-to-minutes): Do not choke on
>> low-high range durations (e.g. "2d-5d") when rendering an agenda. Calculate the average
>> of the range instead.
>>
>> Range durations are valid when estimating effort, and supported
>> elsewhere via the {est+} summarizer.
> 
> Org mode durations have no notion of ranges. It is completely
> org-colview thing. So, modifying `org-duration-to-minutes' is not
> appropriate. We need to fix org-colview, not org-duration.
> 

The reproduction above does not involve org-colview.

The disagreement apparently is, that org-colview says range durations 
are supported for effort estimates, and even has code handling them via 
the {est+} summarizer, when they are not supported in org-duration.

https://github.com/emacs-mirror/emacs/blob/f27553c30a772a0103d2e6762e4d7f588f302e4b/lisp/org/org-colview.el#L1419

I get your point about not accepting this patch. None of the other 
functions or docstrings in org-duration mentions or handles ranges, fair 
enough.

I'm puzzled though, because I did not come up with this feature. It's 
genuinely useful and it appears to have worked in the past.
https://lists.gnu.org/archive/html/emacs-orgmode/2014-12/msg00435.html

Maybe sorting agenda views by effort was not active at that stage: I 
suspect that is what is triggering the error. Which points to a 
potential solution (and also to a potential speed optimization): even 
when I am not sorting on effort at all, this error is thrown, so why is 
org-duration-to-minutes even called at all in the agenda view? Is there 
a way to disable that?

I.e. even when I simplify my sorting strategy to:

    org-agenda-sorting-strategy
    '((agenda priority-down)
      (todo priority-down)
      (tags priority down)
      (search priority-down))
    )

org-duration-to-minutes is called and throws an error. Why is it even 
called?

I'm out of my depth in Lisp and don't know how to properly step that 
call flow.


-- 
     Guido Stevens    |   Cosent   |     https://cosent.nl

     s o c i a l   k n o w l e d g e   t e c h n o l o g y


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

end of thread, other threads:[~2024-09-16  8:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-11 12:01 support range durations Guido Stevens
2024-09-15 12:02 ` Ihor Radchenko
2024-09-16  8:41   ` Guido Stevens

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