--- a/stop.php
+++ b/stop.php
@@ -141,6 +141,30 @@
if (sizeof($trips) == 0) {
echo "
No trips in the near future.";
} 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)
@@ -152,6 +176,9 @@
$destination = getTripDestination($trip['trip_id']);
echo '' . $trip['route_short_name'] . " towards " . $destination['stop_name'] . "
";
$viaPoints = viaPointNames($trip['trip_id'], $trip['stop_sequence']);
+if (isset($labs)) {
+ echo '
ETA: ' . $tripETA[$trip['trip_id']] . '';
+ }
if ($viaPoints != "")
echo '
Via: ' . $viaPoints . '';
if (sizeof($tripStopNumbers) > 0) {