Ejemplo n.º 1
0
 public function getRows()
 {
     $elos = $this->userRepository->getElosArray();
     $distribution = array_count_values($elos);
     unset($distribution[1200]);
     $data = array();
     foreach ($distribution as $elo => $nb) {
         $data[] = array($elo, $nb);
     }
     return $data;
 }
Ejemplo n.º 2
0
 public function getRows()
 {
     $cacheKey = 'lichess_users_elo_chart';
     $data = apc_fetch($cacheKey);
     if (false === $data) {
         $elos = $this->userRepository->getElosArray();
         $distribution = array_count_values($elos);
         unset($distribution[1200]);
         $data = array();
         foreach ($distribution as $elo => $nb) {
             $data[] = array($elo, $nb);
         }
         apc_store($cacheKey, $data, 86400);
     }
     return $data;
 }
Ejemplo n.º 3
0
 public function getData(User $user)
 {
     $userId = $user->getId();
     $usernames = $this->userRepository->getUsernamesIndexedById();
     $games = iterator_to_array($this->gameRepository->createRecentByUserQuery($user)->hydrate(false)->select('createdAt', 'status', 'turns', 'v', 'isRated', 'clock.l', 'clock.i', 'players.user.$id', 'players.c', 'players.w', 'players.elo', 'players.eloDiff')->getQuery()->execute());
     $data = array(array('#', 'Date (RFC 2822)', 'Color', 'Opponent', 'Result', 'Status', 'Plies', 'Variant', 'Mode', 'Time control', 'Your Elo', 'Your Elo change', 'Opponent Elo', 'Opponent Elo Change', 'Game url', 'Analysis url', 'PGN url'));
     $it = 0;
     foreach ($games as $gameId => $game) {
         list($player, $opponent) = $this->findPlayerAndOpponent($game, $userId);
         if (!empty($player['isAi'])) {
             $opponentUsername = sprintf('A.I. level %d', $opponent['aiLevel']);
         } elseif (!empty($opponent['user']['$id'])) {
             $opponentUsername = isset($usernames[(string) $opponent['user']['$id']]) ? $usernames[(string) $opponent['user']['$id']] : 'Anonymous';
         } else {
             $opponentUsername = '******';
         }
         $clock = isset($game['clock']) ? $game['clock'] : null;
         $data[] = array(++$it, date('r', $game['createdAt']->sec), $player['c'], $opponentUsername, $this->getPgnResult($game), $this->getStatusMessage($game['status']), $game['turns'] - 1, $this->getVariantName($game['v']), !empty($game['isRated']) ? 'rated' : 'casual', $clock ? sprintf('%d %d', round($clock['l'] / 60, 1), $clock['i']) : 'unlimited', (int) $player['elo'], (int) isset($player['eloDiff']) ? $player['eloDiff'] : 0, (int) isset($opponent['elo']) ? $opponent['elo'] : 0, (int) isset($opponent['eloDiff']) ? $opponent['eloDiff'] : 0, $this->urlGenerator->generate('lichess_game', array('id' => $gameId, 'color' => $player['c']), true), $this->urlGenerator->generate('lichess_pgn_viewer', array('id' => $gameId, 'color' => $player['c']), true), $this->urlGenerator->generate('lichess_pgn_export', array('id' => $gameId, 'color' => $player['c']), true));
     }
     return $data;
 }