org-clock-agg: select elements works

This commit is contained in:
Pavel Korytov 2023-12-01 17:32:31 +03:00
parent 7ccf1521c6
commit 043aa82f86

View file

@ -29,6 +29,67 @@
;;; Code: ;;; Code:
(require 'compat) (require 'compat)
(require 'org)
(require 'org-ql)
;; Reset org-ql cache
(setq org-ql-cache (make-hash-table :weakness 'key))
(defun org-clock-agg--parse-clocks (headline)
(let ((contents (buffer-substring-no-properties
(org-element-property :contents-begin headline)
(org-element-property :contents-end headline))))
(with-temp-buffer
(insert contents)
(let (res)
(org-element-map (org-element-parse-buffer) 'clock
(lambda (clock)
(let ((start )
(end (time-convert
(org-timestamp-to-time (org-element-property :value clock) t)
'integer))))
(push
`((:start . ,(time-convert
(org-timestamp-to-time (org-element-property :value clock))
'integer))
(:end . ,(time-convert
(org-timestamp-to-time (org-element-property :value clock) t)
'integer)))
res))
nil nil 'headline)
res))))
(defun org-clock-agg--parse-headline ()
(let* ((headline (org-element-headline-parser))
(tags-val (org-ql--tags-at (point)))
(tags (seq-filter
#'stringp ;; to filter out `org-ql-nil'
(append (unless (eq (car tags-val) 'org-ql-nil)
(car tags-val))
(unless (eq (cdr tags-val) 'org-ql-nil)
(cdr tags-val)))))
(file (buffer-file-name))
(outline-path (mapcar
#'substring-no-properties
(org-ql--outline-path)))
(category (org-get-category)))
`((:headline . ,headline)
(:tags . ,tags)
(:file . ,file)
(:outline-path . ,outline-path)
(:category . ,category)
(:clocks . ,(org-clock-agg--parse-clocks headline)))))
(defun org-clock-agg--query (from to files)
(org-ql-query
:select #'org-clock-agg--parse-headline
:from files
:where `(clocked :from ,from :to ,to)))
(defun org-clock-agg ()
(interactive)
())
(provide 'org-clock-agg) (provide 'org-clock-agg)
;;; org-clock-agg.el ends here ;;; org-clock-agg.el ends here