--- a/stop.php +++ b/stop.php @@ -16,8 +16,9 @@ limitations under the License. */ include ('include/common.inc.php'); -if ($stopid) +if (isset($stopid)) { $stop = getStop($stopid); +} /* if ($stopcode != "" && $stop[5] != $stopcode) { $url = $APIurl . "/json/stopcodesearch?q=" . $stopcode; $stopsearch = json_decode(getPage($url)); @@ -85,7 +86,7 @@ echo '<div id="servicewarning">'.$serviceAlert['alert']['description']['translation'].'</div>'; } */ -echo '<span class="content-secondary">'; +echo '<div class="content-secondary">'; echo $stopLinks; if (sizeof($stops) > 0) { trackEvent("View Stops", "View Combined Stops", $stop["stop_name"], $stop["stop_id"]); @@ -102,7 +103,7 @@ timeSettings(); -echo '</span><span class="content-primary">'; +echo '</div><div class="content-primary">'; echo ' <ul data-role="listview" data-inset="true">'; if (sizeof($allStopsTrips) > 0) { sktimesort($allStopsTrips, "arrival_time", true); @@ -140,6 +141,30 @@ if (sizeof($trips) == 0) { echo "<li style='text-align: center;'>No trips in the near future.</li>"; } else { + if (isset($labs)) { +// ETA calculation + + $tripETA = Array(); + // max/min delay instead of stddev? + $query = $query = "select 'lol', avg(timing_delta), stddev(timing_delta), count(*) from myway_timingdeltas where extract(hour from time) between ".date("H", $earlierTime)." and ".date("H", $laterTime); + //select 'lol', stop_id,extract(hour from time), avg(timing_delta), stddev(timing_delta), count(*) from myway_timingdeltas where stop_id = '5501' group by stop_id, extract(hour from time) order by extract(hour from time) + $query = $conn->prepare($query); + $query->execute(); + if (!$query) { + databaseError($conn->errorInfo()); + return Array(); + } + $ETAparams = Array(); + foreach ($query->fetchAll() as $row) { + $ETAparams[$row[0]] = Array("avg"=> $row[1], "stddev"=>floor($row[2]),"count"=>$row[3]); + }; + //print_r($ETAparams); + foreach ($trips as $trip) { + $tripETA[$trip['trip_id']] = date("H:i",strtotime($trip['arrival_time']." - ".(floor($ETAparams['lol']['stddev']))." seconds"))." to ". + date("H:i",strtotime($trip['arrival_time']." + ".(floor($ETAparams['lol']['stddev']))." seconds")); + } + //print_r($tripETA); +} foreach ($trips as $trip) { if ( isset($filterHasStop) && (getTripHasStop($trip['trip_id'], $filterHasStop) == 1) @@ -151,6 +176,9 @@ $destination = getTripDestination($trip['trip_id']); echo '<a href="trip.php?stopid=' . $stopid . '&tripid=' . $trip['trip_id'] . '"><h3>' . $trip['route_short_name'] . " towards " . $destination['stop_name'] . "</h3><p>"; $viaPoints = viaPointNames($trip['trip_id'], $trip['stop_sequence']); +if (isset($labs)) { + echo '<br><span class="eta">ETA: ' . $tripETA[$trip['trip_id']] . '</span>'; + } if ($viaPoints != "") echo '<br><span class="viaPoints">Via: ' . $viaPoints . '</span>'; if (sizeof($tripStopNumbers) > 0) { @@ -173,7 +201,7 @@ } } echo '</ul>'; -echo '</span>'; +echo '</div>'; include_footer(); ?>