1 Context
In a custom org-mode agenda view (in column mode), there is a column with label μ
that shows "utility ranges" in brackets. Here is what it looks like (alongside the Category
and TODO
columns):
|Category | TODO | μ |
|cat1 | COMPLETE | [0.1μ, 3 μ] |
|cat2 | STARTED | [0.2μ, 4 μ] |
|cat2 | COMPLETE | [0.2 μ] |
|cat2 | TODO | [0.1μ, 3 μ] |
|cat3 | COMPLETE | [0.2μ, 6 μ] |
Here [0.2 μ]
is just short-hand for [0.2 μ, 0.2 μ]
.
2 Problem
What I'd like is some conditional summation data which shows -- for each category -- the sum of the utility ranges for tasks which are in the DONE state (i.e., the sum of the lowest utilities and the highest utilities in enclosed in brackets). In this case it should show something like the following:
|Category | TODO | μ |
|cat1 | COMPLETE | [0.1μ, 3 μ] |
|cat2 | STARTED | [0.2μ, 4 μ] |
|cat2 | COMPLETE | [0.2 μ] |
|cat2 | COMPLETE | [0.2 μ, 0.4μ] |
|cat2 | TODO | [0.1μ, 3 μ] |
|cat3 | STARTED | [0.2μ, 6 μ] |
cat1 μ: [0.1μ, 3 μ]
cat2 μ: [0.4 μ, 0.8 μ]
cat3 μ: [0.0 μ, 0.0 μ]
3 First Attempt
I have the following function which sums μ-ranges (or any other range enclosed in brackets):
(defun bracket-sum (begin end char)
(interactive "r\nM String: ")
(save-restriction
(save-excursion
(narrow-to-region begin end)
(goto-char (point-min))
(let ((suml 0)
(sumr 0)
(regexpl (concat "\\[ *\\([-0-9.]+\\) *" char " *,"))
(regexpr (concat ", *\\([-0-9.]+\\) *" char "*\\]"))
(regexpm (concat "\\[ *\\([-0-9.]+\\) *" char "*\\]"))
)
(while (re-search-forward regexpl nil t)
(setq suml (+ suml (string-to-number (match-string 1)))))
(goto-char (point-min))
(while (re-search-forward regexpr nil t)
(setq sumr (+ sumr (string-to-number (match-string 1)))))
(goto-char (point-min))
(while (re-search-forward regexpm nil t)
(setq suml (+ suml (string-to-number (match-string 1))))
(setq sumr (+ sumr (string-to-number (match-string 1)))))
(message "[%s%s, %s%s]" suml char sumr char)
))))
It can be called by enclosing a text region with bracket expressions and calling i.e. (bracket-sum begin end "μ")
. So for example the sum of
[0.1μ, 0.2 μ]
[0.1μ]
[0.1μ, 0.2 μ]
is [0.3μ, 0.5 μ]
.
From here I'm not sure how to work this into the agenda view information. Does anybody have any thoughts on how to do this?