如何划分重叠的日期时间间隔(组织模式时钟时间)?

发布于 2024-08-05 00:15:26 字数 3193 浏览 6 评论 0原文

我有来自两个组织文件/子树的相关任务,其中一些时钟时间重叠。这些是手动工作日志和生成的 git 提交日志,请参见下文。

一棵子树的时钟:需要调整条目以消除重叠时间。另一个子树被认为是完整的,并且它的时钟:不应调整条目。

编辑:这个问题是关于计算新的时间间隔以消除任何重叠。任何建议都不需要解析Org模式文件格式。 Python datetime.datetime 算法很有帮助,使用或不使用 Org 模式函数的 Emacs Lisp 也很有帮助。

在 Python(更熟悉)或 Emacs Lisp(Org 函数可能有帮助)中,我想:

  1. 确定时间重叠的地方 发生。 file1.org 将是可变的, file2.org 时间间隔应该是 被认为是固定/正确的。

  2. 计算新的时间间隔 CLOCK: file1.org 中的行 删除任何重叠 file2.org CLOCK:行。

  3. 写入生成的新时钟:行 出来,或者至少是相关的 日期时间。

python 便捷函数 tsparse 将 Org Mode 时间戳转换为 python datetime.datetime 对象:

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

测试用例可以在下面找到。感谢您提供有关 Python 或 Emacs Lisp 的任何算法或实现建议。

Jeff


file1.org调整前

* 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调整后< /em> 调整:

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

I have related tasks from two Org files/subtrees where some of the clocked time overlaps. These are a manual worklog and a generated git commit log, see below.

One subtree's CLOCK: entries needs to be adjusted to remove overlapping time. The other subtree is considered complete, and it's CLOCK: entries should not be adjusted.

EDIT: This question is about calculating new time intervals to remove any overlaps. Any suggestions don't need to parse the Org mode file format. Python datetime.datetime algorithms are helpful, as are Emacs Lisp with or without the use of Org mode functions.

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

  1. Identify time overlaps where they
    occur. file1.org will be mutable,
    file2.org time intervals should be
    considered fixed/correct.

  2. Calculate new time intervals for
    the CLOCK: lines in file1.org
    to remove any overlap with
    file2.org CLOCK: lines.

  3. write resulting new CLOCK: lines
    out, or at least the pertinent
    datetimes.

The python convenience function tsparse converts an 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 algorithm or implementation suggestions for Python or Emacs Lisp.

Jeff


file1.org, prior to adjustments:

* 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 adjustments:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一张白纸 2024-08-12 00:15:26

您需要解析文件格式的帮助吗?或者只是计算出重叠时间?

datetime 对象在 Python 中是可比较的,因此您可以执行以下操作:

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

如果第一个范围的末尾 (b) 在第二个范围(c 和 d)内,则存在重叠,您 可以执行以下操作:可以将这两对合并到一个范围(a,d)中。

由于您的数据集看起来非常小,您可能只需在所有时间范围 (N**2) 之间进行比较和合并即可获得可接受的结果。

Do you want help parsing the file format? Or just on figuring out the overlapping times?

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 within the second range (c and d), then there is an overlap and you can merge those two pairs into one range (a,d).

Since your set of data looks pretty small you can probably just do this comparison and merge between all time ranges (N**2) and get an acceptable result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文