Puerto Rico Points

[insert_php]
$useDB=’rcdrlc5_dragtrac.’;

$sqlDate= date(‘Y-m-d’, time());
$currentYear=date(‘Y’);
$userClub=4; $userSeason=2019;

$one=’one’;
$caption=null;
$debug=null;
$highestRace=0;
$inCountdown=’N’;
$levelNeeded=0;
$mainCol=null;
$minRaceNum=99;$maxRaceNum=0;
$page_title=’Season Points’;
$raceRemainingPoints=0;
$RNA=null;
$pointsRaces=0;
$showResults=null;
$throughRound=array();

## GET EVENTS AND SET POINTS RESET POINT
$eventsQuery=”SELECT eventNumber,raceNumber from “.$useDB.”event where clubNumber=’$userClub’ and season=’$userSeason’ and (officialEvent=’Y’ or countdownBegins=’Y’) order by raceNumber asc”;
$result=@mysql_query($eventsQuery);
$num=mysql_num_rows($result);
if ($num >0)
{ $PreOrPost=’tableHeaderPre’;
$tableHeader=’

#Name

‘;
while ($row=mysql_fetch_array($result,MYSQL_NUM))
{ $raceNum=floatval($row[1]);
if (strpos($raceNum,’.’) ==false) { $$PreOrPost.=”

$raceNum

“; $raceOrderArray[]=$row[0]; }
else { $tableHeaderMid.=’

TotalPoints
Reset

‘; $fullResetRace=$raceNum; $resetRace=floor($raceNum); $resetEvent=$row[0];$inCountdown=’Y’;$PreOrPost=’tableHeaderPost’;} //if (substr($raceNum, -1)==5)
if ($row[0]<$minRaceNum) { $minRaceNum=$row[0]; } if ($row[0]>$maxRaceNum) { $maxRaceNum=$row[0]; }
if ($row[1]>$pointsRaces) { $pointsRaces=$row[1]; }
$seasonRaceNumber[$row[0]]=$row[1];
}
$tableHeaderEnd.=’

TOTALpb+/-

‘;
}
# else { echo $eventsQuery;}

arsort($seasonRaceNumber);

## GET ALL POINTS FOR SEASON AND CREATE CLASS/RACER ARRAY
$resultsQuery=”SELECT racerNumber,classNumber,eventNumber,qualPoints,bonusPoints,totalPoints,currentRound,numberQualified from “.$useDB.”classEntrys where clubNumber=’$userClub’ and eventNumber>=$minRaceNum and eventNumber<=$maxRaceNum order by racerNumber"; $result=@mysql_query($resultsQuery); $num=mysql_num_rows($result); if ($num >0)
{
while ($row=mysql_fetch_array($result,MYSQL_NUM))
{ $class=$row[1];$event=$row[2];$racer=$row[0];$currentRound=$row[6];
$points[$class][$racer][$event]=$row[5];
$numberQualified[$event][$class]=$row[7];
if (!array_key_exists($event,$throughRound)) { $throughRound[$event][$class]=$currentRound;}
if (!array_key_exists($class,$throughRound[$event])) { $throughRound[$event][$class]=$currentRound;}

if ($currentRound==’FIN’) { $pointsThrough[$event][$class]=$currentRound; }
else { if($currentRound >$throughRound[$event][$class]) {$throughRound[$event][$class]=$currentRound;} }

if ($seasonRaceNumber[$event]>$highestRace) { $highestRace=$seasonRaceNumber[$event]; }

$pointsPosition[$row[0]][$row[2]][$row[1]]=$row[8]; //pointsPosition[racerNumber][eventNumber][classnumber]
}
}
else { $message=’
No events have been completed yet.
‘.$resultsQuery;}

if ($highestRace>$resetRace) { $tableHeaderPre=str_replace(‘expendableCell’,’hideCell’, $tableHeaderPre); $whichCells=’hidePre’;}
if ($highestRace<=$resetRace) { $tableHeaderPost=str_replace('expendableCell','hideCell', $tableHeaderPost); $whichCells='hidePost';} $tableHeader='#Name

‘.$tableHeaderPre.$tableHeaderMid.$tableHeaderPost.$tableHeaderEnd;

## GET ALL CLASSES
$classesQuery=”SELECT classNumber,className,classType,prevYearChamp,clubRecord,date_format(dateRecordSet,’%m/%d/%y’),recordHeldBy,prevYearChamp,maxQualified,officialYears from “.$useDB.”class where clubNumber=’$userClub’ and activeClass=’Y’ order by activeClass desc, className asc”;
$result=@mysql_query($classesQuery);
$num=mysql_num_rows($result);
if ($num >0)
{
while ($row=mysql_fetch_array($result,MYSQL_NUM))
{ unset ($showRacerResults); unset($totalPoints);$debug=null;$officialYearsA=unserialize($row[9]);
$class=$row[0];$maxQualified=$row[8];
if (in_array($userSeason,$officialYearsA))
{ if (!isset($RNA[$row[6]])) { $rnaArray=mysql_fetch_array(@mysql_query(“SELECT racerFirst,racerLast from “.$useDB.”racers where racerNumber=’$row[6]’ limit 1″)); $RNA[$row[6]]=”$rnaArray[0] $rnaArray[1]”;}
if (!isset($RNA[$row[7]])) { $rnaArray=mysql_fetch_array(@mysql_query(“SELECT racerFirst,racerLast from “.$useDB.”racers where racerNumber=’$row[7]’ limit 1″)); $RNA[$row[7]]=”$rnaArray[0] $rnaArray[1]”;}
if ($row[2]==’H’) { $showRecord=”Current ET Record $row[4] • “.$RNA[$row[6]].” • $row[5]
“;} else {$showRecord=null; }
$showRecord.=’Reigning Champ • ‘.$RNA[$row[7]].’‘;
$showResults.= “
\n
\n$userSeaon $row[1]$showRecord“;
$showResults.= “\n

$tableHeader”;

## FIGURE MAX REMAINING POINTS
$raceRemainingPoints=0;
$racesRemaining=$pointsRaces-$highestRace;
$highestEvent=array_search($highestRace,$seasonRaceNumber);

##Figure max points for rounds for full races
if ($maxQualified>32) { $baseMaxRemainingPoints=154; $theseRounds=6;}
elseif ($maxQualified>16) { $baseMaxRemainingPoints=134; $theseRounds=5;}
elseif ($maxQualified>8) { $baseMaxRemainingPoints=114; $theseRounds=4;}
elseif ($maxQualified>4) { $baseMaxRemainingPoints=94; $theseRounds=3;}
else { $baseMaxRemainingPoints=74; $theseRounds=2;}

##Figure max points for rounds for todays Race
if ($numberQualified[$highestEvent][$class]>32) { $todayRounds=6;}
elseif ($numberQualified[$highestEvent][$class]>16) { $todayRounds=5;}
elseif ($numberQualified[$highestEvent][$class]>8) { $todayRounds=4;}
elseif ($numberQualified[$highestEvent][$class]>4) { $todayRounds=3;}
else { $todayRounds=2;}

$baseMaxRemainingPoints=$baseMaxRemainingPoints*$racesRemaining;

$currentThroughRound=$throughRound[$highestEvent][$class];
if ($currentThroughRound!=’FIN’)
{ if (($currentThroughRound==’Q1′)) { $raceRemainingPoints=($todayRounds*20)+4+10+20; $roundToShow=’Prerace’;}
if (($currentThroughRound==’Q2′)) { $raceRemainingPoints=($todayRounds*20)+4+10+20; $roundToShow=’Q1′;}
if ($currentThroughRound==’R1′) { $raceRemainingPoints=$todayRounds*20; $roundToShow=’Q2′;}
if ($currentThroughRound==’R2′) { $raceRemainingPoints=($todayRounds-1)*20; $roundToShow=’Round 1′;}
if ($currentThroughRound==’R3′) { $raceRemainingPoints=($todayRounds-2)*20; $roundToShow=’Round 2′;}
if ($currentThroughRound==’R4′) { $raceRemainingPoints=($todayRounds-3)*20; $roundToShow=’Round 3′;}
if ($currentThroughRound==’R5′) { $raceRemainingPoints=($todayRounds-4)*20; $roundToShow=’Round 4′;}
if ($currentThroughRound==’R6′) { $raceRemainingPoints=($todayRounds-5)*20; $roundToShow=’Round 5′;}
}

$totalRemainingPoints=$baseMaxRemainingPoints+$raceRemainingPoints;
if ($numberQualified[$highestEvent][$class] > 1)
{ $displayPRTR=$raceRemainingPoints.’   –   Based on ‘.$numberQualified[$highestEvent][$class].’ qualified’; }
else { $displayPRTR=$baseMaxRemainingPoints/$racesRemaining.” based on max $maxQualified entrants.”; }
if ($throughRound[$highestEvent][$class]==’FIN’)
{ $roundDescription=’Race is Final’; }
else
{ $roundDescription=’ ‘.$roundToShow.’     •     Points remaining this race: ‘.$displayPRTR;}
$caption1=’Points through race ‘.number_format($highestRace,0).’ – ‘.$roundDescription.’
‘;
$caption1.=$totalRemainingPoints.’ max points remain in season. (‘.$raceRemainingPoints.’ left in current race, ‘.”$baseMaxRemainingPoints pending from $racesRemaining races with $maxQualified maximum entrys)”;

# $debug.=’

Highest Event of Season: ‘.$highestEvent.’
Total Remaining Points: ‘.$totalRemainingPoints.’
Base Max: ‘.$baseMaxRemainingPoints;

$roundedHighestRace=number_format($highestRace,0);

if (count($points[$row[0]])>0)
{ foreach ($points[$row[0]] as $racer=>$racerValues)
{ //echo “

$racer
“;
if (!isset($RNA[$racer])) { $rnaArray=mysql_fetch_array(@mysql_query(“SELECT racerFirst,racerLast from “.$useDB.”racers where racerNumber=’$racer’ limit 1″)); $RNA[$racer]=”$rnaArray[0] $rnaArray[1]”;}

$racerResults=”

“;

foreach($raceOrderArray as $key=>$value) //key+1 is event race number // value is event number
{ $raceNum=$key+1;
$totalPoints[$class][$racer]=$totalPoints[$class][$racer]+$points[$class][$racer][$value];
if ($points[$row[0]][$racer][$value]==0) { $points[$row[0]][$racer][$value]=”;}
if (($key+1>$resetRace) && ($whichCells==’hidePost’)) { $showCellClass=’hideCell’; }
elseif (($key+1<=$resetRace) && ($whichCells=='hidePre') ){ $showCellClass='hideCell'; } else { $showCellClass='expendableCell';} $racerResults.="

‘;
if ($raceNum!=$roundedHighestRace) { $previousRaceTotal[$class][$racer]=$previousRaceTotal[$class][$racer]+$points[$class][$racer][$value]; } //add if not last race

if ($raceNum==$resetRace)
{ $racerResults.=’

“;
if ($points[$class][$racer][$resetEvent]>0) {$totalPoints[$row[0]][$racer]=$points[$class][$racer][$resetEvent];}
if (($raceNum!=$roundedHighestRace) && ($points[$class][$racer][$resetEvent]>0) ) { $previousRaceTotal[$class][$racer]=$points[$class][$racer][$resetEvent]; }
}
}

$racerResults.=’

‘;

if ($totalPoints[$row[0]][$racer]>0) {$showRacerResults[$racer]=$racerResults;}
}
arsort($totalPoints[$row[0]]);
$previousRaceTotal[$class][$racer]=$previousRaceTotal[$class][$racer];
arsort($previousRaceTotal[$class]);
}
$rank=0;$sinceReset=1;$oldPoints=10000;
foreach ($previousRaceTotal[$class] as $key=>$value)
{
if (strlen($showRacerResults[$key])>0)
{ if ($value<$oldPoints) { $rank=$rank+$sinceReset; $sinceReset=1; } else {$sinceReset++;} $oldPoints=$value; } $oldRank[$class][$key]=$rank; } $rank=0; $rowCount=0;$oldPoints=10000;$sinceReset=1; if (count($totalPoints[$row[0]])>0)
{
foreach ($totalPoints[$row[0]] as $key=>$value) // key=racerNumber $value=points
{
if ($rowCount==1) { $rowClass=’ class=”altRow” ‘; $rowCount=-1;} else {$rowClass=null;}
if (strlen($showRacerResults[$key])>0)
{ if ($value<$oldPoints) { $rank=$rank+$sinceReset; $sinceReset=1; } else {$sinceReset++;} if ($rank==1) { $topPoints=$value; $pointsBehind=0;} else { $pointsBehind=$topPoints-$value; } if ($totalRemainingPoints>0) // show countdown info if higher than reset race and there are still points to be earned.
{
$percentOff=$pointsBehind/$totalRemainingPoints;
$cellBackground=null;
if (($highestRace>$fullResetRace) && ($rank<=10)) { if ($percentOff<.15) {$cellBackground='style="color:green; font-weight:bold;"';} elseif ($percentOff<.50) {$cellBackground='style="color:goldenrod; font-weight:bold;"';} elseif ($percentOff<1) {$cellBackground='style="color:red; font-weight:bold;"';} else {$cellBackground='style="font-weight:bold;"';} $columsForCaption1=$pointsRaces+5; if ($inCountdown=='Y') { $caption='

“.’

‘;} else { $caption=null;}
}
}

$lastRacePosition=(array_search($key, array_keys($previousRaceTotal[$class])))+1;
$positionMove=$oldRank[$class][$key]-$rank;
if ($positionMove>0) { $addOn=’

‘;}
elseif ($positionMove<0) { $addOn='

‘;}
else { $addOn=’

‘;}

$showResults.=”

“.$showRacerResults[$key].”

$addOn

\n”;
$rowCount++; $oldPoints=$value;
}
}
}

$showResults.=”\n”.$caption.’

$RNA[$racer]“.$points[$class][$racer][$value].’‘.$totalPoints[$row[0]][$racer].’‘.$points[$row[0]][$racer][$resetEvent].”‘.$totalPoints[$row[0]][$racer].’
$caption1Still in it
Fair chance
Fat Chance
No Chance
‘.$positionMove.’ ↑‘.abs($positionMove).’ ↓
$rank-$pointsBehind

‘.$debug;
}
}
}
else { echo $classesQuery;}

echo ‘

‘.$userSeason.’ ‘.$clubList[$userClub].’ Season Points
‘;
if ($showYear==’2015’) { echo ‘

2015 results are not complete

‘;}
echo $message;
echo “$showResults”;
[/insert_php]

Web Statistics