How to distribute datetime intervals that overlap (times in Org Mode)?

I have related tasks from two Org files / subtrees where some of the time clocks overlap. This is a manual working log and a generated git log, see below.

One subtree CLOCK: records need to be adjusted to remove overlap time. The other subtree is considered complete and its CLOCK: entries should not be configured.

EDIT: This question has to do with calculating new time slots to remove any overlaps. Any suggestions do not need to parse the Org file format. Python's datetime.datetime algorithms are as useful as Emacs Lisp with or without Org mode functions.

In Python (more familiar) or Emacs Lisp (maybe Org functions) I would like to:

  • Identify temporary overlaps where they occur. file1.org will change, file timezones. considered fixed / correct.

  • Calculate new time intervals for CLOCK: lines in file1.org remove any match with file2.org CLOCK: lines.

  • write a new CLOCK: strings, or at least the corresponding DateTimes.

The python tsparse convenience function converts the Org mode timestamp to a python datetime.datetime object:

>>> from datetime import datetime, timedelta
>>> def tsparse(timestring): return datetime.strptime(timestring,'%Y-%m-%d %a %H:%M')
>>> tsparse('2008-10-15 Wed 00:45')
datetime.datetime(2008, 10, 15, 0, 45)

      

Test cases can be found below. Thanks for any suggestions for an algorithm or implementation for Python or Emacs Lisp.

Jeff


file1.org , before the settings:

* Manually Edited Worklog

** DONE Onsite
   CLOSED: [2009-09-09 Wed 15:00]
   :LOGBOOK:
   CLOCK: [2009-09-09 Wed 07:00]--[2009-09-09 Wed 15:00] =>  8:00
   :END:

** DONE Onsite
   CLOSED: [2009-09-10 Wed 15:00]
   :LOGBOOK:
   CLOCK: [2009-09-10 Thu 08:00]--[2009-09-10 Thu 15:00] =>  7:00
   :END:

      


file2.org

* Generated commit log

** DONE Commit 1                          :partial:overlap:leading:contained:
   CLOSED: [2009-09-09 Tue 10:18]
   :LOGBOOK:
   CLOCK: [2009-09-09 Wed 06:40]--[2009-09-09 Wed 07:18] =>  0:38
   CLOCK: [2009-09-09 Wed 10:12]--[2009-09-09 Wed 10:18] =>  0:06
   :END:

** DONE Commit 2                               :contained:overlap:contiguous:
   CLOSED: [2009-09-09 Wed 10:20]
   :LOGBOOK:
   CLOCK: [2009-09-09 Wed 10:18]--[2009-09-09 Wed 10:20] =>  0:02
   :END:

** DONE Commit 4                                          :contained:overlap:
   CLOSED: [2009-09-10 Wed 09:53]
   :LOGBOOK:
   CLOCK: [2009-09-10 Wed 09:49]--[2009-09-10 Wed 09:53] =>  0:04
   :END:

** DONE Commit 5                                   :partial:overlap:trailing:
   CLOSED: [2009-09-10 Wed 15:12]
   :LOGBOOK:
   CLOCK: [2009-09-10 Wed 14:45]--[2009-09-10 Wed 15:12] =>  0:27
   :END:

** DONE Commit 6                                    :partial:overlap:leading:
   CLOSED: [2009-09-11 Fri 08:05]
   :LOGBOOK:
   CLOCK: [2009-09-11 Fri 07:50]--[2009-09-11 Fri 08:05] =>  0:15
   :END:

** DONE Commit 7                                                 :nonoverlap:
   CLOSED: [2009-09-11 Fri 15:55]
   :LOGBOOK:
   CLOCK: [2009-09-11 Fri 15:25]--[2009-09-11 Fri 15:55] =>  0:30
   :END:

      


file1.org , after settings:

* Manually Edited Worklog

** DONE Onsite
   CLOSED: [2009-09-09 Wed 15:00]
   :LOGBOOK:
   CLOCK: [2009-09-09 Wed 10:20]--[2009-09-09 Wed 14:45] =>  4:25
   CLOCK: [2009-09-09 Wed 07:18]--[2009-09-09 Wed 10:12] =>  2:54
   :END:

** DONE Onsite
   CLOSED: [2009-09-10 Wed 15:00]
   :LOGBOOK:
   CLOCK: [2009-09-10 Thu 08:05]--[2009-09-10 Thu 15:00] =>  6:55
   :END:

      

+2


source to share


1 answer


Do you want to parse the file format? Or just figure out the overlap time?

datetime

objects are comparable in Python, so you can do something like this:

>>> (a,b) = (datetime(2009, 9, 15, 8, 30), datetime(2009, 9, 15, 8, 45))
>>> (c,d) = (datetime(2009, 9, 15, 8, 40), datetime(2009, 9, 15, 8, 50))
>>> a <= b
True
>>> if c <= b <= d:
...     print "overlap, merge these two ranges"
... else:
...     print "separate ranges, leave them alone"
...
overlap, merge these two ranges

      



If the end of the first range (b) is in the second range (c and d), then there is an overlap and you can combine these two pairs into one range (a, d).

Since your dataset looks pretty small, you can probably just do this comparison and merge all the time ranges (N ** 2) and get an acceptable result.

+2


source







All Articles