コード例 #1
0
ファイル: Race07.php プロジェクト: mauserrifle/simresults
 /**
  * @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;
 }
コード例 #2
0
 /**
  * Get a Session instance populated with test data.
  *
  * NOTE: Every time this method is ran, a different instance will be
  *       returned! Keep this in mind when comparing things by reference
  *
  * @return Session
  */
 protected function getSessionWithData()
 {
     // Create new session
     $session = Session::createInstance();
     // Participants testdata array
     $participants_data = array(array('position' => 1, 'vehicle' => array('class' => 'class1'), 'laps' => array(array('time' => 130.7517, 'sectors' => array(53.2312, 32.299, 45.2215), 'position' => 1, 'cuts' => array(array('cut_time' => 3, 'time_skipped' => 4, 'time' => time() + 20))), array('time' => 125.2989, 'sectors' => array(47.4511, 32.063, 45.7848), 'position' => 1), array('time' => 123.3179, 'sectors' => array(46.6382, 32.0084, 44.6712), 'position' => 1, 'cuts' => array(array('cut_time' => 5, 'time_skipped' => 6, 'time' => time() + 200), array('cut_time' => 7, 'time_skipped' => 8, 'time' => time() + 220))))), array('position' => 2, 'vehicle' => array('class' => 'class3'), 'laps' => array(array('time' => 130.9077, 'sectors' => array(54.0223, 32.3176, 44.5677), 'position' => 2, 'cuts' => array(array('cut_time' => 1, 'time_skipped' => 2, 'time' => time()))), array('time' => 125.6976, 'sectors' => array(47.5271, 32.4621, 45.7083), 'position' => 2), array('time' => 126.062, 'sectors' => array(47.7989, 32.7721, 45.491), 'position' => 2))), array('position' => 3, 'vehicle' => array('class' => 'class2'), 'laps' => array(array('time' => 134.8484, 'sectors' => array(56.0119, 32.4913, 46.3452), 'position' => 12), array('time' => 126.2454, 'sectors' => array(50.4389, 31.8827, 43.9237), 'position' => 3), array('time' => 122.0663, 'sectors' => array(46.2715, 31.8696, 43.9252), 'position' => 3))), array('position' => 4, 'vehicle' => array('class' => 'class1'), 'laps' => array(array('time' => 155.1491, 'sectors' => array(60.0119, 40.4913, 54.6459), 'position' => 4), array('time' => 156.1491, 'sectors' => array(60.0119, 40.4913, 55.6459), 'position' => 4))), array('position' => 5, 'vehicle' => array('class' => 'class2'), 'laps' => array()), array('position' => 6, 'vehicle' => array('class' => 'class3'), 'laps' => array(array('time' => null, 'sectors' => array(42.4389), 'position' => 6))));
     // Loop each participant data
     foreach ($participants_data as $participant_data) {
         // Create the new participant and populate
         $participant = Participant::createInstance();
         $participant->setPosition($participant_data['position']);
         $vehicle = new Vehicle();
         $vehicle->setClass($participant_data['vehicle']['class']);
         $participant->setVehicle($vehicle);
         // Create each lap
         foreach ($participant_data['laps'] as $lap_key => $lap_data) {
             $lap = new Lap();
             $lap->setTime($lap_data['time'])->setSectorTimes($lap_data['sectors'])->setNumber($lap_key + 1)->setPosition($lap_data['position'])->setParticipant($participant);
             // Process cuts
             if (isset($lap_data['cuts'])) {
                 foreach ($lap_data['cuts'] as $cut_data) {
                     $cut = new Cut();
                     $cut->setCutTime($cut_data['cut_time']);
                     $cut->setTimeSkipped($cut_data['time_skipped']);
                     $date = new \DateTime();
                     $date->setTimestamp($cut_data['time']);
                     $cut->setDate($date);
                     $lap->addCut($cut);
                 }
             }
             // Add lap to participant
             $participant->addLap($lap);
         }
         // Add participant to session
         $session->addParticipant($participant);
     }
     // Return the session
     return $session;
 }