Ejemplo n.º 1
0
function calculateStats()
{
    global $mysqli, $weekStats, $playerTotals, $possibleScoreTotal;
    //get latest week with all entered scores
    $lastCompletedWeek = getLastCompletedWeek();
    //loop through weeks
    for ($week = 1; $week <= $lastCompletedWeek; $week++) {
        //get array of games
        $games = array();
        $sql = "select * from " . DB_PREFIX . "schedule where weekNum = " . $week . " order by gameTimeEastern, gameID";
        $query = $mysqli->query($sql);
        while ($row = $query->fetch_assoc()) {
            $games[$row['gameID']]['gameID'] = $row['gameID'];
            $games[$row['gameID']]['homeID'] = $row['homeID'];
            $games[$row['gameID']]['visitorID'] = $row['visitorID'];
            if ((int) $row['homeScore'] > (int) $row['visitorScore']) {
                $games[$row['gameID']]['winnerID'] = $row['homeID'];
            }
            if ((int) $row['visitorScore'] > (int) $row['homeScore']) {
                $games[$row['gameID']]['winnerID'] = $row['visitorID'];
            }
        }
        $query->free;
        //get array of player picks
        $playerPicks = array();
        $playerWeeklyTotals = array();
        $sql = "select p.userID, p.gameID, p.pickID, p.points, u.firstname, u.lastname, u.userName ";
        $sql .= "from " . DB_PREFIX . "picks p ";
        $sql .= "inner join " . DB_PREFIX . "users u on p.userID = u.userID ";
        $sql .= "inner join " . DB_PREFIX . "schedule s on p.gameID = s.gameID ";
        $sql .= "where s.weekNum = " . $week . " and u.userName <> 'admin' ";
        $sql .= "order by u.lastname, u.firstname, s.gameTimeEastern";
        $query = $mysqli->query($sql);
        while ($row = $query->fetch_assoc()) {
            $playerPicks[$row['userID'] . $row['gameID']] = $row['pickID'];
            $playerWeeklyTotals[$row['userID']][week] = $week;
            $playerTotals[$row['userID']][wins] += 0;
            $playerTotals[$row['userID']][name] = $row['firstname'] . ' ' . $row['lastname'];
            $playerTotals[$row['userID']][userName] = $row['userName'];
            if (!empty($games[$row['gameID']]['winnerID']) && $row['pickID'] == $games[$row['gameID']]['winnerID']) {
                //player has picked the winning team
                $playerWeeklyTotals[$row['userID']][score] += 1;
                $playerTotals[$row['userID']][score] += 1;
            } else {
                $playerWeeklyTotals[$row['userID']][score] += 0;
                $playerTotals[$row['userID']][score] += 0;
            }
        }
        $query->free;
        //get winners & highest score for current week
        $highestScore = 0;
        arsort($playerWeeklyTotals);
        foreach ($playerWeeklyTotals as $playerID => $stats) {
            if ($stats[score] > $highestScore) {
                $highestScore = $stats[score];
            }
            if ($stats[score] < $highestScore) {
                break;
            }
            $weekStats[$week][winners][] = $playerID;
            $playerTotals[$playerID][wins] += 1;
        }
        $weekStats[$week][highestScore] = $highestScore;
        $weekStats[$week][possibleScore] = getGameTotal($week);
        $possibleScoreTotal += $weekStats[$week][possibleScore];
    }
}
Ejemplo n.º 2
0
        echo $currentWeek;
        ?>
 is locked'});
	//-->
	</script>
	<?php 
    }
    ?>
	<div style="clear: left;"></div>
	<!-- end countdown code -->
	
	<h3>Your Picks At A Glance:</h3>
	<table cellpadding="4" cellspacing="0" class="table1">
		<tr><th>Week</th><th>First Game</th><th>Cutoff</th><th>Picks</th></tr>
	<?php 
    $lastCompletedWeek = getLastCompletedWeek();
    $sql = "select s.weekNum, count(s.gameID) as gamesTotal,";
    $sql .= " min(s.gameTimeEastern) as firstGameTime,";
    $sql .= " (select gameTimeEastern from " . $db_prefix . "schedule where weekNum = s.weekNum and DATE_FORMAT(gameTimeEastern, '%W') = 'Sunday' order by gameTimeEastern limit 1) as cutoffTime,";
    $sql .= " (DATE_ADD(NOW(), INTERVAL " . SERVER_TIMEZONE_OFFSET . " HOUR) > (select gameTimeEastern from " . $db_prefix . "schedule where weekNum = s.weekNum and DATE_FORMAT(gameTimeEastern, '%W') = 'Sunday' order by gameTimeEastern limit 1)) as expired ";
    $sql .= "from " . $db_prefix . "schedule s ";
    $sql .= "group by s.weekNum ";
    $sql .= "order by s.weekNum;";
    $query = mysql_query($sql);
    $i = 0;
    $rowclass = '';
    while ($result = mysql_fetch_array($query)) {
        $rowclass = $i % 2 == 0 ? ' class="altrow"' : '';
        echo '		<tr' . $rowclass . '>' . "\n";
        echo '			<td>Week ' . $result['weekNum'] . '</td>' . "\n";
        echo '			<td>' . date('n/j g:i a', strtotime($result['firstGameTime'])) . '</td>' . "\n";