Last active
November 19, 2021 18:05
-
-
Save Trevoke/c91cc8c97476f681f82f9ce44efdac9b to your computer and use it in GitHub Desktop.
org clock table data grouped by project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; generates something like this | |
;; #+begin: clockreport-by-project | |
;; | | 2021-11-15.org | 2021-11-16.org | | |
;; |------------+----------------+----------------| | |
;; | EA | 0.18 | | | |
;; | internal | 0.83 | | | |
;; | management | 0.47 | 1.70 | | |
;; #+end: | |
(defun org-dblock-write:clockreport-by-project (params) | |
(let* ((clock-table-data (stag-clock-table-data)) | |
(days-and-project-times (stag-days-and-project-times clock-table-data)) | |
(projects (stag-get-projects clock-table-data))) | |
(org-table-create (format "%sx%s" | |
(1+ (seq-length days-and-project-times)) | |
(1+ (seq-length projects)))) | |
(-each-indexed projects | |
(lambda (index project) | |
(org-table-put (+ 2 index) 1 project))) | |
(-each-indexed days-and-project-times | |
(lambda (index day-and-project-times) | |
(let ((day (car day-and-project-times)) | |
(project-times (cdr day-and-project-times))) | |
(org-table-put 1 (+ 2 index) day) | |
(mapc | |
(lambda (project-time) | |
(let ((project (car project-time)) | |
(time (/ (apply '+ (cdr project-time)) 60.0))) | |
(org-table-put (+ 2 (seq-position projects project)) | |
(+ 2 index) | |
(format "%.2f" time) | |
t))) | |
project-times)))))) | |
(defun stag-org-property (headlines) | |
(cdar (nth 5 headlines))) | |
(defun stag-clean-data (project-and-entries) | |
(cons (car project-and-entries) | |
(mapcar (lambda (y) (nth 4 y)) (cdr project-and-entries)))) | |
(defun stag-clock-table-data () | |
(seq-remove | |
(lambda (day-totaltime-projects) (eql 0 (cadr day-totaltime-projects))) | |
(mapcar | |
(lambda (file) | |
(with-current-buffer (find-file-noselect file) | |
(org-clock-get-table-data file '(:properties ("PROJECT"))))) | |
(file-expand-wildcards "~/Documents/orgnotes/roam/daily/*.org")))) | |
(defun stag-days-and-project-times (clock-table-data) | |
(save-excursion | |
(mapcar | |
(lambda (file-total-breakdown) | |
(cons (car (last (split-string (car file-total-breakdown) "/"))) | |
(mapcar | |
#'stag-clean-data | |
(seq-group-by | |
#'stag-org-property | |
(caddr file-total-breakdown))))) | |
clock-table-data))) | |
(defun stag-get-projects (clock-table-data) | |
"List of day-totaltime-projects" | |
(seq-sort | |
#'string-lessp | |
(seq-uniq | |
(mapcar | |
'cdr | |
(mapcan | |
(lambda (headline-data) (nth 5 headline-data)) | |
(mapcan 'caddr clock-table-data))) | |
#'string-equal))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment