From: Maxious Date: Sun, 07 Aug 2011 02:59:57 +0000 Subject: Travelling all routes thought experiment X-Git-Url: https://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=b6f0ab14a2b745f3e4020771fb76064212574c3e --- Travelling all routes thought experiment --- --- a/.box +++ b/.box @@ -1,5 +1,5 @@ shared_writable_dirs: - /labs/tiles - /lib/staticmaplite/cache -php_extensions: [pgsql,pdo,pdo_pgsql,curl] +php_extensions: [pgsql, pdo, pdo_pgsql, curl] --- a/include/db/trip-dao.inc.php +++ b/include/db/trip-dao.inc.php @@ -173,6 +173,22 @@ $r = $query->fetch(PDO::FETCH_ASSOC); return $r['arrival_time']; } +function getTripEndTime($tripID) +{ + global $conn; + $query = "SELECT trip_id,max(arrival_time) as arrival_time from stop_times + WHERE stop_times.arrival_time IS NOT NULL and trip_id = :tripID group by trip_id"; + debug($query, "database"); + $query = $conn->prepare($query); + $query->bindParam(":tripID", $tripID); + $query->execute(); + if (!$query) { + databaseError($conn->errorInfo()); + return Array(); + } + $r = $query->fetch(PDO::FETCH_ASSOC); + return $r['arrival_time']; +} function getActiveTrips($time) { global $conn; --- /dev/null +++ b/labs/travelAllRoutes.php @@ -1,1 +1,23 @@ +prepare($query); + $query->execute(); +echo ""; +$total = 0; +$count = 0; +foreach($query->fetchAll() as $r) { + $trips = getRouteTrips($r['route_id']); + $startTime = $trips[0]['arrival_time']; + $endTime = getTripEndTime($trips[0]['trip_id']); + $timeDiff = strtotime($endTime) - strtotime($startTime); + $total += $timeDiff; + $count ++; + echo ""; +} +echo "
Route NumberFirst Trip StartFirst Trip EndLength
{$r['route_short_name']}$startTime$endTime$timeDiff seconds ie. ". ($timeDiff/60). " minutes
"; +echo "Total time: $total seconds ie. " .($total/60/60). " hours
"; +echo "$count Routes"; +?>