Mercurial > getan
comparison scripts/wochenbericht @ 380:20fde79f8e12
Move all scripts in a common scripts directory
Currently console scripts were kept in several directories. Now use a common
directory for all scripts.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Mon, 05 Jan 2015 10:54:20 +0100 |
parents | contrib/wochenbericht@4de86feae6ac |
children |
comparison
equal
deleted
inserted
replaced
379:47890f38e558 | 380:20fde79f8e12 |
---|---|
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 usage() { | |
16 cat <<EOF | |
17 usage: ./wochenbericht [<week of year>] [<year>] [<getan database file>] | |
18 <week of year> defaults to current week | |
19 <year> defaults to current year | |
20 <getan database file> defaults to time.db | |
21 EOF | |
22 exit 1 | |
23 } | |
24 | |
25 if [ "$1" == "--help" -o "$1" == "-h" ]; then | |
26 usage | |
27 fi | |
28 | |
29 | |
30 if [[ "$1" -eq "" ]]; then | |
31 WEEK=`date +'%W'` | |
32 # remove hash below if you want previous week | |
33 #WEEK=`expr ${WEEK} '-' 1 '|' 52` | |
34 else | |
35 WEEK=$1 | |
36 fi | |
37 | |
38 if [[ "$2" -eq "" ]]; then | |
39 YEAR=`date +'%Y'` | |
40 else | |
41 YEAR=$2 | |
42 fi | |
43 | |
44 TIME_DB=${3:-time.db} | |
45 | |
46 if [ ! -f ${TIME_DB} ]; then | |
47 echo "error: Database file ${TIME_DB} does not exist." | |
48 usage | |
49 fi | |
50 | |
51 sqlite3 ${TIME_DB} " | |
52 SELECT coalesce(description, 'Verschiedenes'), total FROM projects | |
53 INNER JOIN ( | |
54 SELECT | |
55 project_id, | |
56 sum(strftime('%s', stop_time) - strftime('%s', start_time)) AS total | |
57 FROM entries | |
58 WHERE (strftime('%W', start_time) = '${WEEK}' AND | |
59 strftime('%Y', start_time) = '${YEAR}') OR | |
60 (strftime('%W', stop_time) = '${WEEK}' AND | |
61 strftime('%Y', stop_time) = '${YEAR}') | |
62 GROUP BY project_id | |
63 ) ON id = project_id | |
64 WHERE active; | |
65 " | awk ' | |
66 function human_time(t) { | |
67 h = int(t / 3600) | |
68 m = int((t % 3600)/60.0 + 0.5) | |
69 while (m >= 60) { ++h; m -= 60 } | |
70 return sprintf("%2d:%02dh", h, m) | |
71 } | |
72 BEGIN { FS="|"; sum = 0 } | |
73 { sum += $2 | |
74 printf("%s: %s\n", human_time($2), $1) | |
75 } | |
76 END { printf("%s: Gesamt\n", human_time(sum)) } | |
77 ' |