繁体   English   中英

组织模式审查多个标签的计时时间

[英]org-mode review clocked time by multiple tags

我想通过标签查看我的计时时间,以回答例如我本周花了多少时间在我的健康、工作、客户或社交关系上?

我正在使用标签,因为我想查看计时时间的项目可以分布在多个文件中并隐藏在不同的子树中。 也许这就是问题所在,我需要重组? 例如“在你的日记中写一个条目”应该存储在“笔记”下,但总结为“健康”,当然在“笔记”下还会有其他笔记,如“财务”......

任何其他解决方案,例如使用自定义议程视图或类别而不是标签,也将非常受欢迎。

到目前为止,我已经尝试使用由多个标签分组的组织模式时钟表 为了使用时钟表,我使用了这个测试数据:

* Take out the trash                                                :private:
:LOGBOOK:
CLOCK: [2021-03-12 Fri 11:24]--[2021-03-12 Fri 11:30] =>  0:06
:END:
* Update document for client                                        :client1:
:LOGBOOK:
CLOCK: [2021-03-12 Fri 12:45]--[2021-03-12 Fri 13:30] =>  0:45
:END:
* Create my awesome note for work                                      :work:
:LOGBOOK:
CLOCK: [2021-03-13 Sat 11:24]--[2021-03-13 Sat 12:53] =>  1:29
:END:
* Fill in timesheet                                                    :work:
:LOGBOOK:
CLOCK: [2021-03-12 Fri 11:24]--[2021-03-12 Fri 11:40] =>  0:16
:END:

我找到了以下解决方案,但似乎都不适用于我的系统。

在这里我的问题得到了完美的描述。 我已经下载了代码,它会创建一个表格,但不会显示总和。 不幸的是,被截断的代码似乎太旧了,我无法修复它。 我找到了那个剪断的叉子,它给了我这个结果:

#+BEGIN: clocktable-by-tag :tags ("work" "client1")
| Tag     | Headline   | Time (h) |
|         |            |      <r> |
|---------+------------+----------|
| work    | *Tag time* |   *0.00* |
|---------+------------+----------|
| client1 | *Tag time* |   *0.00* |    
#+END:

在这里我找到了另一个解决方案。 作者使用 function 来格式化时间,然后由orgaggregate使用。 不幸的是,第一步似乎无法正常工作:

 #+BEGIN: clocktable :scope file :maxlevel 3 :tags t :match "work|client1" :header "#+TBLNAME: timetable\n"
#+TBLNAME: timetable
| Tags    | Headline                        |   Time | T      |
|---------+---------------------------------+--------+--------|
|         | *Total time*                    | *2:30* | #ERROR |
|---------+---------------------------------+--------+--------|
| client1 | Update document for client      |   0:45 | #ERROR |
| work    | Create my awesome note for work |   1:29 | #ERROR |
| work    | Fill in timesheet               |   0:16 | #ERROR |
#+TBLFM: $4='(convert-org-clocktable-time-to-hhmm $3)::@1$4='(format "%s" "T")
#+END:

这真的不应该那么难,我想实现的目标。 目前我最好的解决方案是使用多个表,每个标签一个:

#+BEGIN: clocktable :scope file :maxlevel 3 :match "work"
#+CAPTION: Clock summary at [2022-01-03 Mon 16:55]
| Headline                        |   Time |
|---------------------------------+--------|
| *Total time*                    | *1:45* |
|---------------------------------+--------|
| Create my awesome note for work |   1:29 |
| Fill in timesheet               |   0:16 |
#+END:


#+BEGIN: clocktable :scope file :maxlevel 3 :match "client1"
#+CAPTION: Clock summary at [2022-01-03 Mon 16:55]
| Headline                   | Time   |
|----------------------------+--------|
| *Total time*               | *0:45* |
|----------------------------+--------|
| Update document for client | 0:45   |
#+END:

您找到的第一个解决方案几乎就在那里。 它有两个问题给了你错误的结果:

  1. 它只考虑议程文件,而不是当前文件作为表格的输入。 这就是您得到空结果的原因。
  2. 要将分钟转换为格式良好的显示,可以使用 function org-duration-from-minutes

通过这些更新,您的测试文件向我提供了以下结果:

  #+BEGIN: clocktable-by-tag :tags ("work" "client1")
  | Tag     | Headline                          | Time (h) |      |
  |---------+-----------------------------------+----------+------|
  | work    | *Tag time*                        |     1:29 |      |
  |         | File *test.org*                   |     1:29 |      |
  |         | . Create my awesome note for work |          | 1:29 |
  |---------+-----------------------------------+----------+------|
  | client1 | *Tag time*                        |     0:45 |      |
  |         | File *test.org*                   |     0:45 |      |
  |         | . Update document for client      |          | 0:45 |
  
  #+END:

您可以使用:summary t获得更好的摘要(我个人更喜欢此选项):

  #+BEGIN: clocktable-by-tag :tags ("work" "client1") :summary t
  | Tag     | Headline   | Time (h) |
  |---------+------------+----------|
  | work    | *Tag time* |     1:29 |
  |---------+------------+----------|
  | client1 | *Tag time* |     0:45 |
  
  #+END:

:scope标签也有效,除了我没有实现比当前文件更严格的范围(例如subtree )。

您可以在gist中找到代码,或从下面复制并粘贴:

(require 'org-clock)

(defun clocktable-by-tag/shift-cell (n)
  (let ((str ""))
    (dotimes (i n)
      (setq str (concat str "| ")))
    str))

(defun clocktable-by-tag/insert-tag (files params)
  (let ((tag (plist-get params :tags))
        (summary-only (plist-get params :summary))
        (total 0))
    (insert "|--\n")
    (insert (format "| %s | *Tag time* |\n" tag))
    (mapcar
     (lambda (file)
       (let ((clock-data (with-current-buffer (find-buffer-visiting file)
                           (org-clock-get-table-data (buffer-name) params))))
         (when (> (nth 1 clock-data) 0)
           (setq total (+ total (nth 1 clock-data)))
           (if (not summary-only)
               (progn
                 (insert (format "| | File *%s* | %s |\n"
                                 (file-name-nondirectory file)
                                 (org-duration-from-minutes (nth 1 clock-data))))
                 (dolist (entry (nth 2 clock-data))
                   (insert (format "| | . %s%s | %s %s |\n"
                                   (org-clocktable-indent-string (nth 0 entry))
                                   (nth 1 entry)
                                   (clocktable-by-tag/shift-cell (nth 0 entry))
                                   (org-duration-from-minutes (nth 4 entry))))))))))
     files)
    (save-excursion
      (re-search-backward "*Tag time*")
      (org-table-next-field)
      (org-table-blank-field)
      (insert (org-duration-from-minutes total))))
  (org-table-align))

(defun org-dblock-write:clocktable-by-tag (params)
  (insert "| Tag | Headline | Time (h) |\n")
  (let ((params (org-combine-plists org-clocktable-defaults params))
        (base-buffer (org-base-buffer (current-buffer)))
          (files (pcase (plist-get params :scope)
                     (`agenda
                      (org-agenda-files t))
                     (`agenda-with-archives
                      (org-add-archive-files (org-agenda-files t)))
                     (`file-with-archives
                      (let ((base-file (buffer-file-name base-buffer)))
                        (and base-file
                               (org-add-archive-files (list base-file)))))
                     ((or `nil `file)
                      (list (buffer-file-name)))
                     (_ (user-error "Unknown scope: %S" scope))))
        (tags (plist-get params :tags)))
    (mapcar (lambda (tag)
              (clocktable-by-tag/insert-tag files (org-combine-plists params `(:match ,tag :tags ,tag))))
            tags)))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM