Re: [Orgmode] Visual representation of clocked time

2009-11-03 Thread Carsten Dominik

Hi Gennady,

thanks for sharing!

- Carsten

On Nov 2, 2009, at 10:16 PM, Gennady Trafimenkov wrote:


Hello everyone,

I was thinking that it would be nice to have a visual representation
of clocked time. It could give you a quick overview of when and how
long you had been working on a particular task.

For example, you have a subtree like this:

** very important task
  CLOCK: [2009-10-03 Sat 22:02]--[2009-10-03 Sat 23:21] =  1:19
  CLOCK: [2009-10-04 Sun 23:53]--[2009-10-05 Mon 02:10] =  2:17
  CLOCK: [2009-10-06 Tue 14:10]--[2009-10-06 Tue 14:50] =  0:40
  CLOCK: [2009-10-07 Wed 21:25]--[2009-10-08 Thu 00:21] =  2:56
  CLOCK: [2009-10-13 Tue 01:52]--[2009-10-13 Tue 02:52] =  1:00
  CLOCK: [2009-10-13 Tue 20:58]--[2009-10-13 Tue 23:32] =  2:34
  CLOCK: [2009-10-14 Wed 23:20]--[2009-10-15 Thu 00:55] =  1:35
  CLOCK: [2009-10-16 Fri 14:14]--[2009-10-16 Fri 14:53] =  0:39
  some text here

You press a combination of keys and get a table like this:

|---+-+-+-+-+-+-+-+--|
| Week Starting | Mon | Tue | Wed | Thu | Fri | Sat | Sun | tt,h |
|---+-+-+-+-+-+-+-+--|
|2009-09-28 | | | | | |  79 | 137 |  3.6 |
|2009-10-05 | |  40 | 176 | | | | |  3.6 |
|2009-10-12 | | 214 |  95 | |  39 | | |  5.8 |
|---+-+-+-+-+-+-+-+--|

The table contains total number of clocked minutes for every day and
total number of hours for every week.

If I could write such a thing in Emacs lisp, I would do that.  But
unfortunately I can't.  So, I wrote a python script and small function
in lisp to call it.  I am posting them here in hope that it might be
useful for someone.

Org-mode is an excellent thing. Thank you!

Best regards,
Gennady Trafimenkov


===  ===


(defun gt/org-get-clocked-time-stat-on-subtree ()
 Calculate nice table with statistics of clocked time.
  It puts results into buffer '*clocked-time-stat*'.
  When called with C-u, it copies results into the kill ring.
  GNU General Public License version 3 or later.
 (interactive)
 (let ((outputbuffer *clocked-time-stat*))
   (save-excursion
 (outline-mark-subtree)
 (shell-command-on-region (region-beginning) (region-end)
  python ~/bin/create-clock-table.py
outputbuffer)
 (if (equal current-prefix-arg '(4))
 (if (get-buffer outputbuffer)
 (progn
   (with-current-buffer outputbuffer
 (mark-whole-buffer)
 (kill-new (filter-buffer-substring
(region-beginning) (region-end))


=== create-clock-table.py ==


#/usr/bin/env python
#
# GNU General Public License version 3 or later
#
# This script extracts all record of this kind from the standart  
input:

#
#CLOCK: [2009-10-17 Sat 21:47]--[2009-10-17 Sat 23:10] =  1:23
#
# then aggregates data and build table with statistics like this:
#   |---+-+-+-+-+-+-+-+--|
#   | Week Starting | Mon | Tue | Wed | Thu | Fri | Sat | Sun | Tot. |
#   |---+-+-+-+-+-+-+-+--|
#   |2009-08-03 | | | | | | | |0 |
#   |2009-08-10 | | | | | | | |0 |
#   |2009-08-17 | | | |  75 |  60 |  60 |  15 |  210 |
#   |2009-08-24 |  75 |  60 |  60 |  70 | | | |  265 |
#   |2009-08-31 | |  10 | | | | | |   10 |
#   |---+-+-+-+-+-+-+-+--|
import sys
import re
import datetime

if __name__ == '__main__':

   dailyStat = {}
   # we are going to extract records like:
   #   CLOCK: [2009-10-17 Sat 21:47]--[2009-10-17 Sat 23:10] =  1:23
   timeExtractor = re.compile('^\s*CLOCK:
\[(\d{4})-(\d\d)-(\d\d).*\]--\[.*\] =\s+(\d+):(\d\d)')
   for line in sys.stdin.readlines():
   match = timeExtractor.match(line)
   if match:
   year, month, day = int(match.group(1)),
int(match.group(2)), int(match.group(3))
   hours, minutes = int(match.group(4)), int(match.group(5))
   date = datetime.date(year, month, day)
   minutes += hours * 60
   # print date, minutes

   dailyStat.setdefault(date, 0)
   dailyStat[date] += minutes

   if len(dailyStat) == 0:
   sys.exit(0)

   minDate = min(dailyStat.keys())
   maxDate = max(dailyStat.keys())
   firstWeek = minDate - datetime.timedelta(minDate.weekday())
   lastWeek = maxDate - datetime.timedelta(maxDate.weekday())

   # calculate weekly stat
   

[Orgmode] Visual representation of clocked time

2009-11-02 Thread Gennady Trafimenkov
Hello everyone,

I was thinking that it would be nice to have a visual representation
of clocked time. It could give you a quick overview of when and how
long you had been working on a particular task.

For example, you have a subtree like this:

** very important task
   CLOCK: [2009-10-03 Sat 22:02]--[2009-10-03 Sat 23:21] =  1:19
   CLOCK: [2009-10-04 Sun 23:53]--[2009-10-05 Mon 02:10] =  2:17
   CLOCK: [2009-10-06 Tue 14:10]--[2009-10-06 Tue 14:50] =  0:40
   CLOCK: [2009-10-07 Wed 21:25]--[2009-10-08 Thu 00:21] =  2:56
   CLOCK: [2009-10-13 Tue 01:52]--[2009-10-13 Tue 02:52] =  1:00
   CLOCK: [2009-10-13 Tue 20:58]--[2009-10-13 Tue 23:32] =  2:34
   CLOCK: [2009-10-14 Wed 23:20]--[2009-10-15 Thu 00:55] =  1:35
   CLOCK: [2009-10-16 Fri 14:14]--[2009-10-16 Fri 14:53] =  0:39
   some text here

You press a combination of keys and get a table like this:

|---+-+-+-+-+-+-+-+--|
| Week Starting | Mon | Tue | Wed | Thu | Fri | Sat | Sun | tt,h |
|---+-+-+-+-+-+-+-+--|
|2009-09-28 | | | | | |  79 | 137 |  3.6 |
|2009-10-05 | |  40 | 176 | | | | |  3.6 |
|2009-10-12 | | 214 |  95 | |  39 | | |  5.8 |
|---+-+-+-+-+-+-+-+--|

The table contains total number of clocked minutes for every day and
total number of hours for every week.

If I could write such a thing in Emacs lisp, I would do that.  But
unfortunately I can't.  So, I wrote a python script and small function
in lisp to call it.  I am posting them here in hope that it might be
useful for someone.

Org-mode is an excellent thing. Thank you!

Best regards,
Gennady Trafimenkov


===  ===


(defun gt/org-get-clocked-time-stat-on-subtree ()
  Calculate nice table with statistics of clocked time.
   It puts results into buffer '*clocked-time-stat*'.
   When called with C-u, it copies results into the kill ring.
   GNU General Public License version 3 or later.
  (interactive)
  (let ((outputbuffer *clocked-time-stat*))
(save-excursion
  (outline-mark-subtree)
  (shell-command-on-region (region-beginning) (region-end)
   python ~/bin/create-clock-table.py
outputbuffer)
  (if (equal current-prefix-arg '(4))
  (if (get-buffer outputbuffer)
  (progn
(with-current-buffer outputbuffer
  (mark-whole-buffer)
  (kill-new (filter-buffer-substring
(region-beginning) (region-end))


=== create-clock-table.py ==


#/usr/bin/env python
#
# GNU General Public License version 3 or later
#
# This script extracts all record of this kind from the standart input:
#
#CLOCK: [2009-10-17 Sat 21:47]--[2009-10-17 Sat 23:10] =  1:23
#
# then aggregates data and build table with statistics like this:
#   |---+-+-+-+-+-+-+-+--|
#   | Week Starting | Mon | Tue | Wed | Thu | Fri | Sat | Sun | Tot. |
#   |---+-+-+-+-+-+-+-+--|
#   |2009-08-03 | | | | | | | |0 |
#   |2009-08-10 | | | | | | | |0 |
#   |2009-08-17 | | | |  75 |  60 |  60 |  15 |  210 |
#   |2009-08-24 |  75 |  60 |  60 |  70 | | | |  265 |
#   |2009-08-31 | |  10 | | | | | |   10 |
#   |---+-+-+-+-+-+-+-+--|
import sys
import re
import datetime

if __name__ == '__main__':

dailyStat = {}
# we are going to extract records like:
#   CLOCK: [2009-10-17 Sat 21:47]--[2009-10-17 Sat 23:10] =  1:23
timeExtractor = re.compile('^\s*CLOCK:
\[(\d{4})-(\d\d)-(\d\d).*\]--\[.*\] =\s+(\d+):(\d\d)')
for line in sys.stdin.readlines():
match = timeExtractor.match(line)
if match:
year, month, day = int(match.group(1)),
int(match.group(2)), int(match.group(3))
hours, minutes = int(match.group(4)), int(match.group(5))
date = datetime.date(year, month, day)
minutes += hours * 60
# print date, minutes

dailyStat.setdefault(date, 0)
dailyStat[date] += minutes

if len(dailyStat) == 0:
sys.exit(0)

minDate = min(dailyStat.keys())
maxDate = max(dailyStat.keys())
firstWeek = minDate - datetime.timedelta(minDate.weekday())
lastWeek = maxDate - datetime.timedelta(maxDate.weekday())

# calculate weekly stat


weeklyStat = {}
week = firstWeek