<commit_before><?php

class TimetableController extends BaseController {
	private function getNationalData($stop){
		$stopData = Stop::where('id', '=', $stop)->get();
		if (!$stopData->isEmpty()){
			$url = 'http://nextbus.mxdata.co.uk/nextbuses/1.0/1';
			$date =  date("Y-m-d\TH:i:s\Z");
			$id = rand(100000, 999999);
			$request = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
						<Siri version="1.0" xmlns="http://www.siri.org.uk/">
						<ServiceRequest>
						<RequestTimestamp>' . $date . '</RequestTimestamp>
						<RequestorRef>' . Config::get('traveline.username') . '</RequestorRef>
						<StopMonitoringRequest version="1.0">
						<RequestTimestamp>' . $date . '</RequestTimestamp>
						<MessageIdentifier>' . $id . '</MessageIdentifier>
						<MonitoringRef>' . $stop . '</MonitoringRef>
						</StopMonitoringRequest>
						</ServiceRequest>
						</Siri>';
			$response = Httpful::post($url)->body($request)->authenticateWith(Config::get('traveline.username'), Config::get('traveline.password'))->sendsXml()->expectsXml()->send();
			$timetable = $response->body->ServiceDelivery->StopMonitoringDelivery;
			$standardTimetable = array();
			foreach($timetable->MonitoredStopVisit as $trip){
				$standardTimetable[] = ['BusName' => (string) $trip->MonitoredVehicleJourney->PublishedLineName, 'BusHeading' => (string) $trip->MonitoredVehicleJourney->DirectionName, 'ArrivalTime' => strtotime((string) $trip->MonitoredVehicleJourney->MonitoredCall->AimedDepartureTime)];
			}
			if (isset($standardTimetable[0]['ArrivalTime'])){
				Redis::setex($stop, $standardTimetable[0]['ArrivalTime'] - time(), json_encode($standardTimetable));
				return $standardTimetable;
			} else {
				return FALSE;
			}
		} else {
			return FALSE;
		}
	}
	private function getManchesterData($stop){
		$stopData = Stop::where('id', '=', $stop)->get();
		$timetable = DB::connection('mysql')->select('SELECT `stop_times`.`departure_time`,`trips`.`trip_id`,`routes`.`route_short_name`,`trips`.`trip_headsign` FROM calendar
			LEFT JOIN `gtfs`.`trips` ON `calendar`.`service_id` = `trips`.`service_id` 
			LEFT JOIN `gtfs`.`routes` ON `trips`.`route_id` = `routes`.`route_id` 
			LEFT JOIN `gtfs`.`stop_times` ON `trips`.`trip_id` = `stop_times`.`trip_id` 
			WHERE(( stop_id = ?) AND ( ' . strtolower(date('l')) . ' = 1) AND ( start_date <= ' . date('Ymd') . ') AND ( end_date >= ' . date('Ymd') . '))
			ORDER BY departure_time', [$stop]);
		if (count($timetable) > 0) {
			$standardTimetable = array();
			foreach($timetable as $trip){
				if (strtotime($trip->departure_time) > time()){
					$standardTimetable[] = ['BusName' => $trip->route_short_name, 'BusHeading' => $trip->trip_headsign, 'ArrivalTime' => strtotime($trip->departure_time)];
				}
			}
			return $standardTimetable;
		} else {
			return FALSE;
		}
	}
	private function getLondonData($stop){
		$baseUrl = Config::get('traveline.tflurl');
		$urlparameters = '?StopCode2=' . $stop . '&ReturnList=LineName,DestinationText,EstimatedTime';
		$response = Httpful::get($baseUrl . $urlparameters)
			->parsewith(function($body) {<commit_msg>SQL query is now webscale! (or tidier using query builder, at least)<commit_after><?php

class TimetableController extends BaseController {
	private function getNationalData($stop){
		$stopData = Stop::where('id', '=', $stop)->get();
		if (!$stopData->isEmpty()){
			$url = 'http://nextbus.mxdata.co.uk/nextbuses/1.0/1';
			$date =  date("Y-m-d\TH:i:s\Z");
			$id = rand(100000, 999999);
			$request = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
						<Siri version="1.0" xmlns="http://www.siri.org.uk/">
						<ServiceRequest>
						<RequestTimestamp>' . $date . '</RequestTimestamp>
						<RequestorRef>' . Config::get('traveline.username') . '</RequestorRef>
						<StopMonitoringRequest version="1.0">
						<RequestTimestamp>' . $date . '</RequestTimestamp>
						<MessageIdentifier>' . $id . '</MessageIdentifier>
						<MonitoringRef>' . $stop . '</MonitoringRef>
						</StopMonitoringRequest>
						</ServiceRequest>
						</Siri>';
			$response = Httpful::post($url)->body($request)->authenticateWith(Config::get('traveline.username'), Config::get('traveline.password'))->sendsXml()->expectsXml()->send();
			$timetable = $response->body->ServiceDelivery->StopMonitoringDelivery;
			$standardTimetable = array();
			foreach($timetable->MonitoredStopVisit as $trip){
				$standardTimetable[] = ['BusName' => (string) $trip->MonitoredVehicleJourney->PublishedLineName, 'BusHeading' => (string) $trip->MonitoredVehicleJourney->DirectionName, 'ArrivalTime' => strtotime((string) $trip->MonitoredVehicleJourney->MonitoredCall->AimedDepartureTime)];
			}
			if (isset($standardTimetable[0]['ArrivalTime'])){
				Redis::setex($stop, $standardTimetable[0]['ArrivalTime'] - time(), json_encode($standardTimetable));
				return $standardTimetable;
			} else {
				return FALSE;
			}
		} else {
			return FALSE;
		}
	}
	private function getManchesterData($stop){
		$stopData = Stop::where('id', '=', $stop)->get();
		$timetable = DB::connection('mysql')->table('calendar')
			->select('stop_times.departure_time', 'trips.trip_id', 'routes.route_short_name', 'trips.trip_headsign')
			->leftJoin('gtfs.trips', 'calendar.service_id', '=', 'trips.service_id')
			->leftJoin('gtfs.routes', 'trips.route_id', '=', 'routes.route_id')
			->leftJoin('gtfs.stop_times', 'trips.trip_id', '=', 'stop_times.trip_id')
			->where('stop_id', '=', $stop)
			->where(strtolower(date('l')), '=', '1')
			->where('start_date', '<=', date('Ymd'))
			->where('end_date', '>=', date('Ymd'))
			->orderBy('departure_time', 'asc')
			->get();
		if (count($timetable) > 0) {
			$standardTimetable = array();
			foreach($timetable as $trip){
				if (strtotime($trip->departure_time) > time()){
					$standardTimetable[] = ['BusName' => $trip->route_short_name, 'BusHeading' => $trip->trip_headsign, 'ArrivalTime' => strtotime($trip->departure_time)];
				}
			}
			return $standardTimetable;
		} else {
			return FALSE;
		}
	}
	private function getLondonData($stop){
		$baseUrl = Config::get('traveline.tflurl');
		$urlparameters = '?StopCode2=' . $stop . '&ReturnList=LineName,DestinationText,EstimatedTime';
		$response = Httpful::get($baseUrl . $urlparameters)
			->parsewith(function($body) {
{'fraction_non_alphanumeric': 0.1993006993006993, 'fraction_numerical': 0.008582326764144946, 'mean_word_length': 4.870335820895522, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 2, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, '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': '1443950', 'n_tokens_mistral': 2523, 'n_tokens_neox': 2124, 'n_words': 325}