From: Jon Langseth Date: Mon, 13 May 2013 15:27:04 +0000 (+0200) Subject: Added status reporting X-Git-Url: https://git.defcon.no/?a=commitdiff_plain;h=24e69710100f0e151f66ef9e0d7deef8c012cc87;p=trk Added status reporting --- diff --git a/trk b/trk index 83bf87d..710e9ad 100755 --- a/trk +++ b/trk @@ -53,6 +53,7 @@ sub help printf(" %s {projects|list} [verbose]\n", $0); printf(" %s report [{terse|standard|verbose|details}] []\n", $0); printf(" %s edit \n", $0); + printf(" %s status\n", $0); printf("\nSee README.txt for more information\n"); exit(-1); @@ -110,6 +111,16 @@ sub time2str ($) return strftime("%Y-%m-%d %H:%M", localtime($t)); } +sub delta2str ($) +{ + my $delta = shift; + my $t = $delta; + my $hours = $t / 3600; + $t = $delta % 3600; + my $minutes = $t / 60; + return sprintf("%d hours %d minutes", $hours, $minutes); +} + sub parse_arguments ($) { @@ -370,11 +381,7 @@ sub report ($$;$) if ( not $silent ) { - my $t = $delta; - my $hours = $t / 3600; - $t = $delta % 3600; - my $minutes = $t / 60; - printf(" %s to %s => %d hours %d minutes\n", $start, $end, $hours, $minutes); + printf(" %s to %s => %s\n", $start, $end, delta2str($delta) ); } $total += $delta; @@ -384,6 +391,25 @@ sub report ($$;$) } +sub current_starttime (;$) +{ + my $trk_id = shift; + my $wrk_dir = $trk_dir; + $wrk_dir = $trk_dir . "/" . $trk_id if $trk_id; + + my $line = undef; + + my $current = get_current_id( $trk_id ); + open (TRACK, "<" . $wrk_dir . "/" . $current . "/tracking" ) or die ("Unable to open file, $!"); + while ( ) + { + $line = $_; + } + close ( TRACK ); + return 0 if not $line =~ m/\[(\d\d\d\d-\d\d-\d\d \d\d:\d\d)\]/; + return str2time($1); +} + ############################################################ if ( ! -d $trk_dir ) @@ -609,25 +635,52 @@ elsif ( $command eq "report" ) print("\n") if $output >= 1; - my $t = $total; - my $hours = $t / 3600; - $t = $total % 3600; - my $minutes = $t / 60; + printf("Total: %s\n", delta2str($total) ); - printf("Total: %d hours %d minutes\n", $hours, $minutes); if ( $output >= 2 ) { - my $t = $subtotals; - my $hours = $t / 3600; - $t = $subtotals % 3600; - my $minutes = $t / 60; - printf("Time logged on tasks: %d hours %d minutes\n", $hours, $minutes); + printf("Time logged on tasks: %s\n", delta2str($subtotals) ); } print("# End of report\n") if $output >= 1; } +elsif ( $command eq "status" ) +{ + + my $trk_id = get_current_id(); + if ( not $trk_id ) + { + printf("Not currently tracking anything.\n"); + $trk_id = get_last_id(); + if ( $trk_id ) + { + printf("Last track was: %s\n", get_track_name( $trk_id ) ); + } + exit(1); + } + printf("Currently tracking: %s\n", get_track_name( $trk_id ) ); + my $t = current_starttime(); + printf("Tracking started at %s\n", scalar localtime $t); + printf("Time elapsed since start of session: %s\n", delta2str(time - $t) ); + my $activity = get_current_id( $trk_id ); + if ( $activity ) + { + printf("\nCurrent sub-task/activity is: %s\n", get_track_name( $activity, $trk_id ) ); + my $t = current_starttime($trk_id); + printf("Activity started at %s\n", scalar localtime $t); + printf("Time elapsed since start of activity: %s\n", delta2str(time - $t) ); + } + else + { + $activity = get_last_id( $trk_id ); + if ( $activity ) + { + printf("\nLast track was: %s\n", get_track_name( $activity, $trk_id ) ); + } + } +} elsif ( $command eq "edit" ) {