#!/usr/bin/perl -w use lib '/home/whelan/pisarcik/pairwise'; use KRACH; use Fcntl; use POSIX 'log10'; use Carp; require 'dumpvar.pl'; use Storable qw(dclone retrieve store); use Getopt::Long; Getopt::Long::config('auto_abbrev'); GetOptions('verbose=s' => \$verb, # Verbose output file 'i|scores=s' => \$infile, # Score input file (default STDIN) 'refweight=f'=> \$refweight, # Weight for ref games in KRACH # (default 0) 'indata=s'=> \$indata, # read the non-TUC data from this file # (instead of calculating it) 'outdata=s'=> \$outdata, # write the non-TUC data to this file 'onetol=f' => \$onetol, # tolerance for one-shot KPct soln 'systol=f' => \$systol); # tolerance for KPct system soln #@time=localtime; #++$time[4]; #foreach (3,4){ # if ($time[$_]<10) {$time[$_]='0'.$time[$_]} #} if (defined $onetol) { Criterion->tol($onetol); } if (defined $systol) { Group->tol($systol); } # $refweight=1 unless defined $refweight; # die "Zero-weighted reference games not yet supported!\n" unless $refweight; %name=( Ab => 'Albany', AF => 'Air Force', Ar => 'Army', BC => 'Boston Coll', Bh => 'Binghamton', Bk => 'Bucknell', Br => 'Brown', Bu => 'Butler', Cg => 'Colgate', Cn => 'Canisius', Cr => 'Cornell', Da => 'Dartmouth', De => 'Delaware', Dk => 'Duke', Dr => 'Drexel', DU => 'Denver', Ff => 'Fairfield', Gt => 'Georgetown', Ha => 'Harvard', Hb => 'Hobart', HC => 'Holy Cross', Hf => 'Hartford', Ho => 'Hofstra', JH => 'Johns Hopkins', Le => 'Lehigh', Lf => 'Lafayette', Lo => 'Loyola', Ma => 'UMass', MB => 'UMBC', Md => 'Maryland', Mh => 'Manhattan', Mr => 'Marist', MS => 'Mt St Mary\'s', Na => 'Navy', NC => 'No. Carolina', ND => 'Notre Dame', OS => 'Ohio State', Pn => 'Pennsylvania', Pr => 'Princeton', PS => 'Penn State', Pv => 'Providence', Qn => 'Quinnipiac', Ru => 'Rutgers', SB => 'Stony Brook', SH => 'Sacred Heart', Si => 'Siena', SJ => 'St. Joseph\'s', Sy => 'Syracuse', To => 'Towson', Va => 'Virginia', Vi => 'Villanova', VM => 'VMI', Vt => 'Vermont', Wa => 'Wagner', Ya => 'Yale'); while (($abbr,$name)=each %name) { new Team(abbr=>$abbr, name=>$name); } if ($indata) { $dataref=retrieve($indata); %Team::TEAM=%{$dataref}; } else { $date=&initscores($infile); warn "Caching KRACH"; if ($refweight) { $ref=new Team; foreach (Team->team) { unless ($ref eq $_) { $ref->game(0,$_,0,weight=>$refweight); } } foreach (Team->team) { $_->krach; } warn $ref->krach; warn 1/(1+1/$ref->krach); delete $Team::TEAM{$ref=$ref->abbr}; foreach $team (Team->team) { foreach (grep {/^_/} keys %{$team}) { next if $_ eq '_pf' or $_ eq '_krach' or $_ eq '_chain' or $_ eq '_t' or $_ eq '_recent'; delete $team->{$_}; } delete $team->{_pf}{$ref}; delete $team->{_chain}[0]{$ref}; delete $team->{_chain}[1]{$ref}; shift @{$team->{_recent}}; shift @{$team->{_recent}}; } } else { foreach (Team->team) { $_->krach; } } warn "Caching RPI"; foreach $team (Team->team) { # warn $team->abbr, $team->rpi; } } if ($outdata) { store(\%Team::TEAM,$outdata); } warn "Sorting by RRWP"; @team = sort {$b->rrwp<=>$a->rrwp} Team->team; if ($verb) { warn "Printing BT table"; sysopen(VERB,$verb,O_WRONLY|O_TRUNC|O_CREAT) or die "Can't open $verb: $!" ; @team = grep {$_->num} @team; # printf VERB "%-13s %2.2f-%2.2f-%2d %4s %4s\n"; $i=0; foreach (@team) { printf VERB "%2d %-13s %5s-%5s-%2d %4s %.5f %.5f\n", ++$i, $_->name , sprintf('%.2f',$_->rrw), sprintf('%.2f',$_->rrl) , $_->rrt, &pct($_->rrwp,'p') , $_->rrw+$_->rrl+$_->rrt-Team->team+1 , $_->rrwp-($_->rrw+$_->rrt/2)/(Team->team-1); } printf VERB "\n%-13s %5s %4s ", '', '', '', ''; foreach (@team) { print VERB substr($_->abbr,0,1); } print VERB "\n"; printf VERB '%-13s %5s %4s ', 'Team', 'KRACH', 'RRWP'; foreach (@team) { print VERB substr($_->abbr,1,1); } foreach (@team) { printf VERB "\n%-13s %5s %4s ", $_->name , &five($_->krach*100), &pct($_->rrwp,'p'); foreach $opp (@team) { print VERB $_->connection($opp); } } print VERB "\n"; @group = grep {($_->teams)[0]->num} Group->group; foreach (@group) {$_->rrwp} @group = sort {$conn = $a->connection($b); return -1 if $conn eq '>' ; return 1 if $conn eq '<' ; return $b->rrwp <=> $a->rrwp} @group; print VERB ' '; foreach (@group) { print VERB $_->abbr; } print VERB "\n"; foreach $group (@group) { print VERB $group->abbr, ' '; foreach (@group) { print VERB ' ',$group->connection($_); } print VERB "\n"; } foreach $group (@group) { # warn $group->abbr; # warn $group->connected('>'); # warn $group->connected('<'); print VERB "\nGroup ", $group->abbr, "\n"; if ($group->connected('>')) { print VERB "Better than:", map({(' ',$_->abbr)} $group->connected('>')), "\n"; } if ($group->connected('<')) { print VERB "Worse than:", map({(' ',$_->abbr)} $group->connected('<')), "\n"; } } $n=0; foreach $group (@group) { print VERB "\nGroup ",++$n,":\n"; @team=sort {$b->rrwp <=> $a->rrwp} $group->teams; print VERB "Ratings and intra-group HHWPs:\n"; printf VERB '%-13s %4s %5s'.(' %4s'x@team)."\n",'','RRWP','KRACH' , map {$_->abbr.' '} @team; foreach $team (@team) { printf VERB '%-13s %4s %5s'.(' %4s'x@team)."\n",$team->name, &pct($team->rrwp,'p'),&five($team->krach*100), map {&pct($team->hhwp($_),'p')} @team; } if ($team[0]->connected('>')) { print VERB "All teams in the group have HHWPs of 1.000 with:\n", map({(' ',$_->abbr)} $team[0]->connected('>')), "\n"; } if ($team[0]->connected('<')) { print VERB "All teams in the group have HHWPs of .000 with:\n", map({(' ',$_->abbr)} $team[0]->connected('<')), "\n"; } if ($team[0]->connected('?')) { print VERB "All teams in the group have undefined HHWPs with:\n", map({(' ',$_->abbr)} grep {$_->num} $team[0]->connected('?')), "\n"; } } } sub initscores { my $infile=shift; my ($date,$team1,$score1,$team2,$score2,$fh); if ($infile) { sysopen (SCORES, $infile, O_RDONLY) or die $!; $fh = *SCORES; } else { $fh = *STDIN; } while (<$fh>) { ($date,$team1,$score1,$team2,$score2)=split; if (exists $name{$team1} and exists $name{$team2}) { Team->game($team1=>$score1, $team2=>$score2); } } if ($infile) { close SCORES or die $!; } return $date; } sub pct { my $pf=shift; my $pa=shift; my $pct; if ($pa eq 'p') { $pct=$pf; } else { if ($pf+$pa) { $pct=$pf/($pf+$pa); } else { return '.---'; } } if ($pct==1) { return '1.000'; } elsif ($pct eq '00.5') { return '.---'; } elsif (substr($pct,0,2) eq '00') { return ','.substr(sprintf("%0.3f",$pct),2,3); } else { return substr(sprintf("%0.3f",$pct),1,4); } } sub five { my ($num)=@_; my $f=4-int(1+log10($num)); $f=0 if ($f<0); # warn $num; # warn $f; $num=sprintf("%.${f}f",$num); # warn $num; $num =~ s/^0//; # warn $num; return $num; }