From: Maxious Date: Fri, 23 Mar 2012 08:28:19 +0000 Subject: Beginnings of ETA calc based on actual data X-Git-Url: https://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=b895ed0fe961eb254ee2b2f21b2f6e2666024455 --- Beginnings of ETA calc based on actual data --- --- a/.gitmodules +++ b/.gitmodules @@ -10,4 +10,9 @@ [submodule "js/yepnope"] path = js/yepnope url = https://github.com/SlexAxton/yepnope.js.git - +[submodule "javascripts/tesseract"] + path = javascripts/tesseract + url = https://github.com/square/tesseract.git +[submodule "javascripts/d3"] + path = javascripts/d3 + url = https://github.com/mbostock/d3.git --- a/include/common-request.inc.php +++ b/include/common-request.inc.php @@ -29,6 +29,9 @@ } if (isset($_REQUEST['nearby'])) { $nearby = true; +} +if (isset($_REQUEST['labs'])) { + $labs = true; } if (isset($_REQUEST['suburb'])) { $suburb = $_REQUEST['suburb']; --- a/include/db/servicealert-dao.inc.php +++ b/include/db/servicealert-dao.inc.php @@ -106,7 +106,19 @@ function getFutureAlerts() { global $conn; - $query = "SELECT id,extract('epoch' from start) as start, extract('epoch' from \"end\") as \"end\",cause,effect,header,description,url from servicealerts_alerts where NOW() > start or NOW() < \"end\""; + $query = "SELECT id,extract('epoch' from start) as start, extract('epoch' from \"end\") as \"end\",cause,effect,header,description,url from servicealerts_alerts where NOW() < \"end\""; + // debug($query, "database"); + $query = $conn->prepare($query); + $query->execute(); + if (!$query) { + databaseError($conn->errorInfo()); + return Array(); + } + return $query->fetchAll(); +} +function getAllAlerts() { + global $conn; + $query = "SELECT id,extract('epoch' from start) as start, extract('epoch' from \"end\") as \"end\",cause,effect,header,description,url from servicealerts_alerts"; // debug($query, "database"); $query = $conn->prepare($query); $query->execute(); --- /dev/null +++ b/labs/busdelay.csv.php @@ -1,1 +1,52 @@ +prepare(' +SELECT * from myway_timingdeltas' + , array(PDO::ATTR_CURSOR => PDO::FETCH_ORI_NEXT)); +$query->execute(); +$errors = $conn->errorInfo(); +if ($errors[2] != "") { + die("Export terminated, db error" . print_r($errors, true)); +} + +$headers = Array("date", "delay", "distance", "origin", "destination"); + +$fp = fopen('php://output', 'w'); +if ($fp && $query) { + //header('Content-Type: text/csv'); + header('Pragma: no-cache'); + header('Expires: 0'); + fputcsv($fp, $headers); + while ($r = $query->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) { + $row = Array(); + foreach ($headers as $i => $fieldName) { + switch ($fieldName) { + case "date": + $row[] = date("r",strtotime($r['date']." ".$r['time'])); + break; + case "delay": + $row[] = $r['timing_delta']; + break; + case "distance": + $row[] = $r['stop_sequence']; + break; + case "origin": + $row[] = $r['myway_stop']; + break; + case "destination": + $row[] = $r['route_name']; + break; + default: + break; + } + } + fputcsv($fp, array_values($row)); + } + die; +} +?> + + --- /dev/null +++ b/labs/busdelay.php @@ -1,1 +1,495 @@ - + + +Tesseract + + + +
+
+
Time of Day
+
+
+
Arrival Delay (min.)
+
+
+
Distance (mi.)
+
+
+
Date
+
+
+ + + +
+
+
+ + + + + + + + + --- a/rtpis/servicealert_editor.php +++ b/rtpis/servicealert_editor.php @@ -82,7 +82,7 @@ '; + echo "'; } ?>
" . date("c", $alert['start']) . "" . date("c", $alert['end']) . "" . substr($alert['description'], 0, 999) . 'edit
" . date("c", $alert['start']) . "
to
" . date("c", $alert['end']) . "
" .$alert['header']."
". $alert['description'] . '
edit
--- a/stop.php +++ b/stop.php @@ -141,6 +141,30 @@ if (sizeof($trips) == 0) { echo "
  • No trips in the near future.
  • "; } else { + if ($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 ($labs) { + echo '
    ETA: ' . $tripETA[$trip['trip_id']] . ''; + } if ($viaPoints != "") echo '
    Via: ' . $viaPoints . ''; if (sizeof($tripStopNumbers) > 0) {