From: Andrew Ruthven Date: Wed, 16 Apr 2008 09:50:56 +0000 (+1200) Subject: More tweaks to output. X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=ical-summary.git More tweaks to output. --- diff --git a/bin/summary-ics.pl b/bin/summary-ics.pl index 997b101..8fe24fa 100755 --- a/bin/summary-ics.pl +++ b/bin/summary-ics.pl @@ -27,7 +27,7 @@ die "Please tell me a filename to work on!\n" die "I can't find the file: $filename\n" unless -f $filename; -print "Processing date range: " . UnixDate($start, '%Y-%m-%d') . " - " . UnixDate($end, '%Y-%m-%d') . "\n"; +print "Processing date range: " . UnixDate($start, '%Y-%m-%d') . " - " . UnixDate($end, '%Y-%m-%d') . "\n\n"; my $parser = iCal::Parser->new( 'start' => UnixDate($start, '%Y%m%d'), @@ -39,6 +39,8 @@ my $cal = $parser->parse($filename); my $events = $cal->{'events'}; my %clients; +my %days; +my $total_hours = 0; use Data::Dumper; for my $year (keys %{ $events }) { @@ -53,7 +55,19 @@ for my $year (keys %{ $events }) { $hours = 8 if defined $events->{$year}{$month}{$day}{$uid}{'allday'}; + $dtstart =~ s/T/ /; + $desc =~ s/\\//g; + + $total_hours += $hours; + + # Days + my ($day) = split(/ /, $dtstart); + $days{$day}{lc($summary)}{'work'}{$desc} += $hours; + $days{$day}{lc($summary)}{'client'} ||= $summary; + + # Clients $clients{lc($summary)}{'work'}{$desc}{'hours'} += $hours; + $clients{lc($summary)}{'hours'} += $hours; $clients{lc($summary)}{'client'} ||= $summary; push @{ $clients{lc($summary)}{'work'}{$desc}{'times'} }, [ $hours, $dtstart ]; #print "event: $summary - $dtstart - $desc\n"; @@ -63,23 +77,63 @@ for my $year (keys %{ $events }) { } } -for my $client (sort keys %clients) { - print "$clients{$client}{'client'}:\n"; - for my $desc (sort keys %{ $clients{$client}{'work'} }) { - print wrap(' ', ' ', $desc) . "\n"; +print_clients_summary(); +print "\n"; +print_clients(); +print "\n"; +print_days(); - for my $time (sort @{ $clients{$client}{'work'}{$desc}{'times'} }) { - print detail_line($time->[0], $time->[1]); - } +print "Total Hours Worked: $total_hours\n\n"; - if (scalar(@{ $clients{$client}{'work'}{$desc}{'times'} }) > 1) { - print detail_line($clients{$client}{'work'}{$desc}{'hours'}, 'Total'); +exit; + +sub detail_line { + my $indent = shift; + return sprintf((' ' x $indent) . "%2.2f - %s\n", @_); +} + +sub print_clients_summary { + $Text::Wrap::columns = 78; + for my $client (sort keys %clients) { + print detail_line(2, $clients{$client}{'hours'}, $clients{$client}{'client'}); + } +} + +sub print_clients { + $Text::Wrap::columns = 78; + for my $client (sort keys %clients) { + print "$clients{$client}{'client'}:\n"; + print detail_line(2, $clients{$client}{'hours'}, 'Client Total'); + print "\n"; + + for my $desc (sort keys %{ $clients{$client}{'work'} }) { + print wrap(' ', ' ', $desc) . "\n"; + + for my $time (sort { $a->[1] cmp $b->[1] } @{ $clients{$client}{'work'}{$desc}{'times'} }) { + print detail_line(4, $time->[0], $time->[1]); + } + + if (scalar(@{ $clients{$client}{'work'}{$desc}{'times'} }) > 1) { + print detail_line(4, $clients{$client}{'work'}{$desc}{'hours'}, 'Total'); + } } + + print "\n"; } - print "\n"; } -sub detail_line { - return sprintf(" %5.2f - %s\n", @_); +sub print_days { + $Text::Wrap::columns = 70; + for my $day (sort keys %days) { + print "$day:\n"; + + for my $client (sort keys %{ $days{$day} }) { + for my $desc (sort keys %{ $days{$day}{$client}{'work'} }) { + print detail_line(2, $days{$day}{$client}{'work'}{$desc}, wrap('', ' ', "$days{$day}{$client}{'client'} - $desc")); + } + } + + print "\n"; + } } - +