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; 5+ 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] 5+ 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; 5+ 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] 5+ messages in thread

* Re: support range durations
  2024-09-15 12:02 ` Ihor Radchenko
@ 2024-09-16  8:41   ` Guido Stevens
  2024-09-22  7:56     ` [BUG] Regression: org-duration fails to support duration ranges since Org 9.0.6 (was: support range durations) Ihor Radchenko
  0 siblings, 1 reply; 5+ 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] 5+ messages in thread

* [BUG] Regression: org-duration fails to support duration ranges since Org 9.0.6 (was: support range durations)
  2024-09-16  8:41   ` Guido Stevens
@ 2024-09-22  7:56     ` Ihor Radchenko
  2024-09-23 12:21       ` [BUG] Regression: org-duration fails to support duration ranges since Org 9.0.6 Guido Stevens
  0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2024-09-22  7:56 UTC (permalink / raw)
  To: Guido Stevens; +Cc: emacs-orgmode

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

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

At this point, using emacs -Q, I am getting

Debugger entered--Lisp error: (error "Invalid duration format: \"1d-2d\"")
  error("Invalid duration format: %S" "1d-2d")

In other words, such ranges are not supported in Effort property.

I am not sure what Doom does so that you are not getting that error.

> 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

I bisected the problem back to the initial introduction of org-duration
library. It simply does not support duration ranges.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=7e8cf5f4c202f51231d444f41735a4db06cb7052

The right thing appears to be implementing such support in org-duration.
However, it is not at all trivial, as the duration API in
org-duration.el is designed without ranges in mind.

> 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-duration-to-minutes is called and throws an error. Why is it even 
> called?

Agenda converts and stores duration in minutes as a part of calculating
metadata for agenda items. Your duration format cannot be converted to
minutes, leading to the error you are seeing.

My current conclusion is that we unfortunately got a regression since
Org 9.0.6. And it is not very easy to fix it without implementing
range durations across the whole codebase.

One possible "fix" could be making org-duration ignore ending estimate
in the duration ranges, but that's not ideal.

This is a difficult bug to address.

As a workaround, I suggest using some other property for your effort
estimates. Then, est+ summary in column view will work without errors.

-- 
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] 5+ messages in thread

* Re: [BUG] Regression: org-duration fails to support duration ranges since Org 9.0.6
  2024-09-22  7:56     ` [BUG] Regression: org-duration fails to support duration ranges since Org 9.0.6 (was: support range durations) Ihor Radchenko
@ 2024-09-23 12:21       ` Guido Stevens
  0 siblings, 0 replies; 5+ messages in thread
From: Guido Stevens @ 2024-09-23 12:21 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Thanks for looking into this, Ihor.

On 9/22/24 09:56, Ihor Radchenko wrote:
>> 2. Set estimate "1d-2d" on a task (C-c C-x e)
> 
> At this point, using emacs -Q, I am getting
> 
> Debugger entered--Lisp error: (error "Invalid duration format: \"1d-2d\"")
>    error("Invalid duration format: %S" "1d-2d")
> 
> In other words, such ranges are not supported in Effort property.
> 
> I am not sure what Doom does so that you are not getting that error.

My bad. Invalid reproduction. My local patch for org-duration-to-minutes 
must've been active when doing that, because org-duration-to-minutes is 
called by org-set-effort to validate the new input value.

> As a workaround, I suggest using some other property for your effort
> estimates. Then, est+ summary in column view will work without errors.

Thanks, I have done just that now.

-- 
     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] 5+ messages in thread

end of thread, other threads:[~2024-09-23 12:22 UTC | newest]

Thread overview: 5+ 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
2024-09-22  7:56     ` [BUG] Regression: org-duration fails to support duration ranges since Org 9.0.6 (was: support range durations) Ihor Radchenko
2024-09-23 12:21       ` [BUG] Regression: org-duration fails to support duration ranges since Org 9.0.6 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).