function bestMatch($team1players) { $team1players = explode(',', $team1players); if (count($team1players) == 2) { if ($team1players[0] == 0) { $team1players = array($team1players[1]); } elseif ($team1players[1] == 0) { $team1players = array($team1players[0]); } } $players = loadPlayers(); $ratings = loadRatings(); $bestScore = 0; $bestMatch = array(); foreach ($players as $id1 => $name1) { foreach ($players as $id2 => $name2) { if (in_array($id1, $team1players) || in_array($id2, $team1players)) { continue; } $team2players = array($id1); if ($id1 != $id2) { $team2players[] = $id2; } $score = matchScore($team1players, $team2players, $ratings); if ($score > $bestScore) { $bestScore = $score; $bestMatch = $team2players; } } } return $bestMatch; }
function players() { $players = loadPlayers(); $result = array(); foreach ($players as $id => $name) { $result[] = array($id, $name); } return $result; }
function ranking() { $players = loadPlayers(); $ratings = loadRatings(); uasort($ratings, 'compareRatings'); $result = array(); foreach ($ratings as $playerId => $rating) { $result[] = array($playerId, $players[$playerId], round($rating->getConservativeRating() * 100)); } return $result; }
function history() { $id = (int) (isset($_REQUEST['id']) ? $_REQUEST['id'] : 0); $days = (int) (isset($_REQUEST['days']) ? $_REQUEST['days'] : 10); $players = loadPlayers(); $stats = loadStats(); $last = array(); $result = array(); $dates = array(); for ($i = 0; $i < count($stats); $i++) { $timestamp = (int) (round($stats[$i][0] / 86400) * 86400); if (!isset($dates[$timestamp])) { $dates[$timestamp] = 0; } $dates[$timestamp]++; $stats[$i][0] = $timestamp; } $dates = array_keys($dates); sort($dates); $startDate = $days <= 0 ? 0 : $dates[count($dates) - $days]; foreach ($stats as $stat) { $timestamp = $stat[0]; $playerId = $stat[1]; $score = $stat[2]; if ($id != 0 && $id != $playerId) { continue; } if (isset($last[$playerId]) && $last[$playerId][0] < $timestamp && ($last[$playerId][2] != $score || $timestamp == $startDate) && $timestamp >= $startDate) { $result[] = getLogEntry($last[$playerId], $players); } $last[$playerId] = $stat; } foreach ($last as $stat) { $result[] = getLogEntry($stat, $players); } return $result; }
function loadRatings() { $stats = file_get_contents('games.stats'); $stats = explode("\n", $stats); $ratings = array(); foreach ($stats as $stat) { if (empty($stat)) { continue; } $stat = explode("\t", $stat); $playerId = (int) $stat[0]; $mean = (double) $stat[1]; $stddev = (double) $stat[2]; $ratings[$playerId] = new Rating($mean, $stddev); } $gameInfo = new GameInfo(); $players = loadPlayers(); foreach ($players as $playerId => $playerName) { if (!isset($ratings[$playerId])) { $ratings[$playerId] = $gameInfo->getDefaultRating(); } } return $ratings; }
getCompletedChallenges($data); } if ($type == "loadRounds") { loadRounds(); } if ($type == "changeChallangesNumber") { changeChallangesNumber($data); } if ($type == "changeStatus") { changeStatus($data); } if ($type == "loadTeams") { loadTeams($data); } if ($type == "loadPlayers") { loadPlayers($data); } if ($type == "loadUsers") { loadUsers(); } if ($type == "addPlayer") { addPlayer($data); } if ($type == "loadChalleneges") { loadChalleneges(); } if ($type == "loadChallengeText") { loadChallengeText(); } if ($type == "addLink") { addLink($data);