function g2_test() { $r0 = 1500; // Glicko 1 rating $RD0 = 350; // Glicko 1 rating deviation $sigma0 = 0.06; // Glicko 2 volatility $tau = 0.5; // constrains volatility over time $epsilon = 1.0E-6; $q_inv = 173.7178; //400/log(10); $mu0 = 0; $phi0 = $RD0 / $q_inv; // 2players $A_mu = g2_from_g1_rating(1500, $r0); $A_phi = g2_from_g1_deviation(350); $A_sigma = $sigma0; $B_mu = g2_from_g1_rating(1500, $r0); $B_phi = g2_from_g1_deviation(350); $B_sigma = $sigma0; $A_r = g2_to_g1_rating($A_mu, $r0); $A_RD = g2_to_g1_deviation($A_phi); $B_r = g2_to_g1_rating($B_mu, $r0); $B_RD = g2_to_g1_deviation($B_phi); echo "A mu={$A_mu}, r={$A_r}<br>"; echo "A phi={$A_phi}, RD={$A_RD}<br>"; echo "A sigma={$A_sigma}<br>"; echo "B mu={$B_mu}, r={$B_r}<br>"; echo "B phi={$B_phi}, RD={$B_RD}<br>"; echo "B sigma={$B_sigma}<br>"; echo "-----------------------------------<br>"; $update_A = glicko2_update($A_mu, $A_phi, $A_sigma, 1, $B_mu, $B_phi, $B_sigma, 2, $tau, $epsilon); $update_B = glicko2_update($B_mu, $B_phi, $B_sigma, 2, $A_mu, $A_phi, $A_sigma, 1, $tau, $epsilon); $A_mu = $A_mu + $update_A[0]; $A_phi = $A_phi * $update_A[1]; $A_sigma = $A_sigma * $update_A[2]; $B_mu = $B_mu + $update_B[0]; $B_phi = $B_phi * $update_B[1]; $B_sigma = $B_sigma * $update_B[2]; $A_r = g2_to_g1_rating($A_mu, $r0); $A_RD = g2_to_g1_deviation($A_phi); $B_r = g2_to_g1_rating($B_mu, $r0); $B_RD = g2_to_g1_deviation($B_phi); echo "---><br>"; echo "A mu={$A_mu}, r={$A_r}<br>"; echo "A phi={$A_phi}, RD={$A_RD}<br>"; echo "A sigma={$A_sigma}<br>"; echo "B mu={$B_mu}, r={$B_r}<br>"; echo "B phi={$B_phi}, RD={$B_RD}<br>"; echo "B sigma={$B_sigma}<br>"; echo "-----------------------------------<br>"; }
function rating_period_update() { global $sql; $q = "SELECT " . TBL_PLAYERS . ".*" . " FROM " . TBL_PLAYERS . " WHERE (" . TBL_PLAYERS . ".Event = '" . $this->fields['EventID'] . "')"; $result = $sql->db_Query($q); $num_players = mysql_numrows($result); if ($num_players != 0) { for ($j = 0; $j < $num_players; $j++) { $PlayerID = mysql_result($result, $j, TBL_PLAYERS . ".PlayerID"); $pG2_RD = mysql_result($result, $j, TBL_PLAYERS . ".G2_RD"); $pG2_sigma = mysql_result($result, $j, TBL_PLAYERS . ".G2_sigma"); $pG2_phi = g2_from_g1_deviation($pG2_RD, G2_qinv); // Glicko 2 rating deviation periodic update $pG2_phi = g2_rating_period($pG2_phi, $pG2_sigma); $pG2_RD = g2_to_g1_deviation($pG2_phi, G2_qinv); $q2 = "UPDATE " . TBL_PLAYERS . " SET G2_RD = '" . floatToSQL($pG2_RD) . "'" . " WHERE (PlayerID = '{$PlayerID}')"; $result2 = $sql->db_Query($q2); } } $q = "SELECT " . TBL_TEAMS . ".*" . " FROM " . TBL_TEAMS . " WHERE (" . TBL_TEAMS . ".Event = '" . $this->fields['EventID'] . "')"; $result = $sql->db_Query($q); $num_teams = mysql_numrows($result); if ($num_teams != 0) { for ($j = 0; $j < $num_teams; $j++) { $TeamID = mysql_result($result, $j, TBL_TEAMS . ".TeamID"); $tG2_RD = mysql_result($result, $j, TBL_TEAMS . ".G2_RD"); $tG2_sigma = mysql_result($result, $j, TBL_TEAMS . ".G2_sigma"); $tG2_phi = g2_from_g1_deviation($pG2_RD, G2_qinv); // Glicko 2 rating deviation periodic update $tG2_phi = g2_rating_period($tG2_phi, $tG2_sigma); $tG2_RD = g2_to_g1_deviation($tG2_phi, G2_qinv); $q2 = "UPDATE " . TBL_TEAMS . " SET G2_RD = '" . floatToSQL($tG2_RD) . "'" . " WHERE (TeamID = '{$TeamID}')"; $result2 = $sql->db_Query($q2); } } }
function deleteTeamsMatchScores() { global $sql; // Get event info $event_id = $this->fields['Event']; $event = new Event($event_id); $G2_r0 = $event->getField('G2_default_r'); // Update Players with scores $q = "SELECT " . TBL_MATCHS . ".*, " . TBL_SCORES . ".*, " . TBL_TEAMS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_TEAMS . " WHERE (" . TBL_MATCHS . ".MatchID = '" . $this->fields['MatchID'] . "')" . " AND (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND (" . TBL_TEAMS . ".TeamID = " . TBL_SCORES . ".Team)"; $result = $sql->db_Query($q); $numTeams = mysql_numrows($result); for ($i = 0; $i < $numTeams; $i++) { $mStatus = mysql_result($result, $i, TBL_MATCHS . ".Status"); $tid = mysql_result($result, $i, TBL_TEAMS . ".TeamID"); $tELO = mysql_result($result, $i, TBL_TEAMS . ".ELORanking"); $tTS_mu = mysql_result($result, $i, TBL_TEAMS . ".TS_mu"); $tTS_sigma = mysql_result($result, $i, TBL_TEAMS . ".TS_sigma"); $tG2_r = mysql_result($result, $i, TBL_TEAMS . ".G2_r"); $tG2_RD = mysql_result($result, $i, TBL_TEAMS . ".G2_RD"); $tG2_sigma = mysql_result($result, $i, TBL_TEAMS . ".G2_sigma"); $tG2_mu = g2_from_g1_rating($tG2_r, $G2_r0, G2_qinv); $tG2_phi = g2_from_g1_deviation($tG2_RD, G2_qinv); $tGamesPlayed = mysql_result($result, $i, TBL_TEAMS . ".GamesPlayed"); $tWins = mysql_result($result, $i, TBL_TEAMS . ".Win"); $tDraws = mysql_result($result, $i, TBL_TEAMS . ".Draw"); $tLosses = mysql_result($result, $i, TBL_TEAMS . ".Loss"); $tScore = mysql_result($result, $i, TBL_TEAMS . ".Score"); $tOppScore = mysql_result($result, $i, TBL_TEAMS . ".ScoreAgainst"); $tPoints = mysql_result($result, $i, TBL_TEAMS . ".Points"); $tForfeits = mysql_result($result, $i, TBL_TEAMS . ".Forfeits"); $scoreid = mysql_result($result, $i, TBL_SCORES . ".ScoreID"); $tdeltaELO = mysql_result($result, $i, TBL_SCORES . ".Player_deltaELO"); $tdeltaTS_mu = mysql_result($result, $i, TBL_SCORES . ".Player_deltaTS_mu"); $tdeltaTS_sigma = mysql_result($result, $i, TBL_SCORES . ".Player_deltaTS_sigma"); $tdeltaG2_mu = mysql_result($result, $i, TBL_SCORES . ".Player_deltaG2_mu"); $tdeltaG2_phi = mysql_result($result, $i, TBL_SCORES . ".Player_deltaG2_phi"); $tdeltaG2_sigma = mysql_result($result, $i, TBL_SCORES . ".Player_deltaG2_sigma"); $tdeltaGamesPlayed = 1; $tdeltaWins = mysql_result($result, $i, TBL_SCORES . ".Player_Win"); $tdeltaDraws = mysql_result($result, $i, TBL_SCORES . ".Player_Draw"); $tdeltaLosses = mysql_result($result, $i, TBL_SCORES . ".Player_Loss"); $tdeltaScore = mysql_result($result, $i, TBL_SCORES . ".Player_Score"); $tdeltaOppScore = mysql_result($result, $i, TBL_SCORES . ".Player_ScoreAgainst"); $tdeltaPoints = mysql_result($result, $i, TBL_SCORES . ".Player_Points"); $tdeltaForfeits = mysql_result($result, $i, TBL_SCORES . ".Player_Forfeit"); $tELO -= $tdeltaELO; $tTS_mu -= $tdeltaTS_mu; $tTS_sigma /= $tdeltaTS_sigma; $tG2_mu -= $tdeltaG2_mu; $tG2_phi /= $tdeltaG2_phi; $tG2_sigma /= $tdeltaG2_sigma; $tG2_r = g2_to_g1_rating($tG2_mu, $G2_r0, G2_qinv); $tG2_RD = g2_to_g1_deviation($tG2_phi, G2_qinv); $tGamesPlayed -= $tdeltaGamesPlayed; $tWins -= $tdeltaWins; $tDraws -= $tdeltaDraws; $tLosses -= $tdeltaLosses; $tScore -= $tdeltaScore; $tOppScore -= $tdeltaOppScore; $tPoints -= $tdeltaPoints; $tForfeits -= $tdeltaForfeits; $output .= "<br>tid: {$tid}, tscore: {$tsScore}, telo: {$tELO}<br />"; if ($mStatus == 'active') { $q_update = "UPDATE " . TBL_TEAMS . " SET ELORanking = '" . floatToSQL($tELO) . "'," . " TS_mu = '" . floatToSQL($tTS_mu) . "'," . " TS_sigma = '" . floatToSQL($tTS_sigma) . "'," . " G2_r = '" . floatToSQL($tG2_r) . "'," . " G2_RD = '" . floatToSQL($tG2_RD) . "'," . " G2_sigma = '" . floatToSQL($tG2_sigma) . "'," . " GamesPlayed = {$tGamesPlayed}," . " Loss = {$tLosses}," . " Win = {$tWins}," . " Draw = {$tDraws}," . " Score = {$tScore}," . " ScoreAgainst = {$tOppScore}," . " Points = {$tPoints}," . " Forfeits = {$tForfeits}," . " RankDelta = 0" . " WHERE (TeamID = '{$tid}')"; $result_update = $sql->db_Query($q_update); $output .= "<br>{$q}"; } // fmarc- Can not reverse "streak" information here :( // Delete Score $q = "DELETE FROM " . TBL_SCORES . " WHERE (ScoreID = '{$scoreid}')"; $result2 = $sql->db_Query($q); $output .= "{$q}<br>"; } // The match itself is kept in database, only the scores are deleted. $q = "UPDATE " . TBL_MATCHS . " SET Status = 'deleted' WHERE (MatchID = '" . $this->fields['MatchID'] . "')"; $result = $sql->db_Query($q); //echo $output; //exit; }