Mercurial > getan
comparison contrib/wochenbericht @ 32:4de86feae6ac
Added a parameter 'year' to the 'wochenbericht' script that filters out the week of a specific year only.
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 31 Aug 2010 19:27:36 +0200 |
parents | e7245c2127e5 |
children |
comparison
equal
deleted
inserted
replaced
31:fa5b3b1db867 | 32:4de86feae6ac |
---|---|
12 # This is Free Software in terms of GPLv3 or later. See | 12 # This is Free Software in terms of GPLv3 or later. See |
13 # LICENSE coming with getan for details. | 13 # LICENSE coming with getan for details. |
14 # | 14 # |
15 usage() { | 15 usage() { |
16 cat <<EOF | 16 cat <<EOF |
17 usage: ./wochenbericht [<week of year>] [<getan database file>] | 17 usage: ./wochenbericht [<week of year>] [<year>] [<getan database file>] |
18 <week of year> defaults to current week | 18 <week of year> defaults to current week |
19 <year> defaults to current year | |
19 <getan database file> defaults to time.db | 20 <getan database file> defaults to time.db |
20 EOF | 21 EOF |
21 exit 1 | 22 exit 1 |
22 } | 23 } |
23 | 24 |
32 #WEEK=`expr ${WEEK} '-' 1 '|' 52` | 33 #WEEK=`expr ${WEEK} '-' 1 '|' 52` |
33 else | 34 else |
34 WEEK=$1 | 35 WEEK=$1 |
35 fi | 36 fi |
36 | 37 |
37 TIME_DB=${2:-time.db} | 38 if [[ "$2" -eq "" ]]; then |
39 YEAR=`date +'%Y'` | |
40 else | |
41 YEAR=$2 | |
42 fi | |
43 | |
44 TIME_DB=${3:-time.db} | |
38 | 45 |
39 if [ ! -f ${TIME_DB} ]; then | 46 if [ ! -f ${TIME_DB} ]; then |
40 echo "error: Database file ${TIME_DB} does not exist." | 47 echo "error: Database file ${TIME_DB} does not exist." |
41 usage | 48 usage |
42 fi | 49 fi |
46 INNER JOIN ( | 53 INNER JOIN ( |
47 SELECT | 54 SELECT |
48 project_id, | 55 project_id, |
49 sum(strftime('%s', stop_time) - strftime('%s', start_time)) AS total | 56 sum(strftime('%s', stop_time) - strftime('%s', start_time)) AS total |
50 FROM entries | 57 FROM entries |
51 WHERE strftime('%W', start_time) = '${WEEK}' OR | 58 WHERE (strftime('%W', start_time) = '${WEEK}' AND |
52 strftime('%W', stop_time) = '${WEEK}' | 59 strftime('%Y', start_time) = '${YEAR}') OR |
60 (strftime('%W', stop_time) = '${WEEK}' AND | |
61 strftime('%Y', stop_time) = '${YEAR}') | |
53 GROUP BY project_id | 62 GROUP BY project_id |
54 ) ON id = project_id | 63 ) ON id = project_id |
55 WHERE active; | 64 WHERE active; |
56 " | awk ' | 65 " | awk ' |
57 function human_time(t) { | 66 function human_time(t) { |