如何划分重叠的日期时间间隔(组织模式时钟时间)?
我有来自两个组织文件/子树的相关任务,其中一些时钟时间重叠。这些是手动工作日志和生成的 git 提交日志,请参见下文。
一棵子树的时钟:需要调整条目以消除重叠时间。另一个子树被认为是完整的,并且它的时钟:不应调整条目。
编辑:这个问题是关于计算新的时间间隔以消除任何重叠。任何建议都不需要解析Org模式文件格式。 Python datetime.datetime 算法很有帮助,使用或不使用 Org 模式函数的 Emacs Lisp 也很有帮助。
在 Python(更熟悉)或 Emacs Lisp(Org 函数可能有帮助)中,我想:
确定时间重叠的地方 发生。 file1.org 将是可变的, file2.org 时间间隔应该是 被认为是固定/正确的。
计算新的时间间隔 CLOCK: file1.org 中的行 删除任何重叠 file2.org CLOCK:行。
写入生成的新时钟:行 出来,或者至少是相关的 日期时间。
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:
Identify time overlaps where they
occur. file1.org will be mutable,
file2.org time intervals should be
considered fixed/correct.Calculate new time intervals for
the CLOCK: lines in file1.org
to remove any overlap with
file2.org CLOCK: lines.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要解析文件格式的帮助吗?或者只是计算出重叠时间?
datetime
对象在 Python 中是可比较的,因此您可以执行以下操作:如果第一个范围的末尾 (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: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.