#! perl -w
use strict;
my $ScreenSaverTimeout = 15 * 60;
my $google_reader_hwnd = -1;
sub classify {
my $l = shift;
my @flds = split(m/,\s*/, $l);
my $process = $flds[4];
my $title = $flds[5];
if ($process =~ m!outlook!i) {
return "email";
}
if ($process =~ m!mlpod36|pidgin!i) {
return "im";
}
elsif ($process =~ m!thunderbird!i) {
return "personal-email";
}
elsif ($process =~ m!firefox!i) {
if ($title =~ m!Albion hub|SVN::Web!i) {
return "web-intranet";
}
elsif ($title =~ m!ONYX|QA Defect|oepprod!i) {
return "web-bugs";
}
elsif ($title =~ m!Google Reader!i) {
$google_reader_hwnd = $flds[2];
return "personal-web";
}
elsif ($flds[2] == $google_reader_hwnd) {
# we assume that anything in the same FF window
# as google reader is also personal browsing
return "personal-web";
}
elsif ($title =~ m!you are viewing:.*(application|desktop)!i) {
return "webex";
}
else {
return "web-other";
}
}
elsif ($process =~ m!albion|(pre|post)gui_|ansyswbu!i) {
return "testing";
}
elsif ($process =~ m!wish!i and $title =~ m!ansys!i) {
return "testing";
}
elsif ($process =~ m!mySuiteManager!i) {
return "testing";
}
elsif ($process =~ m!mshta!i and $title =~ m!TestBench!i) {
return "testing";
}
elsif ($process =~ m!Idle!) {
return "idle";
}
elsif ($process =~ m!devenv!i) {
return "coding";
}
elsif ($process =~ m!bash|cmd|putty!i) {
return "other-shell";
}
elsif ($process =~ m!xemacs|notepad2?!i) {
return "other-editing";
}
elsif ($process =~ m!powerpnt|winword!i) {
return "documents";
}
elsif ($process =~ m!explorer!i) {
# known other -- don't print a warning, but
# there's no sensible category for it.
return "other";
}
else {
# unknown other, maybe we need to do add
# something to the table.
print "other: ", $l;
return "other";
}
}
# red => communication
# blue => real work
# green => personal
my %colors =
(
email => 'ff0000',
webex => 'ff7777',
im => 'ff9999',
'web-bugs' => 'ff77aa',
'web-other' => 'ff9900',
'web-intranet' => 'ff7799',
'personal-email' => '99ff00',
'personal-web' => '00ff00',
coding => '0000ff',
testing => '9900ff',
'other-shell' => '0099ff',
'other-editing' => '4499ff',
'other' => '9944ff',
'documents' => '000000',
);
open FILE, ">chart.html" or die $!;
open ACTIVITY, ">activity.xhtml" or die $!;
my $GraphWidth = 800;
print ACTIVITY <<"EOF";
activity chart
activity chart
EOF
close ACTIVITY;
sub write_graph {
my $title = shift;
my %totals = @_;
my $total = 0;
my $non_personal = 0;
for my $class (keys %totals) {
if ($class ne 'idle') {
$total += $totals{$class};
if ($class !~ m!personal!) {
$non_personal += $totals{$class};
}
}
}
my @data;
my @labels;
my @colors;
for my $class (sort keys %totals) {
if ($class ne 'idle') {
push @data, int(($totals{$class} * 100) / $total);
push @labels, $class;
push @colors, defined $colors{$class} ? $colors{$class} : '000000';
}
}
my $url = 'http://chart.apis.google.com/chart?cht=p&chd=t:'
. join(',', @data)
. '&chl=' . join('|', @labels)
. '&chco=' . join(',', @colors)
. '&chs=300x150';
$url =~ s!\&!\&!g;
my $total_fmt = format_secs($total);
my $nonp_fmt = format_secs($non_personal);
print FILE qq($title
Total time $total_fmt; non-personal $nonp_fmt
);
}
sub format_secs {
my $total = shift;
my $hrs = int($total / ( 60 * 60 ));
my $min = int($total / 60 - $hrs * 60);
return "${hrs}h ${min}m";
}