Thursday, August 11, 2011

Debugging Org-mode clocktable time summary

At one time, the following used to work:
#+TBLFM: $3='(org-clock-time% @2$2 $2);%.1f;::$4='(org-clock-time% "40:00" $2);%.1f;
My table would end up getting columns that showed
  • The percentage (time for this row / total time),
  • The percentage (time for this row / 40 hours)
Either due to an Emacs upgrade, or an Org-mode upgrade, this broke. So now I get 0 as the percentage.

To debug this I used the variable org-table-formula-debug which outputs information when Org formulas are evaluated. Please see the function org-table-eval-formula in the file org-table.el.
(setq org-table-formula-debug t)
It showed me something like:
Substitution history of formula
Orig:   '(org-clock-time% "40:00" $2);%.1f;
$xyz->  '(org-clock-time% "40:00" $2)
@r$c->  '(org-clock-time% "40:00" $2)
$1->    '(org-clock-time% "40:00" "1480")
Result: 0
Format: %.1f
Final:  0.0
Indeed, evaluating (org-clock-time% "40:00" "1480") gives me 0.
So I set edebug-on-entry for this function, and tried evaluating the above statement (using M-:).

I ended up adding the following condition to fix my problem:
((string-match "\\([0-9]+\\)" s)
 (throw 'exit
        (/ (* 100.0 (string-to-number (match-string 1 s)))


Post a Comment