#!/mit/perl5/bin/perl -w

use strict;

my $delta=4;
my $threshold=0;
my $your="Abbi";
my $yours=$your."'s";

sub getsec {
    my ($date, $time)=split(" ", $_[0]);
    my ($h,$m,$s)=split(":", $time);
    return $h*3600+$m*60+$s;
}

my $file=$ARGV[0];

open(IN, "$file") || die "Fuck!\n";
my ($crap, $start_time, $end_time, $numPeople, $numSlices);

$_=<IN>;
chomp;
($crap, $start_time)=split(": ", $_);

$_=<IN>;
chomp;
($crap, $end_time)=split(": ", $_);

$_=<IN>;
chomp;
($crap, $numPeople)=split(": ", $_);

$_=<IN>;
chomp;
($crap, $numSlices)=split(": ", $_);

my %peopleActivity;
my ($name, $data);
while(<IN>) {
    chomp;
    ($name, $data)=split("\t", $_);
    @{$peopleActivity{$name}}=split(",", $data);
}
close(IN);

# gawd, top-down programming at its worst.
# OK, now we're finding out all the indices we want to report.  We'll
# store them all here.
my @activeIndices;
my $numberDroppedSlices=0;
my ($i, $activeCount);
for($i=0;$i<=$numSlices;$i++) {
    $activeCount=0;
    foreach $name (keys %peopleActivity) {
	$activeCount++ if (defined($peopleActivity{$name}[$i]) &&
			   $peopleActivity{$name}[$i] eq "X");
    }
    if ($activeCount > $numPeople * $threshold) {
	$activeIndices[$i]=1;
    } else {
	$numberDroppedSlices++;
    }
}
print "thresh: ".($numPeople*$threshold)."\n";

# now that we have all the active indices, now we can do row-by-row
# printing.  *sob*  N^2 programming!  Yes!  Everyone's dream!

print "numberDroppedSlices: $numberDroppedSlices\n";

foreach $name (sort keys %peopleActivity) {
    print "$name";
    print " "x(12-length($name));
    for ($i=0;$i<=$#{$peopleActivity{$name}};$i++) {
	print $peopleActivity{$name}[$i] if defined($activeIndices[$i]);
#	print $peopleActivity{$name}[$i];
    }
    print "\n";
}

################################################################

