/**
  * Default constructor
  * @param string[] $fileContent
  */
 function __construct($fileContent)
 {
     $this->fileContent = $fileContent;
     $this->totalResult = new Event\TotalResult();
     $section = 0;
     $driSectArr = array();
     $lapSectArr = array();
     $lapSectIndex = array();
     $type2input = false;
     $currRaceId = 0;
     $finish_position = 0;
     // set variable
     // process input file content
     foreach ($fileContent as $line) {
         if (trim($line) != "" || $section === 2) {
             $originalLine = $line;
             $line = trim($line);
             if (mb_strstr($line, "Round#") !== false && mb_strstr($line, "Race#") !== false) {
                 // start new race
                 $section = 0;
                 $race_name_line_arr = preg_split("/[\\s]{5,}/u", $line);
                 $currRaceName = trim($race_name_line_arr[0]);
                 //$total_data[$curr_race] = array();
                 $currRaceId = (string) $this->totalResult->addRace($currRaceName);
             } else {
                 if (preg_match('/.*Driver.*Car#.*Laps.*/u', $line)) {
                     $section = 1;
                     $driSectArr = $this->get_driver_section_header_array($line);
                     $finish_position = 1;
                 } else {
                     if (preg_match('/.*1\\_.+2\\_.+3\\_.*/u', $line)) {
                         $section = 2;
                         $lapSectArr = $this->get_lap_section_header_array($originalLine);
                         $lapSectIndex = $this->get_lap_section_index($originalLine);
                     } else {
                         if ($section === 2 && preg_match('/----/u', $line)) {
                             $section = 3;
                         } else {
                             if ($section === 1) {
                                 $elementArr = preg_split('/\\s+/u', $line);
                                 $i = 1;
                                 $name = true;
                                 $currData = new Event\RaceDriverData();
                                 $driverName = "";
                                 foreach ($elementArr as $e) {
                                     // Assuming all start with driver's name
                                     if ($name && !preg_match('/#\\d/u', $e)) {
                                         $driverName .= " " . $e;
                                     } else {
                                         $name = false;
                                         $mapped = $this->getRaceDriverDataMapping($driSectArr[$i]);
                                         if (!empty($mapped)) {
                                             $currData->{$mapped} = $e;
                                         }
                                         $i++;
                                     }
                                 }
                                 $currData->name = trim($driverName);
                                 $currData->carNum = str_replace("#", "", $currData->carNum);
                                 $currData->finishPosition = $finish_position;
                                 $finish_position++;
                                 $this->totalResult->{$currRaceId}->addDriver($currData);
                             } else {
                                 if ($section === 2) {
                                     if (empty($line)) {
                                         $type2input = true;
                                     } else {
                                         $first_ending_splitter_index = 1;
                                         // first delimiter is in the beginning of the line, so we start from 1. this index is fixed for $lapSectArr
                                         for ($i = $first_ending_splitter_index; $i < count($lapSectIndex); $i++) {
                                             $plap_section = mb_substr($originalLine, $lapSectIndex[$i - 1], $lapSectIndex[$i] - $lapSectIndex[$i - 1]);
                                             $plap_section = trim($plap_section);
                                             if (!empty($plap_section)) {
                                                 $plap_section = explode("/", $plap_section);
                                                 //var_dump($plap_section);
                                                 $this->totalResult->raceResultList[$currRaceId]->{$lapSectArr}[$i - 1]->lapData->addLapTime(floatval($plap_section[1]));
                                             }
                                         }
                                     }
                                 } else {
                                     if ($section === 3) {
                                         // when new race starts, finish last race first
                                         if ($type2input) {
                                             // if it's second type of input, need to remove un-needed lines of data
                                             foreach ($lapSectArr as $carNum) {
                                                 if (!is_null($this->totalResult->{$currRaceId}->{$carNum})) {
                                                     $this->totalResult->{$currRaceId}->{$carNum}->lapData->removeEveryOtherLapTime();
                                                 }
                                             }
                                         }
                                         $section = 4;
                                         // 4 means end of one race
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     foreach ($this->totalResult->raceResultList as $currRaceId => $result) {
         $this->totalResult->raceResultList[$currRaceId]->cleanUpDriver();
     }
     unset($this->fileContent);
 }
 function __construct($fileContent)
 {
     $this->fileContent = $fileContent;
     $this->totalResult = new Event\TotalResult();
     $this->minLegalLaptime = 0;
     $this->totalResult->addRace("RaceName");
     $stage = "start";
     /*
     			$this->name = "";
     			$this->nickname = "";
     			$this->bestLap = '';
     			$this->totalLaps = '';
     			$this->totalTime = '';
     			$this->carNum = '';
     			$this->behind = '';
     			$this->averageLap = '';
     			$this->finishPosition = 0;
     			$this->lapData = new RaceDriverLapResult();
     */
     foreach ($this->fileContent as $line) {
         $cleanLine = trim($line);
         if (empty($cleanLine)) {
             //$stage = "laptimes";
         } else {
             if ($stage == "start") {
                 // general info area
                 // check if there's minimum legal laptime setting, if so, setup member var
                 if (mb_strpos($cleanLine, "MinimumLegalLaptime") === 0) {
                     $lineArr = explode("=", $cleanLine);
                     if (count($lineArr) > 1 && !empty($lineArr[1])) {
                         $this->minLegalLaptime = floatval($lineArr[1]);
                         continue;
                     }
                 }
                 if (mb_strpos($cleanLine, "Pos") === 0) {
                     $stage = "general_info";
                     continue;
                 }
             } else {
                 if ($stage == "general_info") {
                     $lineArr = explode("\t", $cleanLine);
                     if ($lineArr[0] == "#") {
                         $stage = "laptimes_content";
                         continue;
                     }
                     /*
                     						0   Pos
                     						1	No.
                     						2	Name
                     						3	Laps
                     						4	Diff
                     						5	Gap
                     						6	Total Tm
                     						7	Best Tm
                     						8	In Lap
                     						9	Nat/State
                     						10	Sponsor
                     */
                     $currRaceDriverData = new Event\RaceDriverData();
                     $currRaceDriverData->name = $lineArr[2];
                     $currRaceDriverData->bestLap = Common\Globals::convertTimeToSeconds($lineArr[7]);
                     $currRaceDriverData->totalLaps = $lineArr[3];
                     $currRaceDriverData->totalTime = $lineArr[6];
                     $currRaceDriverData->carNum = $lineArr[1];
                     $currRaceDriverData->behind = trim($lineArr[5], " -");
                     $currRaceDriverData->finishPosition = $lineArr[0];
                     $this->totalResult->raceResultList[0]->addDriver($currRaceDriverData);
                     continue;
                 } else {
                     if ($stage == "laptimes") {
                         /*
                         						0	#
                         						1	No.
                         						2	Name
                         						3	Laps
                         						4	Lead
                         						5	Lap Tm
                         						6	Elapsed Tm
                         						7	Time of Day
                         						8	Hits
                         						9	Strength
                         						10	Tx
                         */
                         $lineArr = explode("\t", $cleanLine);
                         if ($lineArr[0] == "#") {
                             $stage = "laptimes_content";
                         }
                         continue;
                     } else {
                         if ($stage == "laptimes_content") {
                             $lineArr = explode("\t", $cleanLine);
                             if (($lineArr[2] == "Green Flag" || $lineArr[2] == "Extra Flag" || $lineArr[2] == "Finish Flag") && $lineArr[3] == "") {
                                 // ignore this line
                                 continue;
                             } else {
                                 $currracerId = intval($lineArr[1]);
                                 if (preg_match('/[0-9]+/u', $lineArr[5])) {
                                     $laptime = Common\Globals::convertTimeToSeconds($lineArr[5]);
                                 } else {
                                     $laptime = Common\Globals::convertTimeToSeconds($lineArr[6]);
                                 }
                                 $this->totalResult->raceResultList[0]->driverList[$this->totalResult->raceResultList[0]->getIdByCarNum($currracerId)]->lapData->addLapTime($laptime, $this->minLegalLaptime);
                             }
                         }
                     }
                 }
             }
         }
     }
 }