comparison contrib/wochenbericht @ 4:2b2f74f301db

Added little script to summarize the entries for a given week number of year.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 31 Jul 2008 01:00:42 +0200
parents
children e7245c2127e5
comparison
equal deleted inserted replaced
3:1513c716eef0 4:2b2f74f301db
1 #!/bin/bash
2 #
3 # wochenbericht
4 # -------------
5 # (c) 2008 by Sascha L. Teichmann
6
7 # Little script to summarize times within a given week.
8 # usage:
9 # ./wochenbericht [<week of year>] [<getan database file>]
10 # week defaults to current week, database to time.db
11 #
12 # This is Free Software in terms of GPLv3 or later. See
13 # LICENSE coming with getan for details.
14 #
15 if [[ "$1" -eq "" ]]; then
16 WEEK=`date +'%W'`
17 # remove hash below if you want previous week
18 #WEEK=`expr ${WEEK} '-' 1 '|' 52`
19 else
20 WEEK=$1
21 fi
22
23 TIME_DB=${2:-time.db}
24
25 sqlite3 ${TIME_DB} "
26 SELECT coalesce(description, 'Verschiedenes'), total FROM projects
27 INNER JOIN (
28 SELECT
29 project_id,
30 sum(strftime('%s', stop_time) - strftime('%s', start_time)) AS total
31 FROM entries
32 WHERE strftime('%W', start_time) = '${WEEK}' OR
33 strftime('%W', stop_time) = '${WEEK}'
34 GROUP BY project_id
35 ) ON id = project_id
36 WHERE active;
37 " | awk '
38 function human_time(t) {
39 h = int(t / 3600)
40 m = int((t % 3600)/60.0 + 0.5)
41 while (m >= 60) { ++h; m -= 60 }
42 return sprintf("%2d:%02dh", h, m)
43 }
44 BEGIN { FS="|"; sum = 0 }
45 { sum += $2
46 printf("%s: %s\n", human_time($2), $1)
47 }
48 END { printf("%s: Gesamt\n", human_time(sum)) }
49 '
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)