コード例 #1
0
ファイル: glicko2.php プロジェクト: testt98/ebattles
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>";
}
コード例 #2
0
ファイル: match.php プロジェクト: testt98/ebattles
 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;
 }