function displayWeeklyStandings($db, $users, $season_year, $season_type, $week) { $num_games = getNumberOfGames($season_year, $season_type, $week); $percentages = array(); //$monday_night = getMondayNight($season_year,$season_type,$week); $monday_night_game_id = getMondayNightGame($season_year, $season_type, $week); $monday_kickoff_time = getMondayNightKickoffTime($monday_night_game_id); //echo 'Monday Night game '.$monday_night_game_id.' Kick Time '.$monday_kickoff_time; foreach ($users as $user) { $num_correct = getWeeklyPoints($db, $user['user_id'], $user['group_id'], $season_year, $season_type, $week); $score = getWeeklyScore($db, $user['user_id'], $user['group_id'], $monday_night_game_id); //returns array with score, gsis_id and winner // $score = getGameScore($monday_night_game_id); //$winner = getMondayNightWinner($monday_night_game_id); $percentage = $num_correct / $num_games * 100; //$percentages[$user['user_name']] = $percentage; $this_key = $user['user_name']; //$this_game_id = $score[0]; $totals[$this_key] = $num_correct; $scores[$this_key] = $score[1]; $winners[$this_key] = $score[2]; } /* arsort($percentages); $i=0; foreach($percentages as $u => $p) { echo "<div class=\"progress-label\">".$u."</div><div class=\"progress\">"; echo "<div class=\"progress-bar"; if($i==0 && $p > 0) { echo " progress-bar-success"; } echo "\" role=\"progressbar\" aria-valuenow=\"$p\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"min-width: 2em; width: $p%\"> $p% </div> </div>"; $i++; }*/ arsort($totals); $i = 0; $last_total = 0; echo ' <table class="progress-table"> <tr>'; if (strtotime($monday_kickoff_time) < time()) { echo '<th class="winner">Monday Night Winner</th><th class="score">Score</th>'; echo '<th class="user">User</th><th class="points">Points</th></tr>'; } foreach ($totals as $u => $n) { $length = $n / $num_games * 100; $length = round($length); $total_str = "{$n} ({$n}/{$num_games}, {$length}%)"; echo ' <tr>'; if (strtotime($monday_kickoff_time) < time()) { echo ' <td class="winner">' . $winners[$u] . '</td> <td class="score">' . $scores[$u] . '</td>'; } echo ' <td class="user"> <div class="progress-label">' . substr($u, 0, 12) . '</div> </td> <td class="points"> <div class="progress"> <div class="progress-bar'; if ($n > 0) { if ($i == 0 || $n == $last_total) { echo " progress-bar-success"; $last_total = $n; } } echo '" role="progressbar" aria-valuenow="' . $length . '" aria-valuemin="0" aria-valuemax="100" style="min-width: 2em; width: ' . $length . '%;">' . $total_str . '</div> </div> </td> </tr>'; $i++; } echo '</table>'; }
} } if ($possible_winners > 1) { //there is a tie // echo "<p>It's a tie!</p>\n"; do { //remove the low scores if (current($total_points) != $most_points) { array_pop($total_points); } } while (next($total_points)); // echo "<br>Possible winners after culling:<br>\n"; print_r($total_points); // echo "<br>No compare the Scores. Score Array:<br>\n"; print_r($total_scores); $this_game_id = getMondayNightGame($this_season_year, $this_season_type, $this_week); $this_game_score = getGameScore($this_game_id); // echo "<br>Subtract Actual Game score of $this_game_score.<br>\n"; foreach ($total_scores as $u => $s) { $score_diffs[$u] = abs($s - $this_game_score); } // echo "<br>Unsorted Score Differentials:<br>\n"; print_r($score_diffs); asort($score_diffs); // echo "<br>Sorted Score Differentials:<br>\n"; print_r($score_diffs); $lowest_diff = min($score_diffs); // echo "<br>with a Lowest Diff of $lowest_diff<br>\n"; $possible_winners = 0; foreach ($score_diffs as $d) { if ($d == $lowest_diff) {