private function getJSONData() { $data = array(); $pgnParser = new PgnParser($this->getPgnFile()); $pgnGames = $pgnParser->getUnparsedGames(); for ($i = 0, $count = count($pgnGames); $i < $count; $i++) { $parser = new PgnParser(); $parser->setPgnContent($pgnGames[$i]); $parsedGame = $parser->getFirstGame(); $line = $this->getEcoLine($parsedGame); if (isset($line)) { $data[] = $line; } } return $data; }
public function save($request) { $ret = array(); $filePath = $this->getFilePath($request); if (!file_exists($filePath)) { throw new Exception("File not found {$filePath}", 400); } $parser = new PgnParser($filePath); $games = $parser->getGames(); $dbId = $this->getDatabaseId($request); $count = count($games); $pr = LudoDBProgress::getInstance(); $pr->setSteps($count + 1, "Initializing import"); $c = 0; foreach ($games as $game) { $c++; $pr->increment(1, "Importing game " . $c . " of " . $count); $ret[] = $this->importGame($game, $dbId); } $pr->increment(1, "Finished with import"); return $ret; }
$user = isset($_GET['user']) ? $_GET['user'] : ''; $index = isset($_GET['index']) ? $_GET['index'] : '0'; $urls = array(); $urls['gambit'] = array('http://net-chess.com/matchpgn.cgi?id=m1423367122', 'http://net-chess.com/matchpgn.cgi?id=m1423491489', 'http://net-chess.com/matchpgn.cgi?id=m1423367113', 'http://net-chess.com/matchpgn.cgi?id=m1423367134', 'http://net-chess.com/matchpgn.cgi?id=m1425081526'); $urls['manish'] = array('http://net-chess.com/matchpgn.cgi?id=m1422845786', 'http://net-chess.com/matchpgn.cgi?id=m1423351418', 'http://net-chess.com/matchpgn.cgi?id=m1423367122', 'http://net-chess.com/matchpgn.cgi?id=m1423367134', 'http://net-chess.com/matchpgn.cgi?id=m1423491518', 'http://net-chess.com/matchpgn.cgi?id=m1424882182'); if (!isset($urls[$user])) { echo 'no user selected'; exit; } function pr($d) { echo '<pre>'; print_r($d); echo '</pre>'; } $PgnParser = new PgnParser(); $allGames = array(); $unresolvedGames = array(); if (isset($urls[$user])) { foreach ($urls[$user] as $k => $u) { $result = curl($u); $PgnParser->setPgnContent($result); $games = $PgnParser->getUnparsedGames(); if (!empty($games)) { foreach ($games as $game) { if (stristr($game, $user)) { $details = $PgnParser->getParsedGame($game); if (empty($details)) { $unresolvedGames[] = $game; continue; }
public function listOfGames($noCache = false) { if ($this->isGameListInCache() && !$noCache) { return $this->getGameListFromCache(); } $parser = new PgnParser($this->pgnFile, false); $games = $parser->getGames(); $ret = array(); $count = 0; $tokens = preg_split("/[\\/\\.]/s", $this->pgnFile); array_pop($tokens); $idPrefix = array_pop($tokens); foreach ($games as $game) { $game['last_moves'] = $this->getLastMoves($game['moves']); unset($game['moves']); unset($game['metadata']); $game["gameIndex"] = $count; $game["id"] = $idPrefix . '-' . $count; $ret[] = $game; $count++; } $this->saveGameListInCache($ret); return $ret; }
* User: Alf Magne * Date: 23.01.13 * Time: 14:52 * To change this template use File | Settings | File Templates. */ ini_set('display_errors', 'on'); date_default_timezone_set("Europe/Berlin"); require_once __DIR__ . "/../autoload.php"; LudoDB::setHost('127.0.0.1'); LudoDB::setUser('root'); LudoDB::setPassword('administrator'); LudoDB::setDb('PHPUnit'); // Construct database tables $tables = array('Move', 'Game', 'Fen', 'Metadata', 'MetadataValue'); foreach ($tables as $table) { $inst = new $table(); $inst->drop()->yesImSure(); $inst->createTable(); } $profiling = new XHPProfiling('PGN to parser to DB'); $parser = new PgnParser("../../pgn/profiling.pgn"); $games = $parser->getGames(); foreach ($games as $gameData) { $game = new Game(); $game->setDatabaseId(100); $game->setFen($gameData['metadata']['fen']); $game->setMetadata($gameData['metadata']); $game->setMoves($gameData['moves']); $game->commit(); } echo $profiling->end();
/** * @test */ public function shouldSplitPgnIntoCorrectGames() { // given $pgnParser = new PgnParser("pgn/1001-brilliant-checkmates.pgn"); // when $games = $pgnParser->getUnparsedGames(); // then $this->assertEquals(995, count($games)); }
private function getGameWithVariation() { $parser = new PgnParser("pgn/test.pgn"); $games = $parser->getGames(); return $games[0]; }