# FILE fhscocomb.pl working copy running time 17 sec
#============= CREATE SCORES PAGE ===================
$scofile='FHsco01.txt';
open (SCORES,"<$scofile") || die "Can't open $scorefile $!";
open (SCORESHTML, ">fhscores01.html");
print SCORESHTML "
CIAU Field Hockey scores 2001
\n
FH Scores 2001";
open (SCORESHTML, ">>fhscores01.html");
while () {
($date,$Tm1,$Sco1,$Tm2,$Sco2,$GmType,$Notes) = split(':',$_);
### Flag any reversed score, stops program, prints line to warn
if ($Sco1 < $Sco2) {
die
print "$date $Tm1 $Sco1 $Tm2 $Sco2 $GmType $Notes";
}
if ($Tm1 le " ") { # print date if alone on datafile row
print SCORESHTML "
$date";
}
#elsif ($date =~ /..../) {
# print SCORESHTML "
$date";
#}
elsif ($Tm1 gt " ") { #print score lines without dates
print SCORESHTML "
$Tm1 $Sco1 $Tm2 $Sco2 $GmType $Notes";
}
}
print SCORESHTML ""; #close HTML file
close SCORESHTML;
#====================================================
#### TEAM-BY-TEAM SCORES ###
#====================================================
$scofile='FHsco01.txt';
open (SCORES,"<$scofile") || die "Can't open $scorefile $!";
open (TEAMDATA, ">fhteams01.html");
print TEAMDATA "
";
@TeamName = ("Saint Mary's", "UNB", "UPEI",
"Queen's", "Carleton", "McGill",
"Toronto", "Trent", "York",
"Guelph", "Waterloo", "Western",
"Alberta", "Calgary", "Manitoba", "Victoria", "UBC",);
foreach $team (@TeamName) {
open (TEAMDATA, ">>fhteams01.html");
print TEAMDATA "$team\n";
open (SCORES,"<$scofile") || die "Can't open $scorefile $!";
while () {
($Date,$Tm1,$Sco1,$Tm2,$Sco2,$GmType,$Notes) = split(':',$_);
if ($Tm1 eq $team || $Tm2 eq $team) {
print TEAMDATA "
$Date $Tm1 $Sco1 $Tm2 $Sco2 $GmType $Notes\n";
}
}
}
print TEAMDATA "";
#====================================================
#### CREATING STANDINGS MDA file ###
#====================================================
$scofile='FHsco01.txt';
open (FHMDA, ">fhstand.txt") || die "Can't open fhstand.txt $!";
print FHMDA "";
@TeamName = ("Saint Mary's", "UNB", "UPEI",
"Queen's", "Carleton", "McGill",
"Toronto", "Trent", "York",
"Guelph", "Waterloo", "Western",
"Alberta", "Calgary", "Manitoba", "Victoria", "UBC",);
foreach $team (@TeamName) {
open (SCORES,"<$scofile") || die "Can't open $scorefile $!";
open (FHMDA, ">>fhstand.txt") || die "Can't open fhstand.txt $!";
($teamwins, $teamlosses, $pfor, $Against, $WLpct) =0; # initialize counts
$teamlosses=0; $teamgp=0; $teamties=0; $pfor=0; $Against=0;
$WLpct=0; $Margin=0; $Pts=0; $WLpct=0; $pfpg=0; $papg=0; $mgp=0;
# while reading SCORES (FHsco01.txt) line-by-line
# parse it at colons : into standings variables
while () {
($date,$Tm1,$Sco1,$Tm2,$Sco2,$GmType,$Notes) = split(':',$_);
#-------------------------------------------
# BEGIN calculation of standings variables.
#-------------------------------------------
if ($Tm1 eq $team and $GmType eq "" and $Notes !~ /TIE/ ) {
# selects Conference only
++$teamgp; ++$teamwins ; # counts name in winner column
$pfor = ($pfor + $Sco1); # adds winner's score to FOR
$Against = ($Against + $Sco2); # adds loser's score to AGAINST
}
elsif ($Tm2 eq $team && $GmType eq "" && $Notes !~ /TIE/ ) {
++$teamgp; ++$teamlosses ; # counts name in loser column
$pfor = ($pfor + $Sco2); # adds loser's score to FOR
$Against = ($Against + $Sco1); # adds winner's score to AGAINST
}
elsif (($Tm2 eq $team || $Tm1 eq $team) && $GmType eq "" && $Notes =~ "TIE" ) {
++$teamgp; ++$teamties;
$pfor = ($pfor + $Sco1); # adds tie score to FOR
$Against = ($Against + $Sco1); # adds tie score to AGAINST
}
$Margin = ($pfor - $Against); # Calculates +/- diff
if ($team =~ /Carleton|McGill|Queen's|Toronto|Trent|York|Guelph|Waterloo|Western/) {
$Pts = (3 * $teamwins) + $teamties;
}
elsif ($team =~ /Saint Mary's|UNB|UPEI|Alberta|Calgary|Manitoba||UBC|Victoria/) {
$Pts = (2 * $teamwins) + $teamties;
}
if ($teamgp == 0) { #NEW
$WLpct = 1.000 ; #NEW
} #NEW
# calc W/L %, elim div by zero
elsif ($teamlosses == 0 and $teamties == 0 and $teamgp != 0) {
$WLpct = 1.000; #NEW > > > > > > >
}
else {
$WLpct = ( ($teamwins + ($teamties * .5 )) / $teamgp );
}
if ($teamgp != 0) {
$pfpg = ($pfor / $teamgp);
$papg = ($Against / $teamgp);
$mgp = ($Margin / $teamgp);
}
if ($team =~ /Saint Mary's|UNB|UPEI/) {
$conf = "aAU";
}
elsif ($team =~ /Carleton|McGill|Queen's/) {
$conf = "bOUE";
}
elsif ($team =~ /Toronto|Trent|York/) {
$conf = "cOUC";
}
elsif ($team =~ /Guelph|Waterloo|Western/) {
$conf = "dOUW";
}
elsif ($team =~ /Alberta|Calgary|Manitoba||UBC|Victoria/) {
$conf = "eCW";
}
}
# END calculation of standings variables for Team.
print FHMDA "$team:$conf:$teamgp:$teamwins:$teamlosses:$teamties:$pfor:$Against:$Margin:$Pts:$WLpct:$pfpg:$papg:$mgp\n";
}
close FHMDA;
#====================================================
#### SORTING STANDINGS ###
#====================================================
$stanfile='fhstand.txt';
open (FHMDA, ";
@mdasorted = map { $_->[0] }
sort {
$a->[2] cmp $b->[2]
|| $b->[10] <=> $a->[10]
|| $b->[11] <=> $a->[11]
|| $b->[14] <=> $a->[14]
|| $a->[1] cmp $b->[1]
}
map { [ $_, (split /:/, $_,) ] }
@mda;
open (STANHTML, ">fhstand01.html");
print STANHTM "";
open (STANHTML, ">>fhstand01.html");
open (STANAUS, ">fhstanaus.txt");
open (STANOUE, ">fhstanoue.txt");
open (STANOUC, ">fhstanouc.txt");
open (STANOUW, ">fhstanouw.txt");
open (STANCW, ">fhstancw.txt");
print STANAUS @mdasorted[0 .. 2]; ##AUS .. begins zero
print STANOUE @mdasorted[3 .. 5]; ##OUAE
print STANOUC @mdasorted[6 .. 8]; ##OUAC
print STANOUW @mdasorted[9 .. 11]; ##OUAW
print STANCW @mdasorted[12 .. 16]; ##CanWest
##======================================================
print STANHTML "
FH Standings 2001
2001 Field Hockey Standings |
";
##======================================================
##================AUS=======================
print STANHTML "
Atlantic | W | L | T | F | A | P | Pct | |
";
open (STANAUS, ") {
($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);
$tmpct = sprintf("%.3f", $tmpct); ## converts to 3 places
$tmpct =~ s/^0/ /g; ## replace Leading Zeros
print STANHTML "
$tm | $tmw | $tml | $tmt | $tmf | $tma | $tmpts | $tmpct | |
";
}
##================OUE=======================
print STANHTML "
OUA East | W | L | T | F | A | P | Pct | |
";
open (STANOUE, ") {
($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);
$tmpct = sprintf("%.3f", $tmpct); ## converts to 3 places
$tmpct =~ s/^0/ /g; ## replace Leading Zeros
print STANHTML "
$tm | $tmw | $tml | $tmt | $tmf | $tma | $tmpts | $tmpct | |
";
}
##================OUC=======================
print STANHTML "
OUA Central | W | L | T | F | A | P | Pct | |
";
open (STANOUC, ") {
($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);
$tmpct = sprintf("%.3f", $tmpct); ## converts to 3 places
$tmpct =~ s/^0/ /g; ## replace Leading Zeros
print STANHTML "
$tm | $tmw | $tml | $tmt | $tmf | $tma | $tmpts | $tmpct | |
";
}
##================OUW=======================
print STANHTML "
OUA West | W | L | T | F | A | P | Pct | |
";
open (STANOUW, ") {
($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);
$tmpct = sprintf("%.3f", $tmpct); ## converts to 3 places
$tmpct =~ s/^0/ /g; ## replace Leading Zeros
print STANHTML "
$tm | $tmw | $tml | $tmt | $tmf | $tma | $tmpts | $tmpct | |
";
}
##================CW=======================
print STANHTML "
CanWest | W | L | T | F | A | P | Pct | |
";
open (STANCW, ") {
($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);
$tmpct = sprintf("%.3f", $tmpct); ## converts to 3 places
$tmpct =~ s/^0/ /g; ## replace Leading Zeros
print STANHTML "
$tm | $tmw | $tml | $tmt | $tmf | $tma | $tmpts | $tmpct | |
";
}
print STANHTML "
";
### END STANDINGS PAGE ###
## Tm conf g w l t f a m p % fgp agp mgp
##York:aAUS:8:3:5:0:99:205:-106:6:0.375:12.375:25.625:-13.25
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14
#------------------------------------------------------------------
#------------------------------------------------------------------
### PREPARE HIGH SCORING PAGE ###
open (HIGHHTML, ">fhhigh01.html") || die "Can't open $stanfile $!";
print HIGHHTML "";
print HIGHHTML "
FH Highest Scoring 2001
2001 Team Comparisons sorted by:
|
High Scoring | W | L | T | F | A | P | Fpg | |
";
open (FHMDA, ";
@mdasorted = map { $_->[0] }
sort {
$b->[12] <=> $a->[12]
|| $b->[10] <=> $a->[10]
|| $b->[11] <=> $a->[11]
|| $b->[14] <=> $a->[14]
|| $a->[1] cmp $b->[1]
}
map { [ $_, (split /:/, $_,) ] }
@mda;
open (FHSTANFILE, ">fhstandtemp.txt") || die "Can't open $stanfile $!";
print FHSTANFILE @mdasorted;
open (FHSTANFILE, ") {
($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);
$pfg = sprintf("%.1f", $pfg); ## converts to 1 place
print HIGHHTML "
$tm | $tmw | $tml | $tmt | $tmf | $tma | $tmpts | $pfg | |
";
}
print HIGHHTML "
";
### END HIGH SCORING PAGE ###
#------------------------------------------------------------------
#------------------------------------------------------------------
### PREPARE LEAST SCORED ON PAGE ###
print LEASTHTML "";
open (LEASTHTML, ">fhleast01.html") || die "Can't open $stanfile $!";
print LEASTHTML "";
print LEASTHTML "
FH Least Scored On 2001
2001 Team Comparisons sorted by:
|
Least Against | W | L | T | F | A | P | Apg | |
";
open (FHMDA, ";
@mdasorted = map { $_->[0] }
sort {
$a->[13] <=> $b->[13]
|| $b->[10] <=> $a->[10]
|| $b->[11] <=> $a->[11]
|| $b->[14] <=> $a->[14]
|| $a->[1] cmp $b->[1]
}
map { [ $_, (split /:/, $_,) ] }
@mda;
open (FHSTANFILE, ">fhstandtemp.txt") || die "Can't open $stanfile $!";
print FHSTANFILE @mdasorted;
open (FHSTANFILE, ") {
($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);
$pag = sprintf("%.1f", $pag); ## converts to 1 place
print LEASTHTML "
$tm | $tmw | $tml | $tmt | $tmf | $tma | $tmpts | $pag | |
";
}
print LEASTHTML "
";
### END LEAST SCORED ON PAGE ###
#------------------------------------------------------------------
#------------------------------------------------------------------
### PREPARE MARGIN PAGE ###
print LEASTHTML "";
open (MARGHTML, ">fhmargin01.html") || die "Can't open $stanfile $!";
print MARGHTML "";
print MARGHTML "
FH Least Scored On 2001
2001 Team Comparisons sorted by:
|
WL Margin | W | L | T | F | A | P | Mpg | |
";
open (FHMDA, ";
@mdasorted = map { $_->[0] }
sort {
$b->[14] <=> $a->[14]
|| $b->[10] <=> $a->[10]
|| $b->[11] <=> $a->[11]
|| $a->[1] cmp $b->[1]
}
map { [ $_, (split /:/, $_,) ] }
@mda;
open (FHSTANFILE, ">fhstandtemp.txt") || die "Can't open $stanfile $!";
print FHSTANFILE @mdasorted;
open (FHSTANFILE, ") {
($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);
$pmg = sprintf("%.1f", $pmg); ## converts to 1 place
print MARGHTML "
$tm | $tmw | $tml | $tmt | $tmf | $tma | $tmpts | $pmg | |
";
}
print MARGHTML "
";
### END MARGIN PAGE ###
#------------------------------------------------------------------
#------------------------------------------------------------------
### PREPARE WL PERCENT PAGE ###
open (PCTHTML, ">fhpercent01.html") || die "Can't open $stanfile $!";
print PCTHTML "";
print PCTHTML "
FH Least Scored On 2001
2001 Team Comparisons sorted by:
|
WL Percent | W | L | T | F | A | P | Pct | |
";
open (FHMDA, ";
@mdasorted = map { $_->[0] }
sort {
$b->[11] <=> $a->[11]
|| $b->[10] <=> $a->[10]
|| $b->[14] <=> $a->[14]
|| $a->[1] cmp $b->[1]
}
map { [ $_, (split /:/, $_,) ] }
@mda;
open (FHSTANFILE, ">fhstandtemp.txt") || die "Can't open $stanfile $!";
print FHSTANFILE @mdasorted;
open (FHSTANFILE, ") {
($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);
$tmpct = sprintf("%.3f", $tmpct); ## converts to 3 places
$tmpct =~ s/^0/ /g; ## replace Leading Zeros
print PCTHTML "
$tm | $tmw | $tml | $tmt | $tmf | $tma | $tmpts | $tmpct | |
";
}
print PCTHTML "
";
### END WL PERCENT PAGE ###
#------------------------------------------------------------------
#------------------------------------------------------------------