/**
  * @param InputInterface $input
  * @param OutputInterface $out
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $out)
 {
     $this->outputHeading($out, "Transfer Patterns");
     $scanDate = $this->getNextScanDate();
     $nonTimetableConnections = $this->outputTask($out, "Loading non-timetable connections", function () use($scanDate) {
         return $this->scheduleProvider->getNonTimetableConnections(strtotime($scanDate . " UTC"));
     });
     $timetables = $this->outputTask($out, "Loading timetables", function () use($scanDate) {
         return $this->scheduleProvider->getTimetableConnections(strtotime("{$scanDate} 00:00 UTC"));
     });
     $interchange = $this->outputTask($out, "Loading interchange", function () {
         return $this->scheduleProvider->getInterchangeTimes();
     });
     $stations = array_keys($this->stationProvider->getLocations());
     $persistence = new TransferPatternPersistence($timetables, $nonTimetableConnections, $interchange);
     $this->outputTask($out, "Calculating transfer patterns", function () use($stations, $persistence, $scanDate) {
         //            $persistence->calculateTransferPatternsForStation(call_user_func($this->dbFactory), "MYB", $scanDate);
         //            return;
         $callable = function ($station) use($persistence, $scanDate) {
             $persistence->calculateTransferPatternsForStation(call_user_func($this->dbFactory), $station, $scanDate);
         };
         $this->processManager->process($stations, $callable, $this->forkStrategy);
         $this->processManager->wait();
     });
     $this->setLastScanDate($scanDate);
     $this->outputMemoryUsage($out);
     return 0;
 }
 /**
  * @param  OutputInterface $out
  * @param  string          $origin
  * @param  string          $destination
  * @param  int             $targetTime
  */
 private function planJourney(OutputInterface $out, $origin, $destination, $targetTime)
 {
     $this->outputHeading($out, "Journey Planner");
     $timetableConnections = $this->outputTask($out, "Loading timetable", function () use($targetTime, $origin) {
         return $this->scheduleProvider->getTimetableConnections($targetTime);
     });
     $nonTimetableConnections = $this->outputTask($out, "Loading non timetable connections", function () use($targetTime) {
         return $this->scheduleProvider->getNonTimetableConnections($targetTime);
     });
     $interchangeTimes = $this->outputTask($out, "Loading interchange", function () {
         return $this->scheduleProvider->getInterchangeTimes();
     });
     $locations = $this->outputTask($out, "Loading locations", function () {
         return $this->stationProvider->getLocations();
     });
     $scanner = new ConnectionScanner($timetableConnections, $nonTimetableConnections, $interchangeTimes);
     $route = $this->outputTask($out, "Plan journey", function () use($scanner, $targetTime, $origin, $destination) {
         return $scanner->getJourneys($origin, $destination, strtotime('1970-01-01 ' . gmdate('H:i:s', $targetTime) . ' UTC'));
     });
     if (count($route) === 0) {
         $out->writeln("No route found.");
     } else {
         $this->displayRoute($out, $locations, $route[0]);
     }
     $this->outputMemoryUsage($out);
     $out->writeln("Connections: " . count($timetableConnections));
 }
 /**
  * @param  string[] $origins
  * @param  string[] $destinations
  * @param  int $departureDateTime
  * @return Journey[]
  */
 public function getJourneys($origins, $destinations, $departureDateTime)
 {
     $interchange = $this->scheduleProvider->getInterchangeTimes();
     $nonTimetable = $this->scheduleProvider->getNonTimetableConnections($departureDateTime);
     $departureTime = strtotime('1970-01-01 ' . gmdate('H:i', $departureDateTime) . ' UTC');
     $results = [];
     foreach ($origins as $o) {
         foreach ($destinations as $d) {
             $schedules = $this->scheduleProvider->getTimetable($o, $d, $departureDateTime);
             foreach ($schedules as $schedule) {
                 $scanner = new SchedulePlanner($schedule, $nonTimetable, $interchange);
                 $results = array_merge($results, $scanner->getJourneys($o, $d, $departureTime));
             }
         }
     }
     foreach ($this->filters as $filter) {
         $results = $filter->filter($results);
     }
     return $results;
 }