function add_blindfold_333_consecutive_successes() { global $lists, $WHERE; #--- Get ... $results = dbQuery("\n SELECT personId, value1, value2, value3, value4, value5, year, month\n FROM Results result, Competitions competition\n {$WHERE} 1\n AND eventId = '333bf'\n AND competition.id = competitionId\n ORDER BY personId, year, month, day, roundId\n "); foreach (structureBy($results, 'personId') as $personResults) { extract($personResults[0]); #--- Collect all values of this person, add a 'current DNF' sentinel at the end. unset($datedValues); foreach ($personResults as $personResult) { foreach (range(1, 5) as $i) { $v = $personResult["value{$i}"]; if ($v > 0 || $v == -1) { $datedValues[] = array(getMonthName($personResult['month']) . " {$personResult['year']}", $v); } } } $datedValues[] = array('current', -1); #--- Find longest streak. $streak = array(); $bestStreak = array(); $streakFirstDate = ""; $streakLastDate = ""; foreach ($datedValues as $dv) { if ($dv[1] > 0) { if (!$streak) { $streakFirstDate = $dv[0]; } $streakLastDate = $dv[0]; $streak[] = $dv[1]; } else { if (count($streak) >= count($bestStreak)) { $bestStreak = $streak; $bestStreakFirstDate = $streakFirstDate; $bestStreakLastDate = $dv[0] == 'current' ? '<b>ongoing...</b>' : $streakLastDate; } $streak = array(); } } #--- This person doesn't have any streak? Next person, please. if (!$bestStreak) { continue; } #--- Determine properties of the streak. $length = count($bestStreak); $best = min($bestStreak); $worst = max($bestStreak); $average = array_sum($bestStreak) / $length; #--- Format and memorize this person with its streak $persons[] = array($personId, $length, '', '<span style="color:#0C0">' . formatValue($best) . '</span>', $average, '<span style="color:#E00">' . formatValue($worst) . '</span>', "{$bestStreakFirstDate} - {$bestStreakLastDate}"); } usort($persons, 'compareBlindfoldStreaks'); $persons = array_slice($persons, 0, 10); $lists[] = array("blind_streak_3x3", "Rubik's Cube Blindfolded longest success streak", "", "[P] Person [N] Length [t] [r] Best [r] Avg [r] Worst [t] When?", $persons); }
function bestPodiums() { #---------------------------------------------------------------------- $results = dbQuery("SELECT average, competitionId, personId, pos\n FROM Results\n WHERE pos<=3 AND eventId='333' AND formatId='a' AND average>0 AND roundId in ('f','c')\n ORDER BY competitionId, roundId, pos "); foreach (structureBy($results, 'competitionId') as $top3) { if (count($top3) >= 3) { $list[] = array($top3[0]['competitionId'], $top3[0]['average'] + $top3[1]['average'] + $top3[2]['average'], $top3[0]['personId'], $top3[0]['average'], $top3[1]['personId'], $top3[1]['average'], $top3[2]['personId'], $top3[2]['average']); } } uasort($list, 'comparePodiums'); return array_slice($list, 0, 10); }
function add_333_consecutive_sub20() { global $lists, $WHERE; #--- Get ... $results = dbQuery("\n SELECT personName, personId, value1, value2, value3, value4, value5\n FROM Results result, Competitions competition\n {$WHERE} 1\n AND eventId = '333'\n AND competition.id = competitionId\n ORDER BY personId, year, month, day, roundId\n "); foreach (structureBy($results, 'personId') as $personResults) { extract($personResults[0]); #--- Collect all values of this person, add a DNF at the end. $values = array(); foreach ($personResults as $personResult) { foreach (range(1, 5) as $i) { $v = $personResult["value{$i}"]; if ($v > 0 || $v == -1) { $values[] = $v; } } } $values[] = -1; #--- Find longest streak. $streak = array(); $bestStreak = array(); foreach ($values as $v) { if ($v > 0 && $v < 2000) { $streak[] = $v; } else { if (count($streak) >= count($bestStreak)) { $bestStreak = $streak; } $ongoingStreak = $streak; $streak = array(); } } #--- Build the data for the person. if ($bestStreak) { $persons[] = analyzeSub20Streak($personId, $personName, $bestStreak); } if ($ongoingStreak) { $ongoing[] = analyzeSub20Streak($personId, $personName, $ongoingStreak); } } #--- Sort and cut. usort($persons, 'compareSub20Streaks'); usort($ongoing, 'compareSub20Streaks'); $persons = array_slice($persons, 0, 10); $ongoing = array_slice($ongoing, 0, 10); $persons = array_map('formatSub20Streak', $persons); $ongoing = array_map('formatSub20Streak', $ongoing); #--- Specify the list. $lists[] = array("sub20_streak_3x3", "3x3x3 longest sub20 streak", "all-time / ongoing", "[P] Person [N] Length [N] Best [N] Average [N] Worst [T] | [P] Person [N] Length [N] Best [N] Average [N] Worst [T]", my_merge($persons, $ongoing)); }
function showResultsByEvents() { #---------------------------------------------------------------------- global $chosenPersonId; $results = dbQuery("\n SELECT\n result.*,\n event.name eventName,\n competition.cellName competitionCellName,\n event.format valueFormat,\n round.cellName roundCellName\n FROM\n Results result,\n Events event,\n Competitions competition,\n Rounds round\n WHERE " . randomDebug() . "\n AND personId = '{$chosenPersonId}'\n AND event.id = eventId\n AND event.rank < 1000\n AND competition.id = competitionId\n AND round.id = roundId\n ORDER BY\n event.rank, year DESC, month DESC, day DESC, competitionCellName, round.rank DESC\n "); tableBegin('results', 8); tableCaption(false, "History (<a href='person_map.php?i={$chosenPersonId}'>Map</a>)"); #--- Process results by event. foreach (structureBy($results, 'eventId') as $eventResults) { extract($eventResults[0]); #--- Announce the event. tableCaptionNew(false, $eventId, eventLink($eventId, $eventName)); tableHeader(explode('|', 'Competition|Round|Place|Best||Average||Result Details'), array(2 => 'class="r"', 3 => 'class="R"', 5 => 'class="R"', 7 => 'class="f"')); #--- Initialize. $currentCompetitionId = ''; #--- Compute PB Markers //$pbMarkers = []; $bestBest = 9999999999; $bestAverage = 9999999999; foreach (array_reverse($eventResults) as $result) { extract($result); $pbMarkers[$competitionId][$roundCellName] = 0; if ($best > 0 && $best <= $bestBest) { $bestBest = $best; $pbMarkers[$competitionId][$roundCellName] += 1; } if ($average > 0 && $average <= $bestAverage) { $bestAverage = $average; $pbMarkers[$competitionId][$roundCellName] += 2; } } #--- Show the results. foreach ($eventResults as $result) { extract($result); $isNewCompetition = $competitionId != $currentCompetitionId; $currentCompetitionId = $competitionId; $formatBest = formatValue($best, $valueFormat); if ($pbMarkers[$competitionId][$roundCellName] % 2) { $formatBest = "<span style='color:#F60;font-weight:bold'>{$formatBest}</span>"; } $formatAverage = formatValue($average, $valueFormat); if ($pbMarkers[$competitionId][$roundCellName] > 1) { $formatAverage = "<span style='color:#F60;font-weight:bold'>{$formatAverage}</span>"; } tableRowStyled($isNewCompetition ? '' : 'color:#AAA', array($isNewCompetition ? competitionLink($competitionId, $competitionCellName) : '', $roundCellName, $isNewCompetition ? "<b>{$pos}</b>" : $pos, $formatBest, $regionalSingleRecord, $formatAverage, $regionalAverageRecord, formatAverageSources(true, $result, $valueFormat))); } } tableEnd(); }
function showRegionalRecordsSlim() { #---------------------------------------------------------------------- global $chosenYears; require 'regions_get_current_records.php'; tableBegin('results', 6); $caption = spaced(array(chosenRegionName(), $chosenYears)); if ($caption) { tableCaption(true, $caption); } else { tableRowBlank(); } tableHeader(explode('|', 'Person|Single|Event|Average|Person|Result Details'), array(1 => "class='R2'", 2 => "class='c'", 3 => "class='R2'", 5 => 'class="f"')); #--- Process events. foreach (structureBy($results, 'eventId') as $eventResults) { $structure = structureBy($eventResults, 'type'); $singles = $structure[0]; $averages = isset($structure[1]) ? $structure[1] : array(); $wasShownSinglePerson = $wasShownAveragePerson = array(); #--- Process records for this event. $first = true; while ($singles || $averages) { #--- Get next single. $s = array_shift($singles); if (isset($wasShownSinglePerson[$s['personId']])) { $s = false; } $wasShownSinglePerson[$s['personId']] = true; #--- Get next average. $a = array_shift($averages); if (isset($wasShownAveragePerson[$a['personId']])) { $a = false; } $wasShownAveragePerson[$a['personId']] = true; if ($s || $a) { tableRow(array($s ? personLink($s['personId'], $s['personName']) : '', $first ? formatValue($s['value'], $s['format']) : '', $first ? eventLink($s['eventId'], $s['eventCellName']) : '', $first ? formatValue($a['value'], $a['format']) : '', $a ? personLink($a['personId'], $a['personName']) : '', $a ? formatAverageSources(true, $a, $a['format']) : '')); } $first = false; } } tableEnd(); }