/** * Test friendly track name */ public function testFriendlyTrackName() { // Init new track $track = new Track(); // Set names $track->setVenue('Sebring [Virtua_LM]'); $track->setCourse('Sebring 12h Course ( /1 # `'); // Set (, /, #, ` chars // to test for regex // errors that // previously occured $track->setEvent('12h Course'); // Validate friendly name $this->assertSame('Sebring [Virtua_LM], Sebring 12h Course ( /1 # `', $track->getFriendlyName()); // Change event name $track->setEvent('12h Alternative course'); // Validate friendly name $this->assertSame('Sebring [Virtua_LM], Sebring 12h Course ( /1 # ` (12h Alternative course)', $track->getFriendlyName()); }
/** * @see \Simresults\Data_Reader::readSessions() */ protected function readSessions() { $sessions = array(); // Session data to re-use on next sessions. Must be collected in the // first raw session data (header sections) $initial_session = null; // Loop each session foreach ($this->array_data as $data) { // Has initial session state $session = null; if ($initial_session) { $session = clone $initial_session; } else { // Create new session instance $session = Session::createInstance(); // Get date from human string when available if (isset($data['header']['timestring'])) { // WARNING: Default timezone used. Please note that this is not correct. // The date is the date of the server, but we will never know the // timezone because the data does not provide a timestamp or timezone // information if ($date = \DateTime::createFromFormat('Y/m/d H:i:s', $data['header']['timestring'], new \DateTimeZone(self::$default_timezone))) { $date->setTimezone(new \DateTimeZone(self::$default_timezone)); $session->setDate($date); } } //--- Set game $game = new Game(); $game->setName($data['header']['game'])->setVersion($data['header']['version']); $session->setGame($game); //--- Set server (we do not know...) $server = new Server(); $server->setName('Unknown or offline'); $session->setServer($server); //--- Set track $track = new Track(); // Has race data if (isset($data['race'])) { // Matches track data with file based name // (e.g. Scene=GameData\Locations\Monza_2007\2007_Monza.TRK) if (preg_match('/^.*\\\\(.*)\\\\(.*)\\..*$/i', $data['race']['scene'], $track_matches)) { // Set track values and set to session $track->setVenue($track_matches[1])->setCourse($track_matches[2]); } else { $track->setVenue($data['race']['scene']); } $track->setLength((double) $data['race']['track length']); $session->setTrack($track); } // Remember this initial session state for all coming next // sessions $initial_session = clone $session; } // Get participants $this->setParticipantsAndSessionType($session, $data); // No participants, skip this session if (!$session->getParticipants()) { continue; } $sessions[] = $session; } return $sessions; }
/** * @see \Simresults\Data_Reader::getSessions() */ public function getSessions() { $sessions = array(); // Session data to re-use on next sessions. Must be collected in the // first raw session data (header sections) $initial_session = null; // Loop each session foreach ($this->array_data as $data) { // Has initial session state $session = null; if ($initial_session) { $session = clone $initial_session; } else { // Create new session instance $session = new Session(); // Get date from human string when available if (isset($data['header']['timestring'])) { // WARNING: Default timezone used. Please note that this is not correct. // The date is the date of the server, but we will never know the // timezone because the data does not provide a timestamp or timezone // information if ($date = \DateTime::createFromFormat('Y/m/d H:i:s', $data['header']['timestring'], new \DateTimeZone(self::$default_timezone))) { $date->setTimezone(new \DateTimeZone(self::$default_timezone)); $session->setDate($date); } } //--- Set game $game = new Game(); $game->setName($data['header']['game'])->setVersion($data['header']['version']); $session->setGame($game); //--- Set server (we do not know...) $server = new Server(); $server->setName('Unknown or offline'); $session->setServer($server); //--- Set track $track = new Track(); // Has race data if (isset($data['race'])) { // Matches track data with file based name // (e.g. Scene=GameData\Locations\Monza_2007\2007_Monza.TRK) if (preg_match('/^.*\\\\(.*)\\\\(.*)\\..*$/i', $data['race']['scene'], $track_matches)) { // Set track values and set to session $track->setVenue($track_matches[1])->setCourse($track_matches[2]); } else { $track->setVenue($data['race']['scene']); } $track->setLength((double) $data['race']['track length']); $session->setTrack($track); } // Remember this initial session state for all coming next // sessions $initial_session = clone $session; } // Get participants $this->setParticipantsAndSessionType($session, $data); // No participants, skip this session if (!$session->getParticipants()) { continue; } // Fix driver positions for laps $session_lasted_laps = $session->getLastedLaps(); // Loop each lap number, beginning from 2 because lap 1 has grid // position for ($i = 2; $i <= $session_lasted_laps; $i++) { // Get laps sorted by elapsed time $laps_sorted = $session->getLapsByLapNumberSortedByTime($i); // Sort laps by elapsed time $laps_sorted = Helper::sortLapsByElapsedTime($laps_sorted); // Loop each lap and fix position data foreach ($laps_sorted as $lap_key => $lap) { // Only fix position if lap has a time, this way users of this // library can easier detect whether it's a dummy lap and // decide how to show them if ($lap->getTime() or $lap->getElapsedSeconds()) { $lap->setPosition($lap_key + 1); } } } $sessions[] = $session; } return $sessions; }