<commit_before><?php
namespace Simresults;

/**
 * The reader for RaceRoom server logs
 *
 * TODO: finish status
 *
 * @author     <NAME> <<EMAIL>>
 * @copyright  (c) 2013 <NAME>
 * @license    http://opensource.org/licenses/ISC
 */
class Data_Reader_RaceRoomServer extends Data_Reader {

    /**
     * @see Simresults\Data_Reader::canRead()
     */
    public static function canRead($data)
    {
        if ($data = json_decode($data, TRUE)) {
            return isset($data['Sessions']);
        }

        return false;
    }

    /**
     * @see \Simresults\Data_Reader::readSessions()
     */
    protected function readSessions()
    {
        // Get data
        $data = json_decode($this->data, TRUE);

        // Get date
        preg_match('/\d{10}/i', $data['Time'], $time_matches);
        $date = new \DateTime; $date->setTimestamp($time_matches[0]);
        $date->setTimezone(new \DateTimeZone(self::$default_timezone));

        // Get other settings
        $other_settings = array();
        $known_setting_keys = array(
                'Experience',
                'Difficulty',
                'FuelUsage',
                'MechanicalDamage',
                'FlagRules',
                'CutRules',
                'RaceSeriesFormat',
                'WreckerPrevention',
                'MandatoryPitstop',
                'MandatoryPitstop'
        );
        foreach ($known_setting_keys as $setting)
        {
            if ($setting_value = $this->helper->arrayGet($data, $setting)) {
                $other_settings[$setting] = $setting_value;
            }
        }

        // Init sessions array
        $sessions = array();

        // Gather all sessions
        foreach ($data['Sessions'] as $session_data)
        {
            // Init session
            $session = Session::createInstance();

            // Practice session by default
            $type = Session::TYPE_PRACTICE;

            // Check session type
            switch(strtolower($name = $session_data['Type']))
            {
                case 'qualify':
                    $type = Session::TYPE_QUALIFY;
                    break;
                case 'qualify2':
                    $type = Session::TYPE_QUALIFY;
                    break;
                case 'qualify3':
                    $type = Session::TYPE_QUALIFY;
                    break;
                case 'warmup':
                    $type = Session::TYPE_WARMUP;
                    break;
                case 'race':
                    $type = Session::TYPE_RACE;
                    break;
                case 'race2':
                    $type = Session::TYPE_RACE;
                    break;
                case 'race3':
                    $type = Session::TYPE_RACE;
                    break;
            }

            // Set session values
            $session->setType($type)
                    ->setDate($date)
                    ->setOtherSettings($other_settings);

            // Set game
            $game = new Game; $game->setName('RaceRoom Racing Experience');
            $session->setGame($game);

            // Set server
            $server = new Server; $server->setName($this->helper->arrayGet($data, 'Server'));
            $session->setServer($server);

            // Set track
            $track = new Track;
            $track->setVenue($this->helper->arrayGet($data, 'Track'));
            $session->setTrack($track);

            // Get participants and their best lap (only lap)
            $participants = array();
            $players_data = $this->helper->arrayGet($session_data, 'Players', array());
            foreach ($players_data as $player_index => $player_data)
            {
                // Create driver
                $driver = new Driver;

                // Has name
                if ($name = $this->helper->arrayGet($player_data, 'FullName') OR<commit_msg>R3E Server: TrackLayout as Course<commit_after><?php
namespace Simresults;

/**
 * The reader for RaceRoom server logs
 *
 * TODO: finish status
 *
 * @author     <NAME> <<EMAIL>>
 * @copyright  (c) 2013 <NAME>
 * @license    http://opensource.org/licenses/ISC
 */
class Data_Reader_RaceRoomServer extends Data_Reader {

    /**
     * @see Simresults\Data_Reader::canRead()
     */
    public static function canRead($data)
    {
        if ($data = json_decode($data, TRUE)) {
            return isset($data['Sessions']);
        }

        return false;
    }

    /**
     * @see \Simresults\Data_Reader::readSessions()
     */
    protected function readSessions()
    {
        // Get data
        $data = json_decode($this->data, TRUE);

        // Get date
        preg_match('/\d{10}/i', $data['Time'], $time_matches);
        $date = new \DateTime; $date->setTimestamp($time_matches[0]);
        $date->setTimezone(new \DateTimeZone(self::$default_timezone));

        // Get other settings
        $other_settings = array();
        $known_setting_keys = array(
                'Experience',
                'Difficulty',
                'FuelUsage',
                'MechanicalDamage',
                'FlagRules',
                'CutRules',
                'RaceSeriesFormat',
                'WreckerPrevention',
                'MandatoryPitstop',
                'MandatoryPitstop'
        );
        foreach ($known_setting_keys as $setting)
        {
            if ($setting_value = $this->helper->arrayGet($data, $setting)) {
                $other_settings[$setting] = $setting_value;
            }
        }

        // Init sessions array
        $sessions = array();

        // Gather all sessions
        foreach ($data['Sessions'] as $session_data)
        {
            // Init session
            $session = Session::createInstance();

            // Practice session by default
            $type = Session::TYPE_PRACTICE;

            // Check session type
            switch(strtolower($name = $session_data['Type']))
            {
                case 'qualify':
                    $type = Session::TYPE_QUALIFY;
                    break;
                case 'qualify2':
                    $type = Session::TYPE_QUALIFY;
                    break;
                case 'qualify3':
                    $type = Session::TYPE_QUALIFY;
                    break;
                case 'warmup':
                    $type = Session::TYPE_WARMUP;
                    break;
                case 'race':
                    $type = Session::TYPE_RACE;
                    break;
                case 'race2':
                    $type = Session::TYPE_RACE;
                    break;
                case 'race3':
                    $type = Session::TYPE_RACE;
                    break;
            }

            // Set session values
            $session->setType($type)
                    ->setDate($date)
                    ->setOtherSettings($other_settings);

            // Set game
            $game = new Game; $game->setName('RaceRoom Racing Experience');
            $session->setGame($game);

            // Set server
            $server = new Server; $server->setName($this->helper->arrayGet($data, 'Server'));
            $session->setServer($server);

            // Set track
            $track = new Track;
            $track->setVenue($this->helper->arrayGet($data, 'Track'));
            $track->setCourse($this->helper->arrayGet($data, 'TrackLayout'));
            $session->setTrack($track);

            // Get participants and their best lap (only lap)
            $participants = array();
            $players_data = $this->helper->arrayGet($session_data, 'Players', array());
            foreach ($players_data as $player_index => $player_data)
            {
                // Create driver
                $driver = new Driver;

                // Has name
                if ($name = $this->helper->arrayGet($player_data, 'FullName') OR
{'fraction_non_alphanumeric': 0.12408204608761712, 'fraction_numerical': 0.0029121296530767284, 'mean_word_length': 1.4394688079061149, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5904147', 'n_tokens_mistral': 2131, 'n_tokens_neox': 1999, 'n_words': 427}