org-mode: creation time range from effort estimate
Asked Answered
P

2

6

I would like to use org-mode not with a GTD-like system but rather as a planner/scheduler, scheduling/timestamping every captured task on capture or refile. In such a system, detailed planning of a day including specific frames of times according to the estimated duration a task will take to get done, might be advantageous.

Would it be possible to generate a time frame from an existing effort estimate property when a timestamp is created? This would mean that, when a) scheduling is called and b) I enter not only a date but also a time and c) an effort property exists, this time will automatically be turned into a time frame according to said property.

Some hints as to how this could be achieved would be more than enough, I just do not know enough elisp to get started.

Edit

after capturing the task in my refile.org would look like this:

* TODO Sample todo
 :PROPERTIES:
 :Effort:   1h
 :END:

now when refiling I look at it and decide that I will do it, say, on Friday at 10am:

* TODO Sample todo
  SCHEDULED: <2014-04-18 Fr 10:00>
  :PROPERTIES:
  :Effort:   1h
  :END:

the function that could be called now would automatically add a time range according to effort estimate:

* TODO Sample todo
 SCHEDULED: <2014-04-18 Fr 10:00-11:00>
 :PROPERTIES:
 :Effort:   1h
 :END:

Edit2

See lawlists accepted answer below for a robust solution

Piave answered 13/4, 2014 at 15:29 Comment(4)
If you could post a sample of how the end result will look, it would be easier for someone here to write it up in elisp format. Otherwise, someone will do a draft and then you may ask for revisions . . . because it wasn't exactly clear what the end result will look like.Penuche
I am very sorry for being unclear and thank you for pointing that out. let me try:Moderation
It is now crystal clear -- thank you.Penuche
The effort property drawer example in the org-mode documentation looks like this (setq org-global-properties '(("Effort_ALL". "0 0:10 0:30 1:00 2:00 3:00 4:00"))). If we use 1h, then we need a transform function like (car (split-string "1h" "h")) If we use minutes (e.g., "15m"), then we need a different transform function like (car (split-string "15m" "m")). Can you please give me a link to the org-mode documentation that supports the effort format of h and m, or provide a list of all formats that you anticipate using. Alternatively, you could use the first method (above).Penuche
P
9

To add a scheduled timestamp, use: M-x org-schedule

To add effort as a range to an existing timestamp, using the standard effort format (e.g., "0 0:10 0:30 1:00 2:00 3:00 4:00") [see http://orgmode.org/manual/Filtering_002flimiting-agenda-items.html ], the following function should do the job. NOTE org-mode version 7 uses all lowercase for the org-element-property property drawer, whereas org-mode version 8 uses all capitals -- e.g., (org-element-property :EFFORT (org-element-at-point))


org-schedule-effort was tested with org-mode version 8.2.5.c using the following example task -- not using h or m for effort. Emacs rounds 00 01 02 03 04 05 06 07 08 09 to 0 1 2 3 4 5 6 7 8 9 and timestamp format requires the former -- therefore, we need to concatenate a 0 to the beginning if less than 10.

* TODO Sample todo
  SCHEDULED: <2014-04-18 Fr 10:00>
  :PROPERTIES:
  :Effort:  1:15
  :END:

(defun org-schedule-effort ()
(interactive)
  (save-excursion
    (org-back-to-heading t)
    (let* (
        (element (org-element-at-point))
        (effort (org-element-property :EFFORT element))
        (scheduled (org-element-property :scheduled element))
        (ts-year-start (org-element-property :year-start scheduled))
        (ts-month-start (org-element-property :month-start scheduled))
        (ts-day-start (org-element-property :day-start scheduled))
        (ts-hour-start (org-element-property :hour-start scheduled))
        (ts-minute-start (org-element-property :minute-start scheduled)) )
      (org-schedule nil (concat
        (format "%s" ts-year-start)
        "-"
        (if (< ts-month-start 10)
          (concat "0" (format "%s" ts-month-start))
          (format "%s" ts-month-start))
        "-"
        (if (< ts-day-start 10)
          (concat "0" (format "%s" ts-day-start))
          (format "%s" ts-day-start))
        " "
        (if (< ts-hour-start 10)
          (concat "0" (format "%s" ts-hour-start))
          (format "%s" ts-hour-start))
        ":"
        (if (< ts-minute-start 10)
          (concat "0" (format "%s" ts-minute-start))
          (format "%s" ts-minute-start))
        "+"
        effort)) )))
Penuche answered 14/4, 2014 at 18:2 Comment(9)
Thank you very much, this definitely is a start! However, I cannot get this to work for some reason. Tried also with a clean emacs -Q (24.4). Org-version is 8.2.5c. When I call the function with point on the sample todo (or any other todo), the time is removed completely and the scheduled date is set to 2014-04-15. This was independent of the date and time of the tasks I tried. Might this have something todo with the system language/date format being german?Moderation
I'll work on it some more during the day and repost the revised function -- sorry for the inconvenience.Penuche
it is not an inconvenience! thank you for helping - I hope I am not the only one for whom such a thing might be useful. tried in a virtual machine with everything set to en_US - same outcome. cf also my pathetic attempt to add to your function above.Moderation
@Piave -- I have revised the function -- adding additional fields year, month and day -- I updated all fields (except year) to concatenate a "0" to the front if less than 10. Emacs automatically knows to add < and > to the ends of the timestamp, and it also calculates the correct day of the week.Penuche
That works very well now. Thank you so much. I will play around with it and try to expand (an advice for org-schedule to automatically check if a time has been scheduled and an effort has been set and call your function; making it work with the agenda buffer) and report back.Moderation
I'm glad we got it working. If you need a new function for org-agenda that is based on this function, go ahead and give it a try yourself first -- if you get stuck and need help, post a new question along with a link to this question (like this https://mcmap.net/q/1693959/-org-mode-creation-time-range-from-effort-estimate ) so that others can easily see where you've been and where you're going. Many org-agenda functions jump back to the original org-mode file and do something and then jump back again to the org-agenda buffer -- usually behind the scenes so the user doesn't see the change of focus between buffers . . .Penuche
@lawlist, I liked the question and answer, but have been using plain Timestamp over Scheduled so far. I have made a new question at #23235594. Hope it is straightforward, it did not seem so to me.Effloresce
Today on emacs 26 this function does not work for me.... Am I alone?Springe
@Springe This is working well for me, today on emacs 27.2.5 and org-mode 9.4.5.Macguiness
O
0

Here you have a simpler function based on the ones from lawlist

(defun my/org-schedule-effort ()
  "Takes SCHEDULED and EFFORT properties of the current node and calculates a new SCHEDULED in the range of the effort"
  (interactive)
  (let* ((effort         (org-entry-get nil "EFFORT"))
         (scheduled      (org-entry-get nil "SCHEDULED"))
         (scheduled-time (org-time-string-to-time scheduled))
         (new-scheduled  (format-time-string (concat "<%Y-%m-%d %H:%M+" effort ">") scheduled-time)))
    (org-schedule nil new-scheduled)))
Overdraw answered 29/4, 2024 at 13:11 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.