From: Maxious Date: Sat, 12 Nov 2011 01:24:16 +0000 Subject: Improve myway timeliness based on new GTFS feed accuracy X-Git-Url: https://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=83b53969937e18ec29a562b672d4d4b20968dd5c --- Improve myway timeliness based on new GTFS feed accuracy --- --- a/include/common-db.inc.php +++ b/include/common-db.inc.php @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -if (php_uname('n') == "actbus-www") { +if (strstr(php_uname('n'),"actbus")) { $conn = new PDO("pgsql:dbname=transitdata;user=transitdata;password=transitdata;host=bus-main.lambdacomplex.org"); } else if (isDebugServer()) { $conn = new PDO("pgsql:dbname=transitdata;user=postgres;password=snmc;host=localhost"); --- a/include/common-request.inc.php +++ b/include/common-request.inc.php @@ -58,7 +58,7 @@ $stopids = explode(",", filter_var($_REQUEST['stopids'], FILTER_SANITIZE_STRING)); } if (isset($_REQUEST['tripid'])) { - $tripid = filter_var($_REQUEST['tripid'], FILTER_SANITIZE_NUMBER_INT); + $tripid = filter_var($_REQUEST['tripid'], FILTER_SANITIZE_STRING); } if (isset($_REQUEST['stopid'])) { $stopid = filter_var($_REQUEST['stopid'], FILTER_SANITIZE_NUMBER_INT); --- a/include/common-template.inc.php +++ b/include/common-template.inc.php @@ -241,5 +241,36 @@ } } +//stop list collapsing +function stopCompare($stopName) { + return substr(trim(preg_replace("/\(Platform.*/", "", $stopName)),0,9); +} +function stopGroupTitle($stopName,$stopdesc) { + if (preg_match("/Dr |Cct |Cir |Av |St |Cr |Parade |Way |Bank /",$stopName)) { + $descParts = explode("
",$stopdesc); + return trim(str_replace("Street: ","",$descParts[0])); + } else { + return trim(preg_replace("/\(Platform.*/", "",$stopName)); + } +} + +function viaPointNames($tripid, $stop_sequence = "") { + $viaPointNames = Array(); + foreach (viaPoints($tripid, $stop_sequence) as $point) { + if (strstr($point['stop_name'], "Station") + || strstr($point['stop_name'], "Shops") + || strstr($point['stop_name'], "CIT") + || strstr($point['stop_name'], "School") + || strstr($point['stop_name'], "University") + ) { + $viaPointNames[] = $point['stop_name']; + } + } + if (sizeof($viaPointNames) > 0) { + return r_implode(", ", $viaPointNames); + } else { + return ""; + } +} ?> --- a/include/common-transit.inc.php +++ b/include/common-transit.inc.php @@ -27,7 +27,8 @@ return $_SESSION['service_period']; $override = getServiceOverride($date); if ($override['service_id']) { - return $override['service_id']; + $idParts = explode("-",$override['service_id']); + return strtolower($idParts[2]); } switch (date('w', ($date != "" ? $date : time()))) { --- a/include/common.inc.php +++ b/include/common.inc.php @@ -31,7 +31,7 @@ $cloudmadeAPIkey = "daa03470bb8740298d4b10e3f03d63e6"; $googleMapsAPIkey = "ABQIAAAA95XYXN0cki3Yj_Sb71CFvBTPaLd08ONybQDjcH_VdYtHHLgZvRTw2INzI_m17_IoOUqH3RNNmlTk1Q"; $otpAPIurl = 'http://localhost:8080/opentripplanner-api-webapp/'; -if (isDebug("awsotp") || php_uname('n') == "maxious.xen.prgmr.com") { +if (isDebug("awsotp") || php_uname('n') == "maxious.xen.prgmr.com" || strstr(php_uname('n'),"actbus")) { $otpAPIurl = 'http://bus-main.lambdacomplex.org:8080/opentripplanner-api-webapp/'; } if (isDebug("dotcloudotp") || php_uname('n') == "actbus-www") { @@ -56,7 +56,7 @@ function isDebugServer() { - return php_sapi_name() == "cli" || isset($_SERVER['SERVER_NAME']) && ( $_SERVER['SERVER_NAME'] == "azusa" || $_SERVER['SERVER_NAME'] == "vanille" + return php_sapi_name() == "cli" || strstr(php_uname('n'),"actbus") || isset($_SERVER['SERVER_NAME']) && ( $_SERVER['SERVER_NAME'] == "azusa" || $_SERVER['SERVER_NAME'] == "vanille" || $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1" || $_SERVER['SERVER_NAME'] == "192.168.1.8"); } --- a/include/db/stop-dao.inc.php +++ b/include/db/stop-dao.inc.php @@ -101,10 +101,10 @@ function getStopsBySuburb($suburb) { global $conn; - $query = "Select * from stops where zone_id LIKE :suburb order by stop_name;"; - debug($query, "database"); - $query = $conn->prepare($query); - $suburb = "%" . $suburb . ";%"; + $query = "Select * from stops where stop_desc LIKE :suburb order by stop_name;"; + debug($query, "database"); + $query = $conn->prepare($query); + $suburb = "%
Suburb: %" . $suburb . "%"; $query->bindParam(":suburb", $suburb); $query->execute(); if (!$query) { @@ -163,19 +163,20 @@ return $query->fetchAll(); } -function getStopTrips($stopID, $service_period = "", $afterTime = "", $limit = "") { +function getStopTrips($stopID, $service_period = "", $afterTime = "", $limit = "", $route_short_name = "") { if ($service_period == "") { $service_period = service_period(); } $service_ids = service_ids($service_period); - $sidA = $service_ids[0]; $sidB = $service_ids[1]; + $limitSQL = ""; if ($limit != "") - $limitSQL = " LIMIT :limit "; + $limitSQL .= " LIMIT :limit "; + global $conn; if ($afterTime != "") { - $query = " SELECT stop_times.trip_id,stop_times.arrival_time,stop_times.stop_id,stop_sequence,service_id,trips.route_id,route_short_name,route_long_name, end_times.arrival_time as end_time + $query = " SELECT stop_times.trip_id,stop_times.arrival_time,stop_times.stop_id,stop_sequence,service_id,trips.route_id,route_short_name,route_long_name,end_times.arrival_time as end_time FROM stop_times join trips on trips.trip_id = stop_times.trip_id @@ -183,7 +184,7 @@ WHERE stop_times.arrival_time IS NOT NULL group by trip_id) as end_times WHERE stop_times.stop_id = :stopID AND stop_times.trip_id = end_times.trip_id -AND (service_id=:service_periodA OR service_id=:service_periodB) +AND (service_id=:service_periodA OR service_id=:service_periodB) ".($route_short_name != "" ? " AND route_short_name = :route_short_name ":"")." AND end_times.arrival_time > :afterTime ORDER BY end_time $limitSQL"; } else { @@ -193,7 +194,7 @@ stop_times.trip_id join routes on trips.route_id = routes.route_id WHERE stop_times.stop_id = :stopID -AND (service_id=:service_periodA OR service_id=:service_periodB) +AND (service_id=:service_periodA OR service_id=:service_periodB) ".($route_short_name != "" ? " AND route_short_name = :route_short_name ":"")." ORDER BY arrival_time $limitSQL"; } debug($query, "database"); @@ -205,6 +206,8 @@ $query->bindParam(":limit", $limit); if ($afterTime != "") $query->bindParam(":afterTime", $afterTime); + if ($route_short_name != "") + $query->bindParam(":route_short_name", $route_short_name); $query->execute(); if (!$query) { databaseError($conn->errorInfo()); --- a/include/db/trip-dao.inc.php +++ b/include/db/trip-dao.inc.php @@ -28,6 +28,7 @@ $query->execute(); if (!$query) { databaseError($conn->errorInfo()); + return Array(); } return $query->fetch(PDO :: FETCH_ASSOC); @@ -56,7 +57,8 @@ function getTripStopTimes($tripID) { global $conn; - $query = "SELECT stop_times.trip_id,trip_headsign,arrival_time,stop_times.stop_id,stop_lat,stop_lon,stop_name,stop_code, + $query = "SELECT stop_times.trip_id,trip_headsign,arrival_time,stop_times.stop_id + ,stop_lat,stop_lon,stop_name,stop_desc,stop_code, stop_sequence,service_id,trips.route_id,route_short_name,route_long_name FROM stop_times join trips on trips.trip_id = stop_times.trip_id @@ -83,6 +85,7 @@ } return Array(); } + function getTripStartTime($tripID) { global $conn; $query = "Select * from stop_times @@ -154,16 +157,5 @@ return $query->fetchAll(); } -function viaPointNames($tripid, $stop_sequence = "") { - $viaPointNames = Array(); - foreach (viaPoints($tripid, $stop_sequence) as $point) { - $viaPointNames[] = $point['stop_name']; - } - if (sizeof($viaPointNames) > 0) { - return r_implode(", ", $viaPointNames); - } else { - return ""; - } -} ?> --- a/myway/myway_timeliness_calculate.php +++ b/myway/myway_timeliness_calculate.php @@ -29,7 +29,8 @@ //collect all observation not in delta $query = "select * from myway_observations INNER JOIN myway_stops -ON myway_observations.myway_stop=myway_stops.myway_stop +ON myway_observations.myway_stop=myway_stops.myway_stop INNER JOIN myway_routes +ON myway_observations.myway_route=myway_routes.myway_route WHERE observation_id NOT IN ( SELECT observation_id @@ -54,10 +55,10 @@ // timezones from http://www.postgresql.org/docs/8.0/static/datetime-keywords.html $time = date("H:i:s", strtotime($obsv['time'])); $time_tz = date("H:i:s", strtotime($obsv['time'])) . " AESST"; - $search_time = date("H:i:s", strtotime($obsv['time']) - (30 * 60)); // 30 minutes margin + $search_time = date("H:i:s", strtotime($obsv['time']) - (60 * 60)); // 30 minutes margin $date = date("c", strtotime($obsv['time'])); $timing_period = service_period(strtotime($date)); - if (isset($obsv["stop_id"]) && $obsv["stop_id"] != "" ) { + if (isset($obsv["stop_id"]) && $obsv["stop_id"] != "" && $obsv["stop_id"] != "*") { $potentialStops = Array(getStop($obsv["stop_id"])); } else { echo "Potential stops are a bus station
"; @@ -79,7 +80,7 @@ //:get myway_route record //no result, skip and display error //print out route - $potentialRoutes = getRoutesByShortName(preg_replace("/[A-Z]/", "", $obsv["myway_route"])); + $potentialRoutes = getRoutesByShortName($obsv["route_short_name"]); if (sizeof($potentialRoutes) < 1) { echo "error, route '{$obsv["myway_route"]}' unknown"; continue; @@ -96,7 +97,7 @@ echo "Matching route {$stopRoute['route_id']} found at stop #{$potentialStop['stop_id']}
"; $foundRoute = $stopRoute; //if does get tripstoptimes for this route - $trips = getStopTrips($potentialStop['stop_id'], $timing_period, $search_time); + $trips = getStopTrips($potentialStop['stop_id'], $timing_period, $search_time, 10, $potentialRoute['route_short_name']); foreach ($trips as $trip) { //echo $trip['route_id']." ".$stopRoute['route_id'].";"; if ($trip['route_id'] == $stopRoute['route_id']) { @@ -109,13 +110,16 @@ "timeDiff" => $timeDiff, "stop_id" => $potentialStop['stop_id'], "stop_sequence" => $trip['stop_sequence'], - "route_name" => "{$potentialRoute['route_short_name']} {$potentialRoute['route_long_name']} {$trip['direction']}", + "route_name" => "{$trip['route_short_name']} {$trip['route_long_name']} {$trip['direction']}", "route_id" => $trip['route_id'] ); echo "Found trip {$trip['trip_id']} at stop {$potentialStop['stop_id']} (#{$potentialStop['stop_name']}, sequence #{$trip['stop_sequence']})
"; echo "Arriving at {$timedTrip['arrival_time']}, difference of " . round($timeDiff / 60, 2) . " minutes
"; + } else { + echo "{$trip['route_id']} != {$stopRoute['route_id']}
"; } } + if (sizeof($timeDeltas) == 0) echo "Error, no trips found.
"; break; // because have found route } } @@ -163,6 +167,7 @@ } var_dump($conn->errorInfo()); flush(); + } } flush(); --- a/myway/myway_timeliness_route.json.php +++ b/myway/myway_timeliness_route.json.php @@ -25,7 +25,8 @@ "data": prepare($query); -$query->bindParam(':route_name', $_REQUEST['routeid'], PDO::PARAM_STR, 42); +$_REQUEST['routeid'].=" "; +$query->bindParam(':route_name', $_REQUEST['routeid'], PDO::PARAM_STR); $query->execute(); if (!$query) { --- a/myway/myway_timeliness_stop.php +++ b/myway/myway_timeliness_stop.php @@ -46,9 +46,7 @@ var data = []; var options = { xaxis: { - mode: "time", - min: midnight + (1000*60*60*8), - max: midnight + (1000*60*60*23.5) + mode: "time" }, yaxis: { tickFormatter: yformatter --- a/stopList.php +++ b/stopList.php @@ -17,17 +17,7 @@ */ include ('include/common.inc.php'); $stops = Array(); -function stopCompare($stopName) { - return substr(trim(preg_replace("/\(Platform.*/", "", $stopName)),0,9); -} -function stopGroupTitle($stopName,$stopdesc) { - if (preg_match("/Dr |Cct |Cir |Av |St |Cr |Parade |Way |Bank /",$stopName)) { - $descParts = explode("
",$stopdesc); - return trim(str_replace("Street: ","",$descParts[0])); - } else { - return trim(preg_replace("/\(Platform.*/", "",$stopName)); - } -} + function navbar() { echo '
@@ -149,7 +139,7 @@ } else { // subsequent duplicates $stopsGrouped["stop_ids"][] = $stop['stop_id']; - ; + } } } --- a/trip.php +++ b/trip.php @@ -24,7 +24,6 @@ $trip = getTrip($tripid); $routeid = $trip["route_id"]; } - include_header("Stops on " . $trip['route_short_name'] . ' ' . $trip['route_long_name'], "trip"); trackEvent("Route/Trip View", "View Route", $trip['route_short_name'] . ' ' . $trip['route_long_name'], $routeid); echo ''; @@ -69,9 +68,9 @@ $tripStopTimes = getTripStopTimes($tripid); echo '
  • ' . $tripStopTimes[0]['arrival_time'] . ' to ' . $tripStopTimes[sizeof($tripStopTimes) - 1]['arrival_time'] . ' ' . $trip['route_long_name'] . ' (' . ucwords($tripStopTimes[0]['service_id']) . ')
  • '; foreach ($tripStopTimes as $key => $tripStopTime) { - if ($key + 1 > sizeof($tripStopTimes) || ($tripStopTimes[$key]["stop_name"] != $tripStopTimes[$key + 1]["stop_name"])) { + if ($key + 1 > sizeof($tripStopTimes) || stopCompare($tripStopTimes[$key]["stop_name"]) != stopCompare($tripStopTimes[$key + 1]["stop_name"])) { echo '
  • '; - + if (sizeof($stopsGrouped) > 0) { // print and empty grouped stops // subsequent duplicates @@ -83,7 +82,8 @@ echo '
    ' . distance($tripStopTime['stop_lat'], $tripStopTime['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; } echo '

    '; - echo $tripStopTime["stop_name"]; + echo stopGroupTitle($tripStopTime['stop_name'],$tripStopTime['stop_desc']) . '
    ' . sizeof($stopsGrouped["stop_ids"]) . ' stops'; + echo '
  • '; flush(); @ob_flush(); @@ -103,10 +103,10 @@ } } else { // this is a duplicated line item - if ($key - 1 <= 0 || ($tripStopTimes[$key]['stop_name'] != $tripStopTimes[$key - 1]['stop_name'])) { + if ($key - 1 <= 0 || stopCompare($tripStopTimes[$key]['stop_name']) != stopCompare($tripStopTimes[$key - 1]['stop_name'])) { // first duplicate $stopsGrouped = Array( - "name" => $tripStopTime['stop_name'], + "name" => trim(preg_replace("/\(Platform.*/", "", $stop['stop_name'])), "startTime" => $tripStopTime['arrival_time'], "stop_ids" => Array( $tripStopTime['stop_id']