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