Mercurial > getan
annotate contrib/wochenbericht @ 8:20414d892f04
Added script to generate lines for zeiterfassung.txt
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 01 Aug 2008 18:13:31 +0200 |
parents | e7245c2127e5 |
children | 4de86feae6ac |
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 # |
5
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
15 usage() { |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
16 cat <<EOF |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
17 usage: ./wochenbericht [<week of year>] [<getan database file>] |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
18 <week of year> defaults to current week |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
19 <getan database file> defaults to time.db |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
20 EOF |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
21 exit 1 |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
22 } |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
23 |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
24 if [ "$1" == "--help" -o "$1" == "-h" ]; then |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
25 usage |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
26 fi |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
27 |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
28 |
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
|
29 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
|
30 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
|
31 # 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
|
32 #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
|
33 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
|
34 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
|
35 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
|
36 |
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 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
|
38 |
5
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
39 if [ ! -f ${TIME_DB} ]; then |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
40 echo "error: Database file ${TIME_DB} does not exist." |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
41 usage |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
42 fi |
e7245c2127e5
Applied patch from Stephan Holl to show usage on '-h' of '--help'. Added check for existence of db file.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4
diff
changeset
|
43 |
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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 ) 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
|
55 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
|
56 " | 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 } |
2b2f74f301db
Added little script to summarize the entries for a given week number of year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
63 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
|
64 { 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
|
65 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
|
66 } |
2b2f74f301db
Added little script to summarize the entries for a given week number of year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
67 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
|
68 ' |