\n"; echo ""; echo "\n"; echo "\n"; $totg = 0; $sum_pfc = 0; $sum_pac = 0; for($i=0;$i<$numrows;$i++) { $game = sql_fetch_array(&$res, $dbi); $vres=sql_query("SELECT RANK from teams where team = '$game[vteam]';", $dbi); $ptcomp = ""; $offence = $defence = ""; if(sql_num_rows($vres)) { list($vrank) = sql_fetch_row(&$vres, $dbi); if($game[played] ) { $totg++; # $t_v = get_pfpa_excluding($team, $game[vteam]); $v_t = get_pfpa_excluding($game[vteam], $team); $offence = sprintf("%.1f", $game["score"] - $v_t["avscore"]); $defence = sprintf("%.1f", $game["vscore"] - $v_t["ascore"]); $ptcomp = "$offence/$defence"; $sum_pfc += $v_t[avscore]?($game[score]-$v_t[avscore])/$v_t[avscore]:0; $sum_pac += $v_t[ascore]?($game[vscore]-$v_t[ascore])/$v_t[ascore]:0; } } else { $vrank = "Not DivI"; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; } echo "
$teamScore Comparison
DateOppenentScoreW/LOpp. Rank ScorePF vs Opp. Avg. PAPA vs Opp. Avg. PF
" . $game["date"] . "" . ($game["road"] ? "at " : "") ; echo ""; echo $game["vteam"] . "" . $game["score"] . " - " . $game["vscore"] . "" . ($game["played"] ? ($game["win"] ? "W" : "L") : "-") . "$vrank$offence$defence
"; #echo $sum_pfc/$totg . " " . $sum_pac/$totg . "
"; # $pfac = get_pfpacomp($team); # echo "$pfac[ascore] $pfac[avscore]
"; } function gen_conf_scoreboard_table($conf, $numgames=30) { global $dbi; $res=sql_query("SELECT * from schedule as s where team in (select team from teams as t where t.conf = '$conf') and played = 1 order by DATE DESC;", $dbi); $numrows = sql_num_rows($res, $dbi); # echo "Total games = $numrows

\n"; echo ""; echo "\n"; for($i=0;$i<$numrows && $i<$numgames;) { $game = sql_fetch_array(&$res, $dbi); $res1 = sql_query("SELECT conf from teams where team='" . $game[vteam] . "';", $dbi); list($vconf) = sql_fetch_array(&$res1, $dbi); if($vconf == $conf && $game[road] == 0 || $vconf != $conf) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; echo "\n"; $i++; } } echo "
Scoreboard
" . $game["date"] . ""; echo ""; echo $game["team"] . "" . ($game["road"] ? "at" : "vs") . ""; echo $game["vteam"] . "" . ($game["win"] ? "W" : "L") . "" . $game["score"] . " - " . $game["vscore"] . "
"; } function gen_conf_table($conf, $team="") { global $dbi; $res=sql_query("SELECT * from teams where conf in ('$conf') order by ( case when (cwin+closs <> 0) then (cast(cwin as decimal) / cast(cwin+closs as decimal)) else 0 end ) DESC, ( case when (win+loss <> 0) then (cast(win as decimal) / cast(win+loss as decimal)) else 0 end ) DESC ;", $dbi); $numrows = sql_num_rows($res, $dbi); # echo "Total games = $numrows

\n"; echo ""; echo "\n"; echo "\n"; for($i=0;$i<$numrows;$i++) { $team_a = sql_fetch_array(&$res, $dbi); echo ""; # echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; } echo "
$conf
TeamConf. RecordOverall RecordRank ScoreRank
"; print_r($team_a); echo "" ; echo ""; echo $team_a["team"] . "" . $team_a["cwin"] . " - " . $team_a["closs"] . "" . $team_a["win"] . " - " . $team_a["loss"] . "" . $team_a["qrpi"] . "" . $team_a["rank"] . "
"; } function gen_teams_form() { global $dbi; $res = sql_query("select team from teams order by team;", $dbi); echo "

"; echo "\n"; echo "\n"; echo "
\n"; } function gen_conf_form() { global $dbi; $res = sql_query("select distinct conf from teams order by conf;", $dbi); echo "
"; echo "\n"; echo "\n"; echo "
\n"; } function get_conf_rankings() { global $dbi; $conflist = array(); $res1 = sql_query("select conf, CAST(AVG(qrpi) as decimal(8,3)) as avg_qrpi from teams group by conf order by avg_qrpi DESC;", $dbi); $rank = 1; while( list($conf, $avg_qrpi) = sql_fetch_row(&$res1, $dbi) ) { array_push($conflist, array($conf, $avg_qrpi, $rank++ )); } return $conflist; } function get_point_avg($team) { global $dbi; $ptlist = array(); $res1 = sql_query("select CAST(AVG(score) as decimal(4,1)) as ascore, CAST(AVG(vscore) as decimal(4,1)) as avscore, COUNT(*) as totgames, SUM(win) as wins from schedule where team = '$team' and played = 1;", $dbi); array_push($ptlist, sql_fetch_array(&$res1, $dbi) ); for($i=0;$i<5;$i++) { $res1 = sql_query("select CAST(AVG(score) as decimal(4,1)) as ascore, CAST(AVG(vscore) as decimal(4,1)) as avscore, COUNT(*) as totgames, SUM(win) as wins from schedule where team = '$team' and played = 1 and vteam IN (select team from teams where (RANK>". ($i*10) . ") and (RANK <= " . (($i+1)*10) . "));", $dbi); array_push($ptlist, sql_fetch_array(&$res1, $dbi) ); } return $ptlist; } function get_team_stats($team) { global $dbi; $res = sql_query("select *,arpi from teamstats as ts inner join teams as t on t.team = ts.team where ts.team = '$team'", $dbi); $stats = array(); $stats = sql_fetch_array(&$res, $dbi); return $stats; } function get_stat_rank($stats) { global $dbi; $ranks = array(); $fgp = $stats[fgm]/$stats[fga]; $ftp = $stats[ftm]/$stats[fta]; $tpp = $stats[tpm]/$stats[tpa]; $atr = $stats[asst]/$stats[tovr]; $org = $stats[oreb]/$stats[gp]; $drg = $stats[dreb]/$stats[gp]; $trg = $stats[treb]/$stats[gp]; $stg = $stats[stl]/$stats[gp]; $blg = $stats[blk]/$stats[gp]; $res = sql_query("select count(*) from teamstats where $fgp < (CAST(fgm as real)/CAST(fga as real))", $dbi); $tmp = sql_fetch_array(&$res, $dbi); $ranks[fgp_r] = $tmp[0]+1; $res = sql_query("select count(*) from teamstats where $ftp < (CAST(ftm as real)/CAST(fta as real))", $dbi); $tmp = sql_fetch_array(&$res, $dbi); $ranks[ftp_r] = $tmp[0]+1; $res = sql_query("select count(*) from teamstats where $tpp < (CAST(tpm as real)/CAST(tpa as real))", $dbi); $tmp = sql_fetch_array(&$res, $dbi); $ranks[tpp_r] = $tmp[0]+1; $res = sql_query("select count(*) from teamstats where $atr < (CAST(asst as real)/CAST(tovr as real))", $dbi); $tmp = sql_fetch_array(&$res, $dbi); $ranks[atr_r] = $tmp[0]+1; $res = sql_query("select count(*) from teamstats where $org < (CAST(oreb as real)/CAST(gp as real))", $dbi); $tmp = sql_fetch_array(&$res, $dbi); $ranks[org_r] = $tmp[0]+1; $res = sql_query("select count(*) from teamstats where $drg < (CAST(dreb as real)/CAST(gp as real))", $dbi); $tmp = sql_fetch_array(&$res, $dbi); $ranks[drg_r] = $tmp[0]+1; $res = sql_query("select count(*) from teamstats where $trg < (CAST(treb as real)/CAST(gp as real))", $dbi); $tmp = sql_fetch_array(&$res, $dbi); $ranks[trg_r] = $tmp[0]+1; $res = sql_query("select count(*) from teamstats where $stg < (CAST(stl as real)/CAST(gp as real))", $dbi); $tmp = sql_fetch_array(&$res, $dbi); $ranks[stg_r] = $tmp[0]+1; $res = sql_query("select count(*) from teamstats where $blg < (CAST(blk as real)/CAST(gp as real))", $dbi); $tmp = sql_fetch_array(&$res, $dbi); $ranks[blg_r] = $tmp[0]+1; $res = sql_query("select count(*) from teams where $stats[arpi] < arpi",$dbi); $tmp = sql_fetch_array(&$res, $dbi); $ranks[arpi_r] = $tmp[0]+1; return $ranks; } function gen_point_stat_table($team) { $stats = get_team_stats($team); $ranks = get_stat_rank($stats); echo "\n"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
Rank
FGM/FGA".($stats[fgm])."/".($stats[fga])."".sprintf("%5.1f",100*($stats[fgm]/$stats[fga]))."%$ranks[fgp_r]
FTM/FTA".($stats[ftm])."/".($stats[fta])."".sprintf("%5.1f",100*($stats[ftm]/$stats[fta]))."%$ranks[ftp_r]
3PM/3PA".($stats[tpm])."/".($stats[tpa])."".sprintf("%5.1f",100*($stats[tpm]/$stats[tpa]))."%$ranks[tpp_r]
ASST/TO".($stats[asst])."/".($stats[tovr])."".sprintf("%.3f",($stats[asst]/$stats[tovr]))."$ranks[atr_r]
Off. Reb./gm".sprintf("%5.2f",$stats[oreb]/$stats[gp])."$ranks[org_r]
Def. Reb./gm".sprintf("%5.2f",$stats[dreb]/$stats[gp])."$ranks[drg_r]
Tot. Reb./gm".sprintf("%5.2f",$stats[treb]/$stats[gp])."$ranks[trg_r]
Steals/gm".sprintf("%5.2f",$stats[stl]/$stats[gp])."$ranks[stg_r]
Blocks/gm".sprintf("%5.2f",$stats[blk]/$stats[gp])."$ranks[blg_r]
ARPI".sprintf("%5.3f",$stats[arpi])."$ranks[arpi_r]
\n"; } function gen_stat_rank_table($team) { $points = get_point_avg($team); echo "\n"; echo "\n"; echo "\n"; for($i=0;$i<5;$i++) { echo "\n"; } echo "
vs. RankRecordPFPGPAPG
All". (0|$points[0][wins]) ." - ". ($points[0][totgames]-$points[0][wins]) . "". $points[0][ascore] . "". $points[0][avscore] ."
".($i*10+1)." to ".(($i+1)*10)."". (0|$points[$i+1][wins]) ." - ". ($points[$i+1][totgames]-$points[$i+1][wins]) . "". $points[$i+1][ascore] . "" . $points[$i+1][avscore] . "
\n"; } function get_team_conf($team) { global $dbi; # echo $team . "
"; $res = sql_query("select conf from teams where team = '$team';", $dbi); list($conf) = sql_fetch_row(&$res, $dbi); return $conf; } function gen_rpi_rank_table($start, $end) { global $dbi; $res=sql_query("SELECT * from teams order by rank ASC ;", $dbi); $numrows = sql_num_rows($res, $dbi); echo ""; echo "\n"; echo "\n"; for($i=0;$i<$numrows;$i++) { $team_a = sql_fetch_array(&$res, $dbi); if( $i+1 < $start) { continue; } if($i >= $end) { break; } echo ""; # echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; } echo "
Ranking ($start to $end)
RankTeamConfDiv I W-LOverall W-LConf. RecordLast FewRank ScoreOWPOOWPSched. Rank
"; print_r($team_a); echo "" . $team_a["rank"] . ""; echo ""; echo $team_a["team"] . ""; echo ""; echo $team_a["conf"] . "" . $team_a["d1win"] . " - " . $team_a["d1loss"] . "" . $team_a["win"] . " - " . $team_a["loss"] . "" . $team_a["cwin"] . " - " . $team_a["closs"] . "" . $team_a["lfwin"] . " - " . $team_a["lfloss"] . "" . $team_a["qrpi"] . "" . $team_a["owp"] . "" . $team_a["oowp"] . "" . $team_a["schrank"] . "
"; } function gen_common_opp_table($team1, $team2) { global $dbi; $res=sql_query("SELECT * from schedule where team = '$team1' and vteam = '$team2' and played = 1;", $dbi); $numrows = sql_num_rows($res, $dbi); if($numrows) { $t_v = get_pfpa_excluding($team1, $team2); $v_t = get_pfpa_excluding($team2, $team1); } echo ""; echo "\n"; for($i=0;$i<$numrows;$i++) { $game = sql_fetch_array(&$res, $dbi); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $offence = $game["score"] - $v_t["avscore"]; $defence = $game["vscore"] - $v_t["ascore"]; echo ""; echo "\n"; } echo "
DateHead to HeadScore
" . $game["date"] . "".$game["team"]." "; echo ($game["road"]) ? " at " : " vs "; echo $game["vteam"]."" . (($game["score"]>$game["vscore"]) ? "W" : "L") . "" . $game["vscore"] . " - " . $game["score"] . "$offence/$defence
"; $res=sql_query("SELECT DISTINCT vteam from schedule where vteam in (select vteam from schedule where team = '$team1' and played = 1 ) and team = '$team2' and played = 1;", $dbi); $numrows = sql_num_rows($res, $dbi); # echo "Total games = $numrows

\n"; echo ""; echo "\n"; echo "\n"; echo "\n"; for($i=0;$i<$numrows;$i++) { list($vteam) = sql_fetch_row(&$res, $dbi); $res1=sql_query("SELECT *, SUBSTRING(date from 6 for 5) as date from schedule where vteam = '$vteam' and team = '$team1' and played = 1;", $dbi); $res2=sql_query("SELECT *, SUBSTRING(date from 6 for 5) as date from schedule where vteam = '$vteam' and team = '$team2' and played = 1;", $dbi); while( 1 ) { $game1 = sql_fetch_array(&$res1, $dbi); $game2 = sql_fetch_array(&$res2, $dbi); if( !$game1 && !$game2) { break; } echo ""; if($game1) { echo ""; echo ""; echo ""; } else { echo ""; } echo ""; if($game2) { echo ""; echo ""; echo ""; } else { echo ""; } echo "\n"; } } echo "
$team
$team1Common Oppenent$team2
DateScoreScoreDate
" . $game1["date"] ; echo ($game1["road"] ? " (R) " : " (H) ")."" . $game1["score"] . " - " . $game1["vscore"] . "" . ($game1["win"] ? "W" : "L") . "Blank"; echo ""; echo "$vteam" . ($game2["win"] ? "W" : "L") . "" . $game2["score"] . " - " . $game2["vscore"] . "" . ($game2["road"] ? " (R) " : " (H) ") ; echo $game2["date"] . "Blank
"; } function get_teams_with_com_opp($team) { global $dbi; $result = array(); $res=sql_query("SELECT DISTINCT team from schedule s1 where s1.vteam in (select s2.vteam from schedule s2 where s2.team = '$team' and s2.played = 1) and s1.team <> '$team' and s1.played = 1;", $dbi); $numrows = sql_num_rows($res, $dbi); # echo "Teams with common oponents $numrows\n"; while( list($team) = sql_fetch_array(&$res, $dbi) ) { array_push($result, $team); } return $result; } function get_pfpa_excluding($team1, $team2) { global $dbi; # $res = sql_query("select CAST(AVG(score) as decimal(4,1)) as ascore, CAST(AVG(vscore) as decimal(4,1)) as avscore, COUNT(*) as totgames, SUM(win) as wins from schedule where team = '$team1' and vteam <> '$team2' and played = 1;", $dbi); $res = sql_query("select CAST(AVG(score) as decimal(4,1)) as ascore, CAST(AVG(vscore) as decimal(4,1)) as avscore from schedule where team = '$team1' and vteam <> '$team2' and played = 1;", $dbi); $result = sql_fetch_array(&$res, $dbi); return $result; } function get_pfpacomp($team) { global $dbi; $res = sql_query("select CAST(AVG(score) as decimal(4,1)) as ascore, CAST(AVG(vscore) as decimal(4,1)) as avscore from schedule where team = '$team1' and vteam <> (select team from teams) and played = 1;", $dbi); $result = sql_fetch_array(&$res, $dbi); return $result; } function gen_selection_form( $name, $label1, $values, $label2) { global $dbi; echo "\n"; echo "\n"; } function get_total_teams() { global $dbi; $res=sql_query("SELECT COUNT(*) from teams;", $dbi); list($total) = sql_fetch_row(&$res, $dbi); return $total; } function get_db_header() { global $dbi; $res=sql_query("select * from header ; ", $dbi); $vals = sql_fetch_array(&$res, $dbi); return $vals; } function gen_header($title) { # echo "\n"; # header ("Content-type: HTML "); header("Cache-Control: no-store, no-cache, must-revalidate"); # HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); # HTTP/1.0 echo "\n"; echo "\n"; echo "\n"; echo "$title\n"; echo "\n"; } function gen_footer() { echo "\n"; } ?>