Mercurial > getan
changeset 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 | 1513c716eef0 |
children | e7245c2127e5 |
files | ChangeLog contrib/wochenbericht |
diffstat | 2 files changed, 54 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Jul 30 01:42:38 2008 +0200 +++ b/ChangeLog Thu Jul 31 01:00:42 2008 +0200 @@ -1,3 +1,8 @@ +2008-07-31 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * contrib/wochenbericht: New. Little script to summarize the + entries for a given week number of year. + 2008-07-30 Sascha L. Teichmann <sascha.teichmann@intevation.de> * getan: Added total sum of all projects.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/wochenbericht Thu Jul 31 01:00:42 2008 +0200 @@ -0,0 +1,49 @@ +#!/bin/bash +# +# wochenbericht +# ------------- +# (c) 2008 by Sascha L. Teichmann + +# Little script to summarize times within a given week. +# usage: +# ./wochenbericht [<week of year>] [<getan database file>] +# week defaults to current week, database to time.db +# +# This is Free Software in terms of GPLv3 or later. See +# LICENSE coming with getan for details. +# +if [[ "$1" -eq "" ]]; then + WEEK=`date +'%W'` + # remove hash below if you want previous week + #WEEK=`expr ${WEEK} '-' 1 '|' 52` +else + WEEK=$1 +fi + +TIME_DB=${2:-time.db} + +sqlite3 ${TIME_DB} " +SELECT coalesce(description, 'Verschiedenes'), total FROM projects +INNER JOIN ( + SELECT + project_id, + sum(strftime('%s', stop_time) - strftime('%s', start_time)) AS total + FROM entries + WHERE strftime('%W', start_time) = '${WEEK}' OR + strftime('%W', stop_time) = '${WEEK}' + GROUP BY project_id +) ON id = project_id +WHERE active; +" | awk ' +function human_time(t) { + h = int(t / 3600) + m = int((t % 3600)/60.0 + 0.5) + while (m >= 60) { ++h; m -= 60 } + return sprintf("%2d:%02dh", h, m) +} +BEGIN { FS="|"; sum = 0 } + { sum += $2 + printf("%s: %s\n", human_time($2), $1) + } +END { printf("%s: Gesamt\n", human_time(sum)) } +'