Ejemplo n.º 1
0
function Calculate($dataset)
{
    $counts = array();
    $community_array = array();
    //the number of water points in the community
    $community_arrayx = array();
    //the non-functional water points
    $ranking_array = array();
    //rank by percentage
    $counter = 0;
    foreach ($dataset as $data => $value) {
        if (isset($value['water_functioning'])) {
            $stat = $value['water_functioning'];
            $community = $value['communities_villages'];
            if (!in_array($community, $community_arrayx)) {
                array_push($community_arrayx, $community);
            }
            if (strcasecmp($stat, "yes") == 0) {
                ++$counter;
            }
        }
    }
    $cc_arr = array();
    for ($y = 0; $y < count($community_arrayx); ++$y) {
        $comm = $community_arrayx[$y];
        $community_array[$comm] = getWaterPointsToTal($dataset, $comm);
        $cc_arr[$comm] = getBrokenWaterPointsToTal($dataset, $comm);
        $ranking_array = $cc_arr;
    }
    $counts['functional_water_points'] = $counter;
    $counts['number_of_water_points'] = $community_array;
    $counts['community_ranking'] = getRanking($ranking_array);
    return $counts;
}
Ejemplo n.º 2
0
function updateStats($event_id, $time, $serialize = TRUE)
{
    global $sql;
    global $pref;
    $rater = new rater();
    $file = e_PLUGIN . 'ebattles/cache/sql_cache_event_' . $event_id . '.txt';
    $id = array();
    $uid = array();
    $team = array();
    $name = array();
    $avatar = array();
    $games_played = array();
    $ELO = array();
    $Skill = array();
    $G2 = array();
    $win = array();
    $loss = array();
    $draw = array();
    $windrawloss = array();
    $streaks = array();
    $victory_ratio = array();
    $victory_percent = array();
    $unique_opponents = array();
    $opponentsELO = array();
    $score = array();
    $oppscore = array();
    $scorediff = array();
    $points = array();
    $forfeits = array();
    $forfeits_percent = array();
    $banned = array();
    $rating = array();
    $games_played_score = array();
    $ELO_score = array();
    $Skill_score = array();
    $G2_score = array();
    $win_score = array();
    $loss_score = array();
    $draw_score = array();
    $windrawloss_score = array();
    $victory_ratio_score = array();
    $victory_percent_score = array();
    $unique_opponents_score = array();
    $opponentsELO_score = array();
    $streak_score = array();
    $score_score = array();
    $oppscore_score = array();
    $scorediff_score = array();
    $points_score = array();
    $forfeits_score = array();
    $forfeits_percent_score = array();
    /* Event Info */
    $event = new Event($event_id);
    $type = $event->getField('Type');
    $competition_type = $event->getCompetitionType();
    $hide_ratings_column = $event->getField('hide_ratings_column');
    if ($event->getField('RankingType') == "Classic") {
        $hide_ratings_column = TRUE;
    }
    // Update Players stats
    $q_Players = "SELECT " . TBL_PLAYERS . ".*, " . TBL_USERS . ".*" . " FROM " . TBL_PLAYERS . ", " . TBL_GAMERS . ", " . TBL_USERS . " WHERE (" . TBL_PLAYERS . ".Event = '{$event_id}')" . " AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . " AND (" . TBL_USERS . ".user_id = " . TBL_GAMERS . ".User)";
    $result_Players = $sql->db_Query($q_Players);
    $numPlayers = mysql_numrows($result_Players);
    $players_rated = 0;
    for ($player = 0; $player < $numPlayers; $player++) {
        // For each player
        $pid = mysql_result($result_Players, $player, TBL_PLAYERS . ".PlayerID");
        $puid = mysql_result($result_Players, $player, TBL_USERS . ".user_id");
        $gamer_id = mysql_result($result_Players, $player, TBL_PLAYERS . ".Gamer");
        $gamer = new Gamer($gamer_id);
        $pname = $gamer->getField('Name');
        $pavatar = mysql_result($result_Players, $player, TBL_USERS . ".user_image");
        $pteam = mysql_result($result_Players, $player, TBL_PLAYERS . ".Team");
        $pgames_played = mysql_result($result_Players, $player, TBL_PLAYERS . ".GamesPlayed");
        $pELO = mysql_result($result_Players, $player, TBL_PLAYERS . ".ELORanking");
        $pTS_mu = mysql_result($result_Players, $player, TBL_PLAYERS . ".TS_mu");
        $pTS_sigma = mysql_result($result_Players, $player, TBL_PLAYERS . ".TS_sigma");
        $pSkill = $pTS_mu - 3 * $pTS_sigma;
        $pG2_r = mysql_result($result_Players, $player, TBL_PLAYERS . ".G2_r");
        $pG2_RD = mysql_result($result_Players, $player, TBL_PLAYERS . ".G2_RD");
        $pG2 = $pG2_r - 2 * $pG2_RD;
        $pwin = mysql_result($result_Players, $player, TBL_PLAYERS . ".Win");
        $pdraw = mysql_result($result_Players, $player, TBL_PLAYERS . ".Draw");
        $ploss = mysql_result($result_Players, $player, TBL_PLAYERS . ".Loss");
        $pstreak = mysql_result($result_Players, $player, TBL_PLAYERS . ".Streak");
        $pstreak_worst = mysql_result($result_Players, $player, TBL_PLAYERS . ".Streak_Worst");
        $pstreak_best = mysql_result($result_Players, $player, TBL_PLAYERS . ".Streak_Best");
        $pwindrawloss = $pwin . "/" . $pdraw . "/" . $ploss;
        $pwinloss = $pwin . "/" . $ploss;
        $pvictory_ratio = $ploss > 0 ? $pwin / $ploss : $pwin;
        //fm- draw here???
        $pvictory_percent = $pwin + $pdraw + $ploss > 0 ? 100 * $pwin / ($pwin + $pdraw + $ploss) : 0;
        $pscore = mysql_result($result_Players, $player, TBL_PLAYERS . ".Score");
        $poppscore = mysql_result($result_Players, $player, TBL_PLAYERS . ".ScoreAgainst");
        $ppoints = mysql_result($result_Players, $player, TBL_PLAYERS . ".Points");
        $pforfeits = mysql_result($result_Players, $player, TBL_PLAYERS . ".Forfeits");
        $pforfeits_percent = $pgames_played > 0 ? 100 * $pforfeits / $pgames_played : 0;
        $pbanned = mysql_result($result_Players, $player, TBL_PLAYERS . ".Banned");
        $popponentsELO = 0;
        $popponents = 0;
        $prating = 0;
        $prating_votes = 0;
        // Unique Opponents
        // Find all matches played by current player
        $q_Matches = "SELECT " . TBL_MATCHS . ".*, " . TBL_SCORES . ".*, " . TBL_PLAYERS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . " WHERE (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND (" . TBL_MATCHS . ".Status = 'active')" . " AND (" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " AND (" . TBL_PLAYERS . ".PlayerID = '{$pid}')";
        $result_Matches = $sql->db_Query($q_Matches);
        $numMatches = mysql_numrows($result_Matches);
        $players = array();
        if ($numMatches > 0) {
            for ($match = 0; $match < $numMatches; $match++) {
                // For each match played by current player
                $mID = mysql_result($result_Matches, $match, TBL_MATCHS . ".MatchID");
                $mplayermatchteam = mysql_result($result_Matches, $match, TBL_SCORES . ".Player_MatchTeam");
                // Find all scores/players(+users) for that match
                $q_Scores = "SELECT " . TBL_MATCHS . ".*, " . TBL_SCORES . ".*, " . TBL_PLAYERS . ".*, " . TBL_USERS . ".*" . " FROM " . TBL_MATCHS . ", " . TBL_SCORES . ", " . TBL_PLAYERS . ", " . TBL_GAMERS . ", " . TBL_USERS . " WHERE (" . TBL_MATCHS . ".MatchID = '{$mID}')" . " AND (" . TBL_SCORES . ".MatchID = " . TBL_MATCHS . ".MatchID)" . " AND (" . TBL_PLAYERS . ".PlayerID = " . TBL_SCORES . ".Player)" . " AND (" . TBL_PLAYERS . ".Gamer = " . TBL_GAMERS . ".GamerID)" . " AND (" . TBL_USERS . ".user_id = " . TBL_GAMERS . ".User)";
                $result_Scores = $sql->db_Query($q_Scores);
                $numScores = mysql_numrows($result_Scores);
                for ($scoreIndex = 0; $scoreIndex < $numScores; $scoreIndex++) {
                    $osid = mysql_result($result_Scores, $scoreIndex, TBL_SCORES . ".ScoreID");
                    $ouid = mysql_result($result_Scores, $scoreIndex, TBL_USERS . ".user_id");
                    $oplayermatchteam = mysql_result($result_Scores, $scoreIndex, TBL_SCORES . ".Player_MatchTeam");
                    $oELO = mysql_result($result_Scores, $scoreIndex, TBL_PLAYERS . ".ELORanking");
                    if ($oplayermatchteam != $mplayermatchteam) {
                        $players[] = "{$ouid}";
                        $popponentsELO += $oELO;
                        $popponents += 1;
                    }
                    if ($ouid == $puid) {
                        // Get user rating.
                        $rate = $rater->GetRating("ebscores", $osid);
                        $prating += $rate[0] * ($rate[1] + $rate[2] / 10);
                        $prating_votes += $rate[0];
                    }
                }
            }
        }
        $punique_opponents = count(array_unique($players));
        if ($popponents != 0) {
            $popponentsELO /= $popponents;
        }
        if ($prating_votes != 0) {
            $prating /= $prating_votes;
        }
        // For display
        $id[] = $pid;
        $uid[] = $puid;
        $name[] = $pname;
        $avatar[] = $pavatar;
        $team[] = $pteam;
        $games_played[] = $pgames_played;
        $ELO[] = $pELO;
        $Skill[] = max(0, number_format($pSkill, 0));
        $G2[] = number_format($pG2_r, 0) . " +/- " . number_format($pG2_RD, 0);
        $win[] = $pwin;
        $loss[] = $ploss;
        $draw[] = $pdraw;
        $streaks[] = $pstreak . "|" . $pstreak_best . "|" . $pstreak_worst;
        $windrawloss[] = $pwindrawloss;
        $victory_ratio[] = $pwinloss;
        $victory_percent[] = number_format($pvictory_percent, 2) . "%";
        $unique_opponents[] = $punique_opponents;
        $opponentsELO[] = floor($popponentsELO);
        $score[] = $pgames_played > 0 ? number_format($pscore / $pgames_played, 2) : 0;
        $oppscore[] = $pgames_played > 0 ? number_format($poppscore / $pgames_played, 2) : 0;
        $scorediff[] = $pgames_played > 0 ? number_format(($pscore - $poppscore) / $pgames_played, 2) : 0;
        $points[] = $ppoints;
        $forfeits[] = $pforfeits;
        $forfeits_percent[] = number_format($pforfeits_percent, 2) . "%";
        $banned[] = $pbanned;
        $rating[] = displayRating($prating, $prating_votes);
        // Actual score (not for display)
        $games_played_score[] = $pgames_played;
        $ELO_score[] = $pELO;
        $Skill_score[] = $pSkill;
        $G2_score[] = $pG2;
        $win_score[] = $pwin;
        $loss_score[] = $ploss;
        $draw_score[] = $pdraw;
        $windrawloss_score[] = $pwin - $ploss;
        //fm - ???
        $victory_ratio_score[] = $pvictory_ratio;
        $victory_percent_score[] = $pvictory_percent;
        $unique_opponents_score[] = $punique_opponents;
        $opponentsELO_score[] = $popponentsELO;
        $streaks_score[] = $pstreak_best;
        //max(0,$pstreak_best + $pstreak_worst); //fmarc- TBD
        $score_score[] = $pgames_played > 0 ? $pscore / $pgames_played : 0;
        $oppscore_score[] = $pgames_played > 0 ? -$poppscore / $pgames_played : 0;
        $scorediff_score[] = $pgames_played > 0 ? ($pscore - $poppscore) / $pgames_played : 0;
        $points_score[] = $ppoints;
        $forfeits_score[] = -$pforfeits;
        $forfeits_percent_score[] = -$pforfeits_percent;
        if ($pgames_played >= $event->getField('nbr_games_to_rank') && $pbanned == 0) {
            $players_rated++;
        }
    }
    $rating_max = 0;
    $q_Categories = "SELECT " . TBL_STATSCATEGORIES . ".*" . " FROM " . TBL_STATSCATEGORIES . " WHERE (" . TBL_STATSCATEGORIES . ".Event = '{$event_id}')" . " ORDER BY " . TBL_STATSCATEGORIES . ".CategoryMaxValue DESC";
    $result_Categories = $sql->db_Query($q_Categories);
    $numCategories = mysql_numrows($result_Categories);
    $stat_cat_header = array();
    $stat_min = array();
    $stat_max = array();
    $stat_a = array();
    $stat_b = array();
    $stat_score = array();
    $stat_display = array();
    $cat_index = 0;
    $categories = array();
    for ($category = 0; $category < $numCategories; $category++) {
        $cat_name = mysql_result($result_Categories, $category, TBL_STATSCATEGORIES . ".CategoryName");
        $cat_minpoints = mysql_result($result_Categories, $category, TBL_STATSCATEGORIES . ".CategoryMinValue");
        $cat_maxpoints = mysql_result($result_Categories, $category, TBL_STATSCATEGORIES . ".CategoryMaxValue");
        $cat_InfoOnly = mysql_result($result_Categories, $category, TBL_STATSCATEGORIES . ".InfoOnly");
        if ($cat_maxpoints > 0) {
            //dbg- echo "$cat_name<br>";
            $display_cat = 1;
            switch ($cat_name) {
                case "ELO":
                    $cat_header_title = EB_STATS_L1;
                    $cat_header_text = EB_STATS_L2;
                    $min = min($ELO_score);
                    $max = max($ELO_score);
                    $stat_score[$cat_index] = $ELO_score;
                    $stat_display[$cat_index] = $ELO;
                    break;
                case "Skill":
                    $cat_header_title = EB_STATS_L3;
                    $cat_header_text = EB_STATS_L4;
                    $min = min($Skill_score);
                    $max = max($Skill_score);
                    $stat_score[$cat_index] = $Skill_score;
                    $stat_display[$cat_index] = $Skill;
                    break;
                case "Glicko2":
                    $cat_header_title = EB_STATS_L41;
                    $cat_header_text = EB_STATS_L42;
                    $min = min($G2_score);
                    $max = max($G2_score);
                    $stat_score[$cat_index] = $G2_score;
                    $stat_display[$cat_index] = $G2;
                    break;
                case "GamesPlayed":
                    $cat_header_title = EB_STATS_L5;
                    $cat_header_text = EB_STATS_L6;
                    $min = 0;
                    //min($games_played_score);
                    $max = max($games_played);
                    $stat_score[$cat_index] = $games_played_score;
                    $stat_display[$cat_index] = $games_played;
                    break;
                case "VictoryRatio":
                    $cat_header_title = EB_STATS_L7;
                    $cat_header_text = EB_STATS_L8;
                    $min = 0;
                    //min($victory_ratio_score);
                    $max = max($victory_ratio_score);
                    $stat_score[$cat_index] = $victory_ratio_score;
                    $stat_display[$cat_index] = $victory_ratio;
                    break;
                case "VictoryPercent":
                    $cat_header_title = EB_STATS_L9;
                    $cat_header_text = EB_STATS_L10;
                    $min = 0;
                    //min($victory_percent_score);
                    $max = max($victory_percent_score);
                    $stat_score[$cat_index] = $victory_percent_score;
                    $stat_display[$cat_index] = $victory_percent;
                    break;
                case "WinDrawLoss":
                    $cat_header_title = EB_STATS_L11;
                    $cat_header_text = EB_STATS_L12;
                    $min = min($windrawloss_score);
                    $max = max($windrawloss_score);
                    $stat_score[$cat_index] = $windrawloss_score;
                    $stat_display[$cat_index] = $windrawloss;
                    break;
                case "UniqueOpponents":
                    $cat_header_title = EB_STATS_L13;
                    $cat_header_text = EB_STATS_L14;
                    $min = 0;
                    //min($unique_opponents_score);
                    $max = max($unique_opponents_score);
                    $stat_score[$cat_index] = $unique_opponents_score;
                    $stat_display[$cat_index] = $unique_opponents;
                    break;
                case "OpponentsELO":
                    $cat_header_title = EB_STATS_L15;
                    $cat_header_text = EB_STATS_L16;
                    $min = min($opponentsELO_score);
                    $max = max($opponentsELO_score);
                    $stat_score[$cat_index] = $opponentsELO_score;
                    $stat_display[$cat_index] = $opponentsELO;
                    break;
                case "Streaks":
                    $cat_header_title = EB_STATS_L17;
                    $cat_header_text = EB_STATS_L18;
                    $min = min($streaks_score);
                    $max = max($streaks_score);
                    $stat_score[$cat_index] = $streaks_score;
                    $stat_display[$cat_index] = $streaks;
                    break;
                case "Score":
                    $cat_header_title = EB_STATS_L19;
                    $cat_header_text = EB_STATS_L20;
                    $min = min($score_score);
                    $max = max($score_score);
                    $stat_score[$cat_index] = $score_score;
                    $stat_display[$cat_index] = $score;
                    break;
                case "ScoreAgainst":
                    $cat_header_title = EB_STATS_L21;
                    $cat_header_text = EB_STATS_L22;
                    $min = min($oppscore_score);
                    $max = max($oppscore_score);
                    $stat_score[$cat_index] = $oppscore_score;
                    $stat_display[$cat_index] = $oppscore;
                    break;
                case "ScoreDiff":
                    $cat_header_title = EB_STATS_L23;
                    $cat_header_text = EB_STATS_L24;
                    $min = min($scorediff_score);
                    $max = max($scorediff_score);
                    $stat_score[$cat_index] = $scorediff_score;
                    $stat_display[$cat_index] = $scorediff;
                    break;
                case "Points":
                    $cat_header_title = EB_STATS_L25;
                    $cat_header_text = EB_STATS_L26;
                    $min = min($points_score);
                    $max = max($points_score);
                    $stat_score[$cat_index] = $points_score;
                    $stat_display[$cat_index] = $points;
                    break;
                case "Forfeits":
                    $cat_header_title = EB_STATS_L43;
                    $cat_header_text = EB_STATS_L44;
                    $min = min($forfeits_score);
                    $max = max($forfeits_score);
                    $stat_score[$cat_index] = $forfeits_score;
                    $stat_display[$cat_index] = $forfeits;
                    break;
                case "ForfeitsPercent":
                    $cat_header_title = EB_STATS_L45;
                    $cat_header_text = EB_STATS_L46;
                    $min = min($forfeits_percent_score);
                    $max = max($forfeits_percent_score);
                    $stat_score[$cat_index] = $forfeits_percent_score;
                    $stat_display[$cat_index] = $forfeits_percent;
                    break;
                default:
                    $display_cat = 0;
            }
            if ($display_cat == 1) {
                $stat_InfoOnly[$cat_index] = $cat_InfoOnly;
                switch ($event->getField('RankingType')) {
                    case "CombinedStats":
                        if ($cat_InfoOnly == TRUE) {
                            $cat_header = '<b title="' . $cat_header_title . '">' . $cat_header_text . '</b>';
                        } else {
                            $categories[] = $cat_index;
                            $cat_header = '<b title="' . $cat_header_title . ' [' . number_format($cat_maxpoints, 2) . ' ' . EB_STATS_L27 . ']">' . $cat_header_text . '</b>';
                            /*
                            $cat_header = '
                            <b title="'.$cat_header_title.'">'.$cat_header_text.'</b>
                            <br /><div class="smalltext">['.number_format ($cat_maxpoints,2).'&nbsp;'.EB_STATS_L27.']</div>
                            ';
                            */
                            // a = (ymax-ymin)/(xmax-xmin)
                            // b = ymin - a.xmin
                            if ($max == $min) {
                                $a = 0;
                                $b = $cat_maxpoints;
                            } else {
                                $a = ($cat_maxpoints - $cat_minpoints) / ($max - $min);
                                $b = $cat_minpoints - $a * $min;
                            }
                            $stat_min[$cat_index] = $min;
                            $stat_max[$cat_index] = $max;
                            $stat_a[$cat_index] = $a;
                            $stat_b[$cat_index] = $b;
                            $rating_max += $cat_maxpoints;
                        }
                        break;
                    case "Classic":
                        if ($cat_InfoOnly == TRUE) {
                            $cat_header = '<span title="' . $cat_header_title . '">' . $cat_header_text . '</span>';
                        } else {
                            $cat_header = '<b title="' . $cat_header_title . '">' . $cat_header_text . '</b>';
                            $categories[] = $cat_index;
                        }
                        break;
                    default:
                }
                $stat_cat_header[$cat_index] = $cat_header;
                $cat_index++;
            }
        }
    }
    $numDisplayedCategories = $cat_index;
    $ranks = getRanking($stat_score, $categories);
    $stats = array("0" => array('header', '<b>' . EB_STATS_L28 . '</b>', '<b>' . EB_STATS_L29 . '</b>'));
    // user rating not shown
    // $stats[0][] = '<b>'.EB_STATS_L30.'</b>';
    if ($hide_ratings_column == FALSE) {
        $stats[0][] = '<b title="' . EB_STATS_L31 . ' [' . number_format($rating_max, 2) . ' ' . EB_STATS_L27 . ']">' . EB_STATS_L32 . '</b>';
    }
    //$stats[0][] = '<b title="'.EB_STATS_L31.'">'.EB_STATS_L32.'</b><br /><div class="smalltext">['.number_format ($rating_max,2).'&nbsp;'.EB_STATS_L27.']</div>';
    for ($category = 0; $category < $numDisplayedCategories; $category++) {
        $stats[0][] = $stat_cat_header[$category];
    }
    // Challenge column
    $stats[0][] = "<b>" . EB_CHALLENGE_L1 . "<b>";
    switch ($event->getField('RankingType')) {
        case "CombinedStats":
            $OverallScoreThreshold = 0;
            $final_score = array();
            for ($player = 0; $player < $numPlayers; $player++) {
                $OverallScore[$player] = 0;
                if ($games_played[$player] >= $event->getField('nbr_games_to_rank') && $banned[$player] == 0) {
                    for ($category = 0; $category < $numDisplayedCategories; $category++) {
                        if ($stat_InfoOnly[$category] == FALSE) {
                            $final_score[$category][$player] = $stat_a[$category] * $stat_score[$category][$player] + $stat_b[$category];
                            $OverallScore[$player] += $final_score[$category][$player];
                        }
                    }
                } else {
                    for ($category = 0; $category < $numDisplayedCategories; $category++) {
                        $final_score[$category][$player] = 0;
                    }
                }
                $q_update = "UPDATE " . TBL_PLAYERS . " SET OverallScore = '" . floatToSQL($OverallScore[$player]) . "' WHERE (PlayerID = '{$id[$player]}') AND (Event = '{$event_id}')";
                $result_update = $sql->db_Query($q_update);
            }
            break;
        case "Classic":
            $OverallScoreThreshold = $numPlayers;
            for ($player = 0; $player < $numPlayers; $player++) {
                if ($games_played[$player] >= $event->getField('nbr_games_to_rank') && $banned[$player] == 0) {
                    $OverallScore[$player] = array_search($player, $ranks, false) + $numPlayers + 1;
                } else {
                    $OverallScore[$player] = array_search($player, $ranks, false);
                }
                //dbg: echo "<br>Player $player ($name[$player]), os: $OverallScore[$player]";
                $q_update = "UPDATE " . TBL_PLAYERS . " SET OverallScore = '" . floatToSQL($OverallScore[$player]) . "' WHERE (PlayerID = '{$id[$player]}') AND (Event = '{$event_id}')";
                $result_update = $sql->db_Query($q_update);
            }
            break;
        default:
    }
    // Build results table
    //--------------------
    $q_Players = "SELECT *" . " FROM " . TBL_PLAYERS . " WHERE (Event = '{$event_id}')" . " ORDER BY " . TBL_PLAYERS . ".OverallScore DESC, " . TBL_PLAYERS . ".GamesPlayed DESC, " . TBL_PLAYERS . ".ELORanking DESC, " . TBL_PLAYERS . ".Banned ASC";
    $result_Players = $sql->db_Query($q_Players);
    $ranknumber = 1;
    for ($player = 0; $player < $numPlayers; $player++) {
        $pid = mysql_result($result_Players, $player, TBL_PLAYERS . ".PlayerID");
        $puid = mysql_result($result_Players, $player, TBL_PLAYERS . ".User");
        $prank = mysql_result($result_Players, $player, TBL_PLAYERS . ".Rank");
        $prankdelta = mysql_result($result_Players, $player, TBL_PLAYERS . ".RankDelta");
        $pstreak = mysql_result($result_Players, $player, TBL_PLAYERS . ".Streak");
        // Find index of player
        $index = array_search($pid, $id);
        $prank_side_image = "";
        if ($banned[$index] == 1) {
            $rank = '<span title="' . EB_STATS_L33 . '"><img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/user_delete.ico" alt="' . EB_STATS_L34 . '" title="' . EB_STATS_L34 . '"/></span>';
            $prankdelta_string = "";
            $q_update = "UPDATE " . TBL_PLAYERS . " SET Rank = 0 WHERE (PlayerID = '{$pid}') AND (Event = '{$event_id}')";
            $result_update = $sql->db_Query($q_update);
        } elseif ($OverallScore[$index] <= $OverallScoreThreshold) {
            $rank = '<span title="' . EB_STATS_L35 . '">' . EB_STATS_L36 . '</span>';
            $prankdelta_string = "";
            $q_update = "UPDATE " . TBL_PLAYERS . " SET Rank = 0 WHERE (PlayerID = '{$pid}') AND (Event = '{$event_id}')";
            $result_update = $sql->db_Query($q_update);
        } else {
            $rank = $ranknumber;
            $ranknumber++;
            // increases $ranknumber by 1
            $q_update = "UPDATE " . TBL_PLAYERS . " SET Rank = {$rank} WHERE (PlayerID = '{$pid}') AND (Event = '{$event_id}')";
            $result_update = $sql->db_Query($q_update);
            $new_rankdelta = $prank - $rank;
            if ($new_rankdelta != 0) {
                $prankdelta += $new_rankdelta;
                $q_update = "UPDATE " . TBL_PLAYERS . " SET RankDelta = {$prankdelta} WHERE (PlayerID = '{$pid}') AND (Event = '{$event_id}')";
                $result_update = $sql->db_Query($q_update);
            }
            if ($new_rankdelta != 0 && $rank == 1 && $competition_type == 'Ladder') {
                // Award: player took 1st place
                $q_Awards = "INSERT INTO " . TBL_AWARDS . "(Player,Type,timestamp)\r\n\t\t\t\tVALUES ({$pid},'PlayerTookFirstPlace',{$time})";
                $result_Awards = $sql->db_Query($q_Awards);
            }
            if ($new_rankdelta != 0 && ($prank > 10 || $prank == 0) && $rank <= 10 && $competition_type == 'Ladder') {
                // Award: player enters top 10
                $q_Awards = "INSERT INTO " . TBL_AWARDS . "(Player,Type,timestamp)\r\n\t\t\t\tVALUES ({$pid},'PlayerInTopTen',{$time})";
                $result_Awards = $sql->db_Query($q_Awards);
            }
            $q_Awards = "SELECT " . TBL_AWARDS . ".*, " . TBL_PLAYERS . ".*" . " FROM " . TBL_AWARDS . ", " . TBL_PLAYERS . " WHERE (" . TBL_AWARDS . ".Player = " . TBL_PLAYERS . ".PlayerID)" . " AND (" . TBL_PLAYERS . ".PlayerID = '{$pid}')" . " ORDER BY " . TBL_AWARDS . ".timestamp DESC";
            $result_Awards = $sql->db_Query($q_Awards);
            $numAwards = mysql_numrows($result_Awards);
            if ($numAwards > 0) {
                $paward = mysql_result($result_Awards, 0, TBL_AWARDS . ".AwardID");
                $pawardType = mysql_result($result_Awards, 0, TBL_AWARDS . ".Type");
            }
            if ($rank == 1) {
                $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/awards/award_star_gold_3.png" alt="' . EB_AWARD_L3 . '" title="' . EB_AWARD_L3 . '"/>';
            } else {
                if ($rank <= 10 && ($rank + $prankdelta > min(10, $numPlayers) || $rank + $prankdelta == 0)) {
                    $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/awards/award_star_bronze_3.png" alt="' . EB_AWARD_L5 . '" title="' . EB_AWARD_L5 . '"/>';
                } else {
                    if ($numAwards > 0 && $pawardType != 'PlayerTookFirstPlace' && $pawardType != 'PlayerInTopTen' && $pstreak >= 5) {
                        switch ($pawardType) {
                            case 'PlayerStreak5':
                                if ($pstreak >= 5) {
                                    $award = EB_AWARD_L6;
                                    $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/awards/medal_bronze_3.png" alt="' . EB_AWARD_L7 . '" title="' . EB_AWARD_L7 . '"/>';
                                }
                                break;
                            case 'PlayerStreak10':
                                if ($pstreak >= 10) {
                                    $award = EB_AWARD_L8;
                                    $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/awards/medal_silver_3.png" alt="' . EB_AWARD_L9 . '" title="' . EB_AWARD_L9 . '"/>';
                                }
                                break;
                            case 'PlayerStreak25':
                                if ($pstreak >= 25) {
                                    $award = EB_AWARD_L10;
                                    $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/awards/medal_gold_3.png" alt="' . EB_AWARD_L11 . '" title="' . EB_AWARD_L11 . '"/>';
                                }
                                break;
                        }
                    } else {
                        if ($prankdelta > 0) {
                            $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/arrow_up.gif" alt="+' . $prankdelta . '" title="+' . $prankdelta . '"/>';
                        } else {
                            if ($prankdelta < 0 && $rank + $prankdelta != 0) {
                                $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/arrow_down.gif" alt="' . $prankdelta . '" title="' . $prankdelta . '"/>';
                            } else {
                                if ($rank + $prankdelta == 0) {
                                    $prank_side_image = '<img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/arrow_up.gif" alt="Up" title="' . EB_STATS_L37 . '"/>';
                                }
                            }
                        }
                    }
                }
            }
        }
        list($pclan, $pclantag, $pclanid) = getClanInfo($team[$index]);
        if (strcmp(USERID, $puid) == 0) {
            $stats_row = array("row_highlight");
        } else {
            $stats_row = array("row");
        }
        $stats_row[] = "<b>{$rank}</b> {$prank_side_image}";
        $image = "";
        if ($pref['eb_avatar_enable_playersstandings'] == 1) {
            if ($avatar[$index]) {
                $image = '<img ' . getAvatarResize(avatar($avatar[$index])) . '/>';
            } else {
                if ($pref['eb_avatar_default_image'] != '') {
                    $image = '<img ' . getAvatarResize(getImagePath($pref['eb_avatar_default_image'], 'avatars')) . '/>';
                }
            }
        }
        $stats_row[] = $image . '&nbsp;<a href="' . e_PLUGIN . 'ebattles/userinfo.php?user='******'"><b>' . $pclantag . $name[$index] . '</b></a>';
        // user rating not shown
        //$stats_row[] = $rating[$index];
        if ($hide_ratings_column == FALSE) {
            $stats_row[] = number_format($OverallScore[$index], 2);
        }
        for ($category = 0; $category < $numDisplayedCategories; $category++) {
            if ($stat_InfoOnly[$category] == TRUE || $event->getField('RankingType') == "Classic") {
                $stats_row[] = $stat_display[$category][$index];
            } else {
                $stats_row[] = $stat_display[$category][$index] . '<br /><div class="smalltext">[' . number_format($final_score[$category][$index], 2) . ']</div>';
            }
        }
        // Add challenge button here
        $challenge_text = ' <a href="javascript:challenge_player_js(\'' . $pid . '\');" title="' . EB_CHALLENGE_L1 . ' ' . $pclantag . $name[$index] . '"><img class="eb_image" src="' . e_PLUGIN . 'ebattles/images/challenge.png" alt="' . EB_CHALLENGE_L1 . ' ' . $pclantag . $name[$index] . '"/></a>';
        $stats_row[] = $challenge_text;
        $stats[] = $stats_row;
    }
    /*
    // debug print array
    print_r($stats);
    print_r($stat_score);
    echo "<br>";
    print_r($ranks);
    */
    if ($serialize) {
        // Serialize results array
        $OUTPUT = serialize($stats);
        $fp = fopen($file, "w");
        // open file with Write permission
        if ($fp == FALSE) {
            // handle error
            $error .= EB_STATS_L38;
            echo $error;
            exit;
        }
        fputs($fp, $OUTPUT);
        fclose($fp);
        /*
        $stats = unserialize(implode('',file($file)));
        foreach ($stats as $id=>$row)
        {
        print $row['category_name']."<br />";
        }
        */
    }
}
Ejemplo n.º 3
0
    ?>
</th>
  				<th class="col-md-1"><?php 
    echo $Ltime[$lang];
    ?>
</th>
  				<th class="col-md-3"><?php 
    echo $Lcompetition[$lang];
    ?>
</th>
  				<th class="col-md-2"><?php 
    echo $Ldate[$lang];
    ?>
</th>
  			</tr>
  		</thead>
  		<tbody>
  		  <?php 
    getRanking();
    ?>
  		</tbodY>
	  </table>
	 </div>
	</div>
  <?php 
} else {
    echo "<p class='text-info'>No results found.<p>";
}
?>
</body>
</html>
Ejemplo n.º 4
0
                                <a data-toggle="tab" href="#lastyear">Champions-Race</a>
                            </li>
                            <li>
                                <a data-toggle="tab" href="#special">Early-Bird</a>
                            </li>
                        </ul>

                        <div class="tab-content">
                            <?php 
    }
    if ($zeitraeume == 2) {
        $ranking = getRanking($spiele365, $current_user->id);
        $tabId = "lastyear";
    }
    if ($zeitraeume == 3) {
        $ranking = getRanking($spielesaison, $current_user->id);
        $tabId = "special";
    }
    ?>

                    <div  id="<?php 
    echo $tabId;
    ?>
" class="<?php 
    if ($zeitraeume == 1) {
        echo "tab-pane active";
    } else {
        echo "tab-pane";
    }
    ?>
" >
Ejemplo n.º 5
0
echo get_avatar(get_the_author_meta('ID', $curauth->ID), '81');
?>
                <span><?php 
echo get_the_author_meta('nickname', $curauth->ID);
?>
</span>
                <?php 
// sort function
function sortByLostPoints($kubbLigaItem1, $kubbLigaItem2)
{
    if ($kubbLigaItem1->punkteX == $kubbLigaItem2->punkteX) {
        return 0;
    }
    return $kubbLigaItem1->punkteX < $kubbLigaItem2->punkteX ? 1 : -1;
}
$einzelspieler = getRanking($spiele, $curauth->ID);
usort($einzelspieler, "sortByLostPoints");
?>

                    <table class="ligatable">
                        <caption>Letzte Spiele</caption>
                        <?php 
for ($spielezaehler = 1; $spielezaehler <= 10; $spielezaehler++) {
    echo "<tr>";
    $letztesspiel = array_pop($letztespieleX);
    ?>

                            <tr>
                                <td ><?php 
    echo substr($letztesspiel[0], 0, 5);
    ?>
Ejemplo n.º 6
0
echo $longa;
?>
 <?php 
echo $MSG_LANG['turns'];
?>
</td></tr>
	-->
        <tr>
          <td width="40%" rowspan="2"><div align="center">
              <?php 
echo $_SESSION['playerName'];
?>
        ,
        <?

	    $ranking = getRanking($_SESSION['playerID']);
        $rating = getRating($_SESSION['playerID']);

		if ($CFG_ENABLE_TRIAL_RATING && $rating == 0){
        	$p = mysql_query("select count(*) from games where (whitePlayer='$_SESSION[playerID]' OR blackPlayer='$_SESSION[playerID]') AND (gameMessage='playerResigned' OR gameMessage='checkMate' OR gameMessage='draw')");
			$r = mysql_fetch_array($p);
			$n = 5-$r[0];
			echo "<table style='width: 100%' border='1' style='background:red'><tr><td  style='background:red'>";
		    echo "<font color=white><B>".$MSG_LANG['trialprocess']."</B><BR>";
		    echo str_replace("%n",$n,$MSG_LANG['trialmessage']);
		    echo "</font>";
		    echo "</td></tr></table>";
		}
		else
	        echo $MSG_LANG["yourrating"].": <B>$rating</b> ".$MSG_LANG["yourranking"].": <B>$ranking</B><BR>";
Ejemplo n.º 7
0
?>
            <?php 
echo $country_data['nombre'];
?>
 cuenta con <?php 
echo owloo_number_format($country_data_num['total_user']);
?>
 usuarios, de los cuáles el <?php 
echo owlooFormatPorcent($country_data_num['total_female'], $country_data_num['total_user']);
?>
% son mujeres y <?php 
echo owlooFormatPorcent($country_data_num['total_male'], $country_data_num['total_user']);
?>
 son hombres.<br/>
            Actualmente se encuentra en la posición <?php 
echo getRanking($country_data['id_country']);
?>
 en el ranking mundial de Facebook.
            <hr>
            <a href="<?php 
echo URL_ROOT;
?>
facebook-stats/<?php 
echo convert_to_url_string($country_data['name']);
?>
/" title="Estadísticas de Facebook en <?php 
echo $country_data['nombre'];
?>
" target="_blank">Ver datos completos de <?php 
echo $country_data['nombre'];
?>
Ejemplo n.º 8
0
         $class = $op->classify($sentence);
         //echo "Classifying: \"" . trim($sentence) . "\" as " . $class . "\n";
         $score[$class]++;
     }
 }
 //var_dump($score);
 print $i + 1 . ". " . $filename . " - ";
 if ($score['pos'] > $score['neg']) {
     print "pos ";
     $rankSO = 1;
 }
 if ($score['pos'] < $score['neg']) {
     print "neg ";
     $rankSO = -1;
 }
 $rankStars = trim(getRanking($filename));
 if ($rankSO > 0 and $rankStars >= 30) {
     $rightOnes++;
     fprintf($hndAc, " [OK | TP] ");
     $TP++;
 } elseif ($rankSO < 0 and $rankStars < 30) {
     $rightOnes++;
     fprintf($hndAc, " [OK | TN] ");
     $TN++;
 } else {
     fprintf($hndBO, "{$boc}. {$filename}.utf  {$rankSO}  {$rankStars}\n");
     if ($rankSO < 0 and $rankStars >= 30) {
         $FN++;
         fprintf($hndAc, " [ERROR | FN] ");
     }
     if ($rankSO > 0 and $rankStars < 30) {
 public function ticket($id, $nbMatch)
 {
     $tickets = TableRegistry::get('Tickets');
     $prognostics = TableRegistry::get('Prognostics');
     //The ticket focus
     $ticket = $tickets->find()->where(['id' => $id])->first();
     if (!isset($ticket)) {
         return $this->redirect(['controller' => 'Pages', 'action' => 'page404']);
     }
     //List ticket's matchs today
     $matchs = $prognostics->find()->where(['n_ticket' => $ticket->id])->order(['date_match' => 'ASC']);
     $matchSelected = substr($nbMatch, 5);
     //Match Selected
     foreach ($matchs as $key => $ticketMatch) {
         if ($key == 0) {
             $firstMatch = $ticketMatch;
         }
         if ($key == $matchSelected - 1) {
             $match = $ticketMatch;
             break;
         }
     }
     if (!isset($match)) {
         return $this->redirect(['controller' => 'Pages', 'action' => 'page404']);
     }
     //All championship
     $allChampionship = getChampionships();
     //$championship of the match
     foreach ($allChampionship as $championship) {
         if ($championship['caption'] == $match['competition']) {
             $thisChampionship = $championship;
             break;
         }
     }
     //All matchs championship
     $allMatchsChampionship = getGames($thisChampionship['fixtures']);
     //Match's stats between the teams
     foreach ($allMatchsChampionship as $matchChampionship) {
         if ($matchChampionship['homeTeamName'] == $match['home_team'] && $matchChampionship['awayTeamName'] == $match['away_team']) {
             $matchStats = $matchChampionship['showdown'];
             break;
         }
     }
     //Last match between the teams
     $lastMatchs = getStatsMatch($matchStats);
     //All teams championship
     $allTeamsChampionship = getTeams($thisChampionship['teams']);
     //Team's stats
     foreach ($allTeamsChampionship as $teamChampionship) {
         if ($teamChampionship['name'] == $match['home_team']) {
             $homeTeamStats = $teamChampionship;
         }
         if ($teamChampionship['name'] == $match['away_team']) {
             $awayTeamStats = $teamChampionship;
         }
     }
     //Ranking of the match
     $ranking = getRanking($thisChampionship['leagueTable'], $thisChampionship['teams'], $thisChampionship['fixtures']);
     if (!empty($ranking)) {
         foreach ($ranking as $team) {
             if (!is_array($team)) {
                 if (!empty($homeTeamStats['fixtures'])) {
                     //Home last matchs
                     $homeLastMatchs = getLastMatchs($homeTeamStats['fixtures'], $thisChampionship['championship'], $team, $thisChampionship['teams']);
                     $this->set('homeLastMatchs', $homeLastMatchs);
                 }
                 if (!empty($awayTeamStats['fixtures'])) {
                     //Home last matchs
                     $awayLastMatchs = getLastMatchs($awayTeamStats['fixtures'], $thisChampionship['championship'], $team, $thisChampionship['teams']);
                     $this->set('awayLastMatchs', $awayLastMatchs);
                 }
                 break;
             }
         }
         $this->set('ranking', $ranking);
     }
     $this->set('firstMatch', $firstMatch);
     $this->set('match', $match);
     $this->set('lastMatchs', $lastMatchs);
     $this->set('homeTeamStats', $homeTeamStats);
     $this->set('awayTeamStats', $awayTeamStats);
     $this->set('matchs', $matchs);
     $this->set('ticket', $ticket);
 }
Ejemplo n.º 10
0
//Cambios en el número de usuarios que usan dispositivos móviles
$crecimientoMobileUSers = array('dia' => '', 'semana' => '', 'mes' => '', 'dos_meses' => '', 'tres_meses' => '', 'seis_meses' => '', 'porcentaje' => '');
//Ítem que mayor crecimiento tuvo en las categorías deportivos de los usuarios
$mayorCrecimientoDeportes = array('id_categoria' => '', 'nombre' => '', 'cambio' => '');
//Ítem que mayor crecimiento tuvo en las categorías de actividades de los usuarios
$mayorCrecimientoActividades = array('id_categoria' => '', 'nombre' => '', 'cambio' => '');
//Ítem que mayor crecimiento tuvo en las categorías de intereses los usuarios
$mayorCrecimientoIntereses = array('id_categoria' => '', 'nombre' => '', 'cambio' => '');
//Ítem que mayor crecimiento tuvo en las categorías de Android los usuarios
$mayorCrecimientoAndroid = array('id_categoria' => '', 'nombre' => '', 'cambio' => '');
//Ítem que mayor crecimiento tuvo en las categorías de Ios los usuarios
$mayorCrecimientoIos = array('id_categoria' => '', 'nombre' => '', 'cambio' => '');
//Ítem que mayor crecimiento tuvo en las categorías de Otros moviles los usuarios
$mayorCrecimientoOtrosMoviles = array('id_categoria' => '', 'nombre' => '', 'cambio' => '');
/************************************* FIN - VARIABLES **************************************/
$ranking_position = getRanking(COUNTRY_DATA_ID);
$total_user = get_country_total_audience_for_date(COUNTRY_DATA_ID, COUNTRY_DATE_LAST_UPDATE);
/********************************* Estadísticas de cambio de usuarios en las ultimas 24 horas, ultimos 7 y 30 dias ***************************************/
//Estadística de cambio de usuarios en las ulimas 24 Horas
$sql = "SELECT (total_user - (\n\t\t\t\t\t\t\t\tSELECT total_user \n\t\t\t\t\t\t\t\tFROM record_country \n\t\t\t\t\t\t\t\tWHERE date = (\n\t\t\t\t\t\t\t\t\t\tSELECT max(date) \n\t\t\t\t\t\t\t\t\t\tFROM record_country \n\t\t\t\t\t\t\t\t\t\tWHERE id_country = " . COUNTRY_DATA_ID . "\n\t\t\t\t\t\t\t\t\t\t\tAND date != '" . COUNTRY_DATE_LAST_UPDATE . "'\n\t\t\t\t\t\t\t\t\t ) \n\t\t\t\t\t\t\t\t\t AND id_country = " . COUNTRY_DATA_ID . "\n\t\t\t\t\t\t)) cambio, total_user, total_female, total_male, id_country \n\t\t\t\t\tFROM record_country\n\t\t\t\t\tWHERE id_country = " . COUNTRY_DATA_ID . " \n\t\t\t\t\t\tAND date = '" . COUNTRY_DATE_LAST_UPDATE . "';\n\t\t\t\t ";
$que = mysql_query($sql) or die(mysql_error());
if ($fila = mysql_fetch_assoc($que)) {
    $crecimiento['total_user'] = $fila['total_user'];
    $crecimiento['total_female'] = $fila['total_female'];
    $crecimiento['total_male'] = $fila['total_male'];
    if ($fila['cambio'] > 0) {
        $_crecimiento['value'] = '<span class="owloo_change_audition owloo_arrow_up">' . owloo_number_format($fila['cambio']) . '</span>';
        $_crecimiento['porcentaje'] = '<span class="owloo_arrow_up_porcent">' . owlooFormatPorcent($fila['cambio'], $fila['total_user']) . '%</span>';
    } else {
        if ($fila['cambio'] == 0) {
            $_crecimiento['value'] = '<span class="owloo_not_change_audition"><em>sin cambio</em></span>';
Ejemplo n.º 11
0
            case "/API/GETMYFAVORITE":
            case "/API/GETMYFAVORITE/":
                getMyPrograms($con, $dataForm["UID"], "Program", 1, true, $dataForm["Amount"], $dataForm["Skips"]);
                break;
            case "/API/GETMYAD":
            case "/API/GETMYAD/":
                getMyPrograms($con, $dataForm["UID"], "AD", $dataForm["Status"], null, $dataForm["Amount"], $dataForm["Skips"]);
                break;
            case "/API/GETMYADFAVORITE":
            case "/API/GETMYADFAVORITE/":
                getMyPrograms($con, $dataForm["UID"], "AD", 1, true, $dataForm["Amount"], $dataForm["Skips"]);
                break;
            case "/API/GETCHANNELRANK":
            case "/API/GETCHANNELRANK/":
                getRanking($con, "Channel", $dataForm["Status"], $dataForm["Range"], $dataForm["Amount"], $dataForm["Skips"]);
                break;
            case "/API/GETPROGRAMRANK":
            case "/API/GETPROGRAMRANK/":
                getRanking($con, "Program", $dataForm["Status"], $dataForm["Range"], $dataForm["Amount"], $dataForm["Skips"]);
                break;
            case "/API/GETADRANK":
            case "/API/GETADRANK/":
                getRanking($con, "AD", $dataForm["Status"], $dataForm["Range"], $dataForm["Amount"], $dataForm["Skips"]);
                break;
            default:
                show_error(-7, "URI=" . $_SERVER["REQUEST_URI"] . "\nAPI=" . $API);
                break;
        }
    }
}
$con = null;
Ejemplo n.º 12
0
function generateMedals($player,$generate){
    $rank = 0;

    $p2 = mysql_query("select playerID from {$db_prefix}players where engine='1' AND ativo='1'");
    $totalcpu = mysql_numrows($p2);

    /* Courage Medal */
    if (!$generate)
     $p = mysql_query("SELECT count(*),{$db_prefix}players.* from {$db_prefix}players,{$db_prefix}games WHERE oficial='1' AND playerID='$player' AND
         (status <> 'playerInvited' AND status <> 'inviteDeclined' AND status <> '') AND
         (white_player=playerID OR black_player=playerID)  group by playerID order by rating DESC,rating_month DESC");
    else
     $p = mysql_query("SELECT count(*),players.* from {$db_prefix}players,{$db_prefix}games WHERE oficial='1' AND
     (status <> 'playerInvited' AND status <> 'inviteDeclined' AND status <> '') AND
     (white_player=playerID OR black_player=playerID)  group by playerID order by rating DESC,rating_month DESC");

    while($row = mysql_fetch_array($p)){

        if (!$generate)
            $rank = getRanking($row[playerID]);
        else
            $rank++;

        if ($row[0] >= 20){

        $player = $row[playerID];
        $paralel[$player] = array();
        $venceu[$player] = array();
        $unfinished[$player] = array();
        $game_o = 0;
        $game_u = 0;

        //Golden Medal
        /*
        $p3 = mysql_query("select count(*) from {$db_prefix}games where ratingWhite>0 AND ratingBlack>0 AND (white_player=$player OR black_player=$player) AND status <> '' AND status<>'inviteDeclined' and status<>'playerInvited' and oficial=1");
        if (mysql_numrows($p3) >0){
            $r3 = mysql_fetch_array($p3);
            $game_o = $r3[0];
        }
        $p3 = mysql_query("select count(*) from {$db_prefix}games where ratingWhite>0 AND ratingBlack>0 AND (white_player=$player OR black_player=$player) AND status <> '' AND status<>'inviteDeclined' and status<>'playerInvited' and oficial=0");
        if (mysql_numrows($p3) >0){
            $r3 = mysql_fetch_array($p3);
            $game_u = $r3[0];
        }
        $game_t = $game_o+$game_u;

          $oficial_ratio = ($game_o/$game_t)*100;
          if ($oficial_ratio >=80 && $row[0] >50)
              echo "$row[firstName] $oficial_ratio<BR>";
              //giveMedal("goldenstar",$player,$row[firstName],$generate);
        */

            $p2 = mysql_query("select DISTINCT playerID from {$db_prefix}games,{$db_prefix}players where
            ((status='checkMate' AND message_from='white' AND white_player=$player AND black_player=playerID)
            OR (status='checkMate' AND message_from='black' AND black_player=$player AND white_player=playerID))
            AND DisplayBot='1' AND ativo='1' AND oficial='1'");
            if ($totalcpu >0 && mysql_numrows($p2) >= $totalcpu)
             giveMedal("botslayer",$player,$row[firstName],$generate);


            $vitorias=0;
            $derrotas=0;
            $empates=0;
            $ativos=0;


            $p2 = mysql_query("select *,DATE_FORMAT(dateCreated, '%d/%m/%y') as created,DATE_FORMAT(lastMove, '%d/%m/%y') as fim from {$db_prefix}games where oficial='1' AND (white_player='".$player."' OR black_player='".$player."')");
            while ($r = mysql_fetch_array($p2)){

                $v=0;
                $d=0;
                $e=0;
                $a=0;

                if ($r['status']== '')
                    $a=1;
                else if ($r['status'] == "playerResigned" && $r['message_from'] == "white" && $player != $r['white_player'])
                    $v=1;
                else if ($r['status'] == "playerResigned" && $r['message_from'] == "black" && $player != $r['black_player'])
                    $v=1;
                else if ($r['status'] == "playerResigned" && $r['message_from'] == "white" && $player != $r['black_player'])
                    $d=1;
                else if ($r['status'] == "playerResigned" && $r['message_from'] == "black" && $player != $r['white_player'])
                    $d=1;
                else if ($r['status'] == "checkMate" && $r['message_from'] == "white" && $player != $r['white_player'])
                    $d=1;
                else if ($r['status'] == "checkMate" && $r['message_from'] == "black" && $player != $r['black_player'])
                    $d=1;
                else if ($r['status'] == "checkMate" && $r['message_from'] == "white" && $player != $r['black_player'])
                    $v=1;
                else if ($r['status'] == "checkMate" && $r['message_from'] == "black" && $player != $r['white_player'])
                    $v=1;
                else if ($r['status'] == "draw")
                    $e=1;

            if ($v == 1)$vitorias++;
            if ($d == 1)$derrotas++;
            if ($e == 1)$empates++;
            if ($a == 1)$ativos++;


            if ($v == 1){
            $venceu[$player][$r[created]]++;
            $terminou[$player][$r[fim]] += $r[xpw];
            }else if ($a == 1)
            $unfinished[$player][$r[created]]++;
            else if ($d == 1){
             $paralel[$player][$r[created]]++;
             $terminou[$player][$r[fim]] -= $r[xpl];
            }else
                $paralel[$player][$r[created]]++;

        }

            $medal = "";
            while(list($data,$vit) = each($venceu[$player])){
                $der = $paralel[$player][$data];
                $ati = $unfinished[$player][$data];
                $tot = $der+$vit;
                if ($ati == "")$ati=0;

                if ($vit >=10 && $ati == 0){
                    $percent = round($vit/$tot*100);
                    if ($percent >=70 && $percent <80)
                        $medal = "courage70";
                    else if ($percent >=80 && $percent <90)
                        $medal = "courage80";
                    else if ($percent >=90 && $percent <100)
                        $medal = "courage90";
                    else if ($percent == 100)
                        $medal = "courage100";
                }
            }

            if ($medal != "")
                giveMedal($medal,$player,$row[firstName],$generate);

            while(list($data,$xp) = each($terminou[$player])){
                if ($xp >=130)
                    giveMedal("silverstar",$player,$row[firstName],$generate);
                //if ($xp >=250)
                    //giveMedal("goldenstar",$player,$row[firstName],$generate);
            }


            /* Honour medal */
            if ($rank == 1)
                giveMedal("honour",$player,$row[firstName],$generate);

            /* Purple Heart */
            if ($row[rating] == 900)
                giveMedal("purpleheart",$player,$row[firstName],$generate);

            /* Merit Medal */
                    $total = $vitorias+$derrotas+$empates;
                    $pv = round($vitorias/$total*100,2);

            if ($pv >=90){
                if ($total < 50)$medal = "merit20";
                else if ($total < 100)$medal = "merit50";
                else if ($total >=100)$medal = "merit100";
                giveMedal($medal,$row[playerID],$row[firstName],$generate);
            }
        }

    }

}
Ejemplo n.º 13
0
function displayRanking()
{
    $diplay_num = 5;
    //表示件数
    $postRankList = getRanking();
    $yesterday = date('Y-m-d', strtotime('-1 day', time()));
    $created_at = $postRankList[0]->created_at;
    //ランキングがなければ作成
    if (!$postRankList) {
        reloadedRanking();
        $postRankList = getRanking();
    }
    //ランキングの作成日が前日以前であればランキング再作成
    if ($created_at < $yesterday) {
        reloadedRanking();
        $postRankList = getRanking();
    }
    print <<<RANKING_HEADER
      <!-- new article -->
      <section>
        <div class="new_article">
        <div class="new_article_tittle">Ranking 
        </div>
        <!-- loop start -->
RANKING_HEADER;
    $i = 1;
    foreach ($postRankList as $post) {
        if ($i > $diplay_num) {
            break;
        }
        $post_id = $post->post_id;
        $post_info = get_post($post->post_id);
        $title = get_the_title($post_id);
        $permalink = get_permalink($post_id);
        $thumb = wp_get_attachment_url(get_post_thumbnail_id($post_id));
        $cat = get_the_category($post_id);
        $category = $cat[0]->name;
        print <<<RANKING
        <a href="{$permalink}" onclick="ga('send', 'event', 'matcha', 'ranking', '{$i}');">
          <div class="new_article_box">
          <div class="new_article_category" style="background-color: #FF5B5B !important;">
          <h3>No.{$i}</h3>
          </div>
          <div class="new_article_image">
          <img src="{$thumb}">
          </div>
          <div class="new_article_text">{$title}
          </div>
          </div>
        </a>
RANKING;
        $i++;
    }
    //foreach end
    print <<<RANKING_FOOTER
        <!-- loop end -->
        </div>
      </section>
RANKING_FOOTER;
}
Ejemplo n.º 14
0
 */
get_header();
?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main" style="margin-top:24px;">
        <h1>Einzelspieler-Liga</h1>

        <?php 
if (isset($_POST['resultat1'])) {
    #Spiel hinzufügen
    $spieldatetime = date("Y-m-d H:i:s");
    $wpdb->insert('liga_spiele', array('date' => $spieldatetime, 'spieler1' => $_POST['spieler1'], 'spieler2' => $_POST['spieler2'], 'resultat1' => $_POST['resultat1'], 'resultat2' => $_POST['resultat2']));
}
get_template_part('template-parts/content-liga-formular');
$ranking = getRanking($spiele, $current_user->id);
?>
            <table class="ligatable">
                <caption>Die letzten Spiele</caption>
                <?php 
for ($spielezaehler = 1; $spielezaehler <= 10; $spielezaehler++) {
    echo "<tr>";
    $letztesspiel = array_pop($letztespiele);
    ?>

                    <tr>
                        <td><?php 
    echo substr($letztesspiel[0], 0, 7);
    ?>
</td>