cuervo72
12-06-2006, 08:21 PM
Probably of little usefulness, but I figure what the heck, kinda been wanting to share it...if anyone can figure out what it does anyway. Maybe it gives you some ideas.
#!/usr/bin/perl
require 'global.pl';
$team = 19;
$away = 0;
print "<a href=$file>$file</a>\n";
$pk2b = ($parks{$team}[0] + $parks{$away}[0])/200;
$pk3b = ($parks{$team}[1] + $parks{$away}[1])/200;
$pkAVG{'R'}{'R'} = $pkAVG{'R'}{'L'} = $pkAVG{'S'}{'L'} = ($parks{$team}[2] + $parks{$away}[2])/200;
$pkHR{'R'}{'R'} = $pkHR{'R'}{'L'} = $pkHR{'S'}{'L'} = ($parks{$team}[3] + $parks{$away}[3])/200;
$pkAVG{'L'}{'R'} = $pkAVG{'L'}{'L'} = $pkAVG{'S'}{'R'} = ($parks{$team}[4] + $parks{$away}[4])/200;
$pkHR{'L'}{'R'} = $pkHR{'L'}{'L'} = $pkHR{'S'}{'R'} = ($parks{$team}[5] + $parks{$away}[5])/200;
$file = "hit" . $team . ".html";
open (P, ">$file");
print P <<EOT;
<html><head><title>$teams{$team} Batting</title>
<link rel="stylesheet" type="text/css" href="http://reference.thefobl.com/fbr/site.css">
<style type="text/css">
<!--
body {background-color:#ddba97;margin-left:10px;margin-top:10px;font-family:Verdana,sans-serif;}
table {border-spacing:1px;border-collapse:collapse;border:1px solid #cc9966;background-color:#e7ceb6;font-family:Verdana,sans-serif; font-color=white;}
table.s0 {width:702px;border:1px solid #cc9966;background-color:#005151;}
-->
</style>
</head><body>
EOT
$directory = "2021/EOY";
$bat_file = "$directory/bat_stats.csv";
$names_file = "$directory/players.csv";
processBat(0);
processPlayer(0);
$directory = "2022/EOY";
$bat_file = "$directory/bat_stats.csv";
$names_file = "$directory/players.csv";
processBat(0);
processPlayer(0);
$directory = "2023/EOY";
$bat_file = "$directory/bat_stats.csv";
$names_file = "$directory/players.csv";
processBat(0);
processPlayer(0);
$directory = "2024/SIM16";
$bat_file = "$directory/bat_stats.csv";
$names_file = "$directory/players.csv";
$field_file = "$directory/player_field.csv";
processBat(0);
processField();
processPlayer(0,1);
@tradeblock = (2229,2226,1703,357,2109,1700,1760,73,1711,1895,1811,1058);
@lightning = (593,1150,1207,1928,2038,1433,862,1118,2092,1111,2250,1263,1134,1258,2151,1147,717,468,1926,384,1360,1462,966);
%hbp = (1150,4,2038,6,2250,5,1118,9,862,1,1433,7,1111,5,1263,6,1134,9,2151,10,1258,4,1147,27,2092,5,389,7,1207,6,2229,6,593,9,2226,8,1703,9,157,5,1180,8,1928,26,267,1,780,4,1969,2,235,6,1843,9,10,22,1061,12,946,17,1345,27,1810,19,1926,18,795,21,717,7,1462,9,384,7,1360,5,717,7,1462,9,1360,5,384,7,468,1);
$numab_r = 510;
$numab_l = 170;
$numab_o = $numab_r + $numab_l;
print P "<h2 class=pagetitle>$teams{$team}</h2>\n";
print P "2B: $pk2b, 3B: $pk3b, RAVG: $pkAVG{'R'}{'R'}, RHR: $pkHR{'R'}{'R'}, LAVG: $pkAVG{'L'}{'R'}, LHR: $pkHR{'L'}{'R'}<p>\n";
printArray(@roster);
sub printArray {
print P "<table class=s0 border=1><tr class=colheader><th>Player</th><th>AB</th><th>H</th><th>2B</th><th>3B</th><th>HR</th><th>BB</th><th>AVG</th><th>OBP</th><th>SLG</th><th>OPS</th><th>XR</th><th>HBP</th></tr>\n";
@list = @_;
foreach $p (@list) {
if ($pos{$p} >= 1) {
if (($r_bb_stats{$hand{$p}}[$r_bb{$p}] + $r_bb_ab{$hand{$p}}[$r_bb{$p}]) < 1) {print "NONONONONO $p $pos{$p}";}
print P "<tr align=right class=oddlinestats><td rowspan=3 valign=top><strong><a href=\"http://www.thefobl.com/fobl/p$p.html\">$name{$p}</a>";
if ($hbp{$p} eq "") {$hbp{$p} = 5; print P "*";}
print P ", $positions{$pos{$p}}, $age{$p}, $hand{$p}</strong><br>$teams{$oldteam{$p}}/$teams{$team{$p}}<br><b>$level{$p}</b> \$ " . $sal{$p} . "<br> <b>Spd: $dur{$speed{$p}} </b>/ <b>Sta: $dur{$steal{$p}} </b> ";
foreach $k (keys %positions){
if ($field{$p}{$k} ne "") {
print P "<b>/ $positions{$k}:$dur{$field{$p}{$k}}</b> ";
}
}
print P "</td>\n";
$rhbp = precision($numab_r * $hbp{$p}/550,0);
$rwalks = precision(($numab_r - $rhbp) * $r_bb_stats{$hand{$p}}[$r_bb{$p}] / ($r_bb_stats{$hand{$p}}[$r_bb{$p}] + $r_bb_ab{$hand{$p}}[$r_bb{$p}]) ,0);
$ratbats = $numab_r - $rhbp - $rwalks;
$rhits = precision($pkAVG{$hand{$p}}{'R'} * $ratbats * $r_h_stats{$hand{$p}}[$r_avg{$p}]/$r_ab_stats{$hand{$p}}[$r_avg{$p}],0);
$ravg = precision($rhits/$ratbats,3);
$robp = precision(($rhits + $rwalks + $rhbp)/$numab_r,3);
$rhr = precision($pkHR{$hand{$p}}{'R'} * $ratbats * $r_hr_stats{$hand{$p}}[$r_hr{$p}]/$r_hr_ab{$hand{$p}}[$r_hr{$p}],0);
$r2b = precision($pk2b * $ratbats * $r_2b_stats{$hand{$p}}[$r_2b{$p}]/$r_2b_ab{$hand{$p}}[$r_2b{$p}],0);
$r3b = precision($pk3b * $ratbats * $r_3b_stats{$hand{$p}}[$r_3b{$p}]/$r_3b_ab{$hand{$p}}[$r_3b{$p}],0);
$rslug = precision(($rhits + $r2b + 2*$r3b + 3*$rhr)/$ratbats,3);
$rops = $rslug + $robp;
$r1b = $rhits - $rhr - $r2b - $r3b;
$rXR = ($r1b*.50)+($r2b*.72)+($r3b*1.04)+($rhr*1.44)+(($rwalks+$rhbp)*.33)-(($numab_r-$rhits-$rwalks-$rhbp)*.098);
print P "<td>$ratbats</td><td>$rhits</td><td>$r2b</td> <td>$r3b</td><td>$rhr</td><td>$rwalks</td><td>$ravg (" . precision($r_h_stats{$hand{$p}}[$r_avg{$p}]/$r_ab_stats{$hand{$p}}[$r_avg{$p}],3) . ")</td><td>$robp</td><td>$rslug</td><td>$rops</td><td>$rXR</td><td>$rhbp</td></tr>\n";
$lhbp = precision($numab_l * $hbp{$p}/550,0);
$lwalks = precision(($numab_l - $lhbp) * $l_bb_stats{$hand{$p}}[$l_bb{$p}] / ($l_bb_stats{$hand{$p}}[$l_bb{$p}] + $l_bb_ab{$hand{$p}}[$l_bb{$p}]) ,0);
$latbats = $numab_l - $lhbp - $lwalks;
$lhits = precision($pkAVG{$hand{$p}}{'L'} * $latbats * $l_h_stats{$hand{$p}}[$l_avg{$p}]/$l_ab_stats{$hand{$p}}[$l_avg{$p}],0);
$lavg = precision($lhits/$latbats,3);
$lobp = precision(($lhits + $lwalks + $lhbp)/$numab_l,3);
$lhr = precision($pkHR{$hand{$p}}{'L'} * $latbats * $l_hr_stats{$hand{$p}}[$l_hr{$p}]/$l_hr_ab{$hand{$p}}[$l_hr{$p}],0);
$l2b = precision($pk2b * $latbats * $l_2b_stats{$hand{$p}}[$l_2b{$p}]/$l_2b_ab{$hand{$p}}[$l_2b{$p}],0);
$l3b = precision($pk3b * $latbats * $l_3b_stats{$hand{$p}}[$l_3b{$p}]/$l_3b_ab{$hand{$p}}[$l_3b{$p}],0);
$lslug = precision(($lhits + $l2b + 2*$l3b + 3*$lhr)/$latbats,3);
$lops = $lslug + $lobp;
$l1b = $lhits - $lhr - $l2b - $l3b;
$lXR = ($l1b*.50)+($l2b*.72)+($l3b*1.04)+($lhr*1.44)+(($lwalks+$lhbp)*.33)-(($numab_l-$lhits-$lwalks-$lhbp)*.098);
print P "<tr align=right class=evenlinestats> <td>$latbats</td><td>$lhits</td><td>$l2b</td> <td>$l3b</td><td>$lhr</td><td>$lwalks</td><td>$lavg " . precision($l_h_stats{$hand{$p}}[$l_avg{$p}]/$l_ab_stats{$hand{$p}}[$l_avg{$p}],3) . "</td><td>$lobp</td><td>$lslug</td><td>$lops</td><td>$lXR</td><td>$lhbp</td></tr>\n";
$ohbp = $lhbp + $rhbp;
$owalks = $lwalks + $rwalks;
$oatbats = $latbats + $ratbats;
$ohits = $lhits + $rhits;
$oavg = precision(($ohits/$oatbats),3);
$oobp = precision(($ohits + $owalks + $ohbp)/($oatbats + $owalks + $ohbp),3);
$ohr = $lhr + $rhr;
$o2b = $l2b + $r2b;
$o3b = $l3b + $r3b;
$oslug = precision(($ohits + $o2b + 2*$o3b + 3*$ohr)/$oatbats,3);
$oops = $oslug + $oobp;
$o1b = $ohits - $ohr - $o2b - $o3b;
$oXR = ($o1b*.50)+($o2b*.72)+($o3b*1.04)+($ohr*1.44)+(($owalks+$ohbp)*.33)-(($numab_o-$ohits-$owalks-$ohbp)*.098);
print P "<tr align=right class=totallinestats> <td>$oatbats</td><td>$ohits</td><td>$o2b</td> <td>$o3b</td><td>$ohr</td><td>$owalks</td><td>$oavg</td><td>$oobp</td><td>$oslug</td><td>$oops</td><td><strong>$oXR</strong></td><td>$ohbp</td></tr>\n";
}
}
print P "</table>\n";
}
sub printRowAVG {
local($H,$P) = @_;
print P "<TR><TH>" . $H . "HB vs $P</TH>\n";
#${$current[1] . _AB}
for ($i = 1; $i<=9; $i++) {
if((${$P . _ab_stats}{$H}[$i] eq "") || (${$P . _ab_stats}{$H}[$i] == 0)) { ${$P . _ab_stats}{$H}[$i] = 1;}
print "<td>" . precision(${$P . _h_stats}{$H}[$i]/${$P . _ab_stats}{$H}[$i],3) . "</td>\n";
}
print P "</TR>\n";
}
sub printRowHR {
local($H,$P) = @_;
print P "<TR><TH>" . $H . "HB vs $P</TH>\n";
#${$current[1] . _AB}
for ($i = 1; $i<=14; $i++) {
if(${$P . _hr_ab}{$H}[$i] eq "") { ${$P . _hr_ab}{$H}[$i] = 1;}
#print "<td>" . precision(${$P . _hr_ab}{$H}[$i]/${$P . _hr_stats}{$H}[$i],3) . "`(${$P . _hr_ab}{$H}[$i]/${$P . _hr_stats}{$H}[$i])</td>\n";
print P "<td>" . precision(600*${$P . _hr_stats}{$H}[$i]/${$P . _hr_ab}{$H}[$i],1) . "</td>\n";
}
print P "</TR>\n";
}
sub printRowBB {
local($H,$P) = @_;
print P "<TR><TH>" . $H . "HB vs $P</TH>\n";
#${$current[1] . _AB}
for ($i = 1; $i<=13; $i++) {
if((${$P . _bb_ab}{$H}[$i] eq "") || (${$P . _bb_ab}{$H}[$i] == 0)) { ${$P . _bb_ab}{$H}[$i] = 1;}
#print "<td>" . precision(${$P . _hr_ab}{$H}[$i]/${$P . _hr_stats}{$H}[$i],3) . "`(${$P . _hr_ab}{$H}[$i]/${$P . _hr_stats}{$H}[$i])</td>\n";
print P "<td>" . precision(600*${$P . _bb_stats}{$H}[$i]/${$P . _bb_ab}{$H}[$i],1) . "</td>\n";
}
print P "</TR>\n";
}
sub printRow2B {
local($H,$P) = @_;
print P "<TR><TH>" . $H . "HB vs $P</TH>\n";
#${$current[1] . _AB}
for ($i = 1; $i<=9; $i++) {
if((${$P . _2b_ab}{$H}[$i] eq "") || (${$P . _2b_ab}{$H}[$i] == 0)) { ${$P . _2b_ab}{$H}[$i] = 1;}
#print "<td>" . precision(${$P . _hr_ab}{$H}[$i]/${$P . _hr_stats}{$H}[$i],3) . "`(${$P . _hr_ab}{$H}[$i]/${$P . _hr_stats}{$H}[$i])</td>\n";
print P "<td>" . precision(600*${$P . _2b_stats}{$H}[$i]/${$P . _2b_ab}{$H}[$i],1) . "</td>\n";
}
print P "</TR>\n";
}
sub printRow3B {
local($H,$P) = @_;
print P "<TR><TH>" . $H . "HB vs $P</TH>\n";
#${$current[1] . _AB}
for ($i = 1; $i<=9; $i++) {
if((${$P . _3b_ab}{$H}[$i] eq "") || (${$P . _3b_ab}{$H}[$i] == 0)) { ${$P . _3b_ab}{$H}[$i] = 1;}
#print "<td>" . precision(${$P . _hr_ab}{$H}[$i]/${$P . _hr_stats}{$H}[$i],3) . "`(${$P . _hr_ab}{$H}[$i]/${$P . _hr_stats}{$H}[$i])</td>\n";
print P "<td>" . precision(600*${$P . _3b_stats}{$H}[$i]/${$P . _3b_ab}{$H}[$i],1) . "</td>\n";
}
print P "</TR>\n";
}
sub processNames {
open(NAME,"$names_file");
while(<NAME>){
chomp();
@current = split(/,/);
$lname{$current[0]} = $current[1];
$fname{$current[0]} = $current[2];
$team_id{$current[0]} = $current[145];
$age{$current[0]} = $current[19];
}
close(NAME);
}
sub processBat {
local($offset) = @_;
open(BAT,"$bat_file");
<BAT>;
while(<BAT>){
chomp();
@current = split(/,/);
$newID = $current[0] + $offset;
if (($current[1] eq 'VSR')||($current[1] eq 'VSL')) {
${$current[1] . _AB}{$newID} = $current[5];
${$current[1] . _H}{$newID} = $current[6];
${$current[1] . _2B}{$newID} = $current[12];
${$current[1] . _3B}{$newID} = $current[13];
${$current[1] . _HR}{$newID} = $current[14];
${$current[1] . _BB}{$newID} = $current[19];
}
}
close(BAT);
#print "$HOME_BAT{1}";
}
sub processPlayer {
local($offset,$roster) = @_;
#open(OUTPUT,">$output_file");
open(PLAYER,"$names_file") || print "can't open names\n";
$count = 0;
<PLAYER>;
while(<PLAYER>){
chomp();
s/\.\./\./g;
s/\"//g;
@current = split(/,/);
if ( $current[20] != 1 ){
$newID = $current[0] + $offset;
$name{$newID} = "$current[2] $current[1]";
$hand{$newID} = $current[4];
$age{$newID} = $current[19];
$exp{$newID} = $current[30];
#$o_avg{$newID} = $current[44];
#$o_2b{$newID} = $current[45];
#$o_hr{$newID} = $current[47];
#$o_bb{$newID} = $current[48];
$r_avg{$newID} = $current[50];
$r_2b{$newID} = $current[51];
$r_3b{$newID} = $current[52];
$r_hr{$newID} = $current[53];
$r_bb{$newID} = $current[54];
$l_avg{$newID} = $current[56];
$l_2b{$newID} = $current[57];
$l_3b{$newID} = $current[58];
$l_hr{$newID} = $current[59];
$l_bb{$newID} = $current[60];
$t_avg{$newID} = $current[62];
$team{$newID} = $current[145];
$speed{$newID} = $current[150];
$steal{$newID} = $current[151];
if ($team == $current[145] && ($current[146] eq "AAA" || $current[146] eq "Active" || $current[146] eq "DL" || $current[146] eq "AX") && $roster) {
$level{$newID} = $current[146];
push(@roster,$newID);
}
if ($directory eq "2023/EOY") { $oldteam{$newID} = $current[145]; $lsal{$newID} = $current[38]; }
$sal{$newID} = $current[38];
$pos{$newID} = $current[20];
$count++;
$l_ab_stats{$hand{$newID}}[$l_avg{$newID}] = $VSL_AB{$newID} + $l_ab_stats{$hand{$newID}}[$l_avg{$newID}];
$l_h_stats{$hand{$newID}}[$l_avg{$newID}] = $VSL_H{$newID} + $l_h_stats{$hand{$newID}}[$l_avg{$newID}];
$r_ab_stats{$hand{$newID}}[$r_avg{$newID}] = $VSR_AB{$newID} + $r_ab_stats{$hand{$newID}}[$r_avg{$newID}];
$r_h_stats{$hand{$newID}}[$r_avg{$newID}] = $VSR_H{$newID} + $r_h_stats{$hand{$newID}}[$r_avg{$newID}];
$l_hr_stats{$hand{$newID}}[$l_hr{$newID}] = $VSL_HR{$newID} + $l_hr_stats{$hand{$newID}}[$l_hr{$newID}];
$r_hr_stats{$hand{$newID}}[$r_hr{$newID}] = $VSR_HR{$newID} + $r_hr_stats{$hand{$newID}}[$r_hr{$newID}];
$l_hr_ab{$hand{$newID}}[$l_hr{$newID}] = $VSL_AB{$newID} + $l_hr_ab{$hand{$newID}}[$l_hr{$newID}];
$r_hr_ab{$hand{$newID}}[$r_hr{$newID}] = $VSR_AB{$newID} + $r_hr_ab{$hand{$newID}}[$r_hr{$newID}];
$l_bb_stats{$hand{$newID}}[$l_bb{$newID}] = $VSL_BB{$newID} + $l_bb_stats{$hand{$newID}}[$l_bb{$newID}];
$r_bb_stats{$hand{$newID}}[$r_bb{$newID}] = $VSR_BB{$newID} + $r_bb_stats{$hand{$newID}}[$r_bb{$newID}];
$l_bb_ab{$hand{$newID}}[$l_bb{$newID}] = $VSL_AB{$newID} + $l_bb_ab{$hand{$newID}}[$l_bb{$newID}];
$r_bb_ab{$hand{$newID}}[$r_bb{$newID}] = $VSR_AB{$newID} + $r_bb_ab{$hand{$newID}}[$r_bb{$newID}];
$l_2b_stats{$hand{$newID}}[$l_2b{$newID}] = $VSL_2B{$newID} + $l_2b_stats{$hand{$newID}}[$l_2b{$newID}];
$r_2b_stats{$hand{$newID}}[$r_2b{$newID}] = $VSR_2B{$newID} + $r_2b_stats{$hand{$newID}}[$r_2b{$newID}];
$l_2b_ab{$hand{$newID}}[$l_2b{$newID}] = $VSL_AB{$newID} + $l_2b_ab{$hand{$newID}}[$l_2b{$newID}];
$r_2b_ab{$hand{$newID}}[$r_2b{$newID}] = $VSR_AB{$newID} + $r_2b_ab{$hand{$newID}}[$r_2b{$newID}];
$l_3b_stats{$hand{$newID}}[$l_3b{$newID}] = $VSL_3B{$newID} + $l_3b_stats{$hand{$newID}}[$l_3b{$newID}];
$r_3b_stats{$hand{$newID}}[$r_3b{$newID}] = $VSR_3B{$newID} + $r_3b_stats{$hand{$newID}}[$r_3b{$newID}];
$l_3b_ab{$hand{$newID}}[$l_3b{$newID}] = $VSL_AB{$newID} + $l_3b_ab{$hand{$newID}}[$l_3b{$newID}];
$r_3b_ab{$hand{$newID}}[$r_3b{$newID}] = $VSR_AB{$newID} + $r_3b_ab{$hand{$newID}}[$r_3b{$newID}];
}
}
close(PLAYER);
#close(OUTPUT);
}
sub getRatings {
local($offset) = @_;
#open(OUTPUT,">$output_file");
open(PLAYER,"$names_file");
$count = 0;
<PLAYER>;
while(<PLAYER>){
chomp();
s/\.\./\./g;
s/\"//g;
@current = split(/,/);
$newID = $current[0] + $offset;
$name{$newID} = "$current[2] $current[1]";
$hand{$newID} = $current[4];
$age{$newID} = $current[19];
$exp{$newID} = $current[30];
#$o_avg{$newID} = $current[44];
#$o_2b{$newID} = $current[45];
#$o_hr{$newID} = $current[47];
#$o_bb{$newID} = $current[48];
$r_avg{$newID} = $current[50];
$r_2b{$newID} = $current[51];
$r_3b{$newID} = $current[52];
$r_hr{$newID} = $current[53];
$r_bb{$newID} = $current[54];
$l_avg{$newID} = $current[56];
$l_2b{$newID} = $current[57];
$l_3b{$newID} = $current[58];
$l_hr{$newID} = $current[59];
$l_bb{$newID} = $current[60];
$t_avg{$newID} = $current[62];
$team{$newID} = $current[145];
$pos{$newID} = $current[20];
$speed{$newID} = $current[150];
$steal{$newID} = $current[151];
}
close(PLAYER);
}
sub processField {
open(FIELD,"$field_file");
while(<FIELD>){
chomp();
@current = split(/,/);
if ($current[1] > 1) {
$field{$current[0]}{$current[1]} = $current[2];
}
}
close(FIELD);
}
sub precision {
local($num, $prec) = @_;
my($format,$res) = ("\%\." . $prec . "f","");
$res = sprintf ($format, $num);
return $res;
}
sub calcIP {
local($ip, $ipf, $ips) = @_;
if ($ips == 1 && $ip == 0) { return 0;
} else { return precision(($ip + $ipf/3), 5); }
}
vBulletin v3.6.0, Copyright ©2000-2025, Jelsoft Enterprises Ltd.