1

I am using org-clock-report to keep track of my daily working hours. Example:

#+BEGIN: clocktable :scope file :maxlevel 2
#+CAPTION: Clock summary at [2023-07-26 Mi 06:04]
|   Headline |     Time |
|------------+----------|
| *Total time* | *2d 13:23* |
|------------+----------|
| 18.07.2023 |     8:40 |
| 19.07.2023 |     8:41 |
| 20.07.2023 |     7:22 |
| 21.07.2023 |     8:35 |
| 24.07.2023 |    11:24 |
| 25.07.2023 |     8:02 |
| 26.07.2023 |     8:39 |
#+END:

How can I add a line with the average daily working hours?

1 Answer 1

1

Well, the setup you have makes it marginally more complicated. For the sake of providing you with at least a partial answer, which may spur someone to provide a more complete one, here is something that works easily if you use the subtree scope.

The main reason why the subtree scope is convenient, here, is that it provides a third column, which means I have an existing empty cell in which I can put information.

The key is to change the clocktable properties to add a formula

#+BEGIN: clocktable :scope subtree :maxlevel 2 :formula "@2$3=vmean(@4$3..@>$3);U"

This will add the mean of the hours into the empty cell next to the total time for the subtree. Here's a small example:

* clock
#+BEGIN: clocktable :scope subtree :maxlevel 2 :formula "@2$3=vmean(@4$3..@>$3);U"
#+CAPTION: Clock summary at [2023-07-26 Wed 13:42]
| Headline           | Time    |       |
|--------------------+---------+-------|
| *Total time*       | *21:00* | 05:15 |
|--------------------+---------+-------|
| clock?             | 21:00   |       |
| \_  Time           |         |  6:00 |
| \_  Only time      |         |  2:00 |
| \_  Can bring back |         |  4:00 |
| \_  Our love again |         |  9:00 |
#+TBLFM: @2$3=vmean(@4$3..@>$3);U
#+END:

** Time
:LOGBOOK:
CLOCK: [2023-07-26 Wed 12:41]--[2023-07-26 Wed 18:41] =>  6:00
:END:
** Only time
:LOGBOOK:
CLOCK: [2023-06-26 Wed 12:41]--[2023-06-26 Wed 14:41] =>  2:00
:END:

** Can bring back 
:LOGBOOK:
CLOCK: [2023-05-26 Wed 12:41]--[2023-05-26 Wed 16:41] =>  4:00
:END:
** Our love again
:LOGBOOK:
CLOCK: [2023-04-26 Wed 12:41]--[2023-04-26 Wed 21:41] =>  9:00
:END:

The references I used to figure this out are primarily under https://orgmode.org/manual/The-Spreadsheet.html - it's not particularly pretty, but it is incredibly powerful. You'll find things in here like the U for time calculations and the meanings of $ and @ and @>.

I am not entirely sure how to add a new table line after the fact through the org-clock-report function.

This being said, you may be able to leverage the above to write a function that first calls org-clock-report and then modifies the resulting table, now that you have a sense of the formula you need to use to get the average.

I hope this helps - I know it's not a complete answer to your question.

2
  • +1 for the ;U which I think I knew at one point but had certainly forgotten. But I too don't know how to add an empty row at the end of the table, other than using a :formatter function - but that would mean basically copying and modifying org-clocktable-write-default - or maybe it could be done by advising the function instead.
    – NickD
    Commented Jul 26, 2023 at 18:27
  • 1
    Thank you very much! Because of your answer I learned 1) how to add spreadsheet formulas to org-clock-report functions and 2) learned about ;U. As the total hours are not important to me, I am replacing it now by the average; so your answer really solved my problem! #+BEGIN: clocktable :scope file :maxlevel 2 :formula "@2$2=vmean(@3$2..@>>$2);U::@2$1=Average time"
    – ontheair
    Commented Jul 27, 2023 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.