From: maxious Date: Mon, 13 Jun 2011 01:59:26 +0000 Subject: Start on service alerts api X-Git-Url: http://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=947916e24c85471831b2b83c7b0621b9accfd4da --- Start on service alerts api --- --- /dev/null +++ b/geo/route.kml.php @@ -1,1 +1,30 @@ + +'; +echo ' + '; +$route = getRoute($routeid); + echo "\n\n"; + $link = curPageURL()."/../trip.php?routeid=".htmlspecialchars ($route["route_id"]); + echo "".$route['route_short_name'].""; + echo ''; + echo ''.$route['route_short_name']." ".$route['route_long_name']."]]> "; +echo "#yellowLineGreenPoly"; + $trips = getRouteTrips($routeid); + echo getTripShape($trips[0]['trip_id']); + +echo "\n\n"; +?> + + --- /dev/null +++ b/geo/stops.kml.php @@ -1,1 +1,36 @@ - +createElementNS('http://earth.google.com/kml/2.1', 'kml'); +$parNode = $dom->appendChild($node); +// Creates a KML Document element and append it to the KML element. +$dnode = $dom->createElement('Document'); +$docNode = $parNode->appendChild($dnode); +if ($suburb != "") $result_stops = getStopsBySuburb($suburb); +else $result_stops = getStops(); +foreach ($result_stops as $stop) { + $description = 'http://bus.lambdacomplex.org/' . 'stop.php?stopid=' . $stop['stop_id'] . "
"; + // Creates a Placemark and append it to the Document. + $node = $dom->createElement('Placemark'); + $placeNode = $docNode->appendChild($node); + // Creates an id attribute and assign it the value of id column. + $placeNode->setAttribute('id', 'placemark' . $stop['stop_id']); + // Create name, and description elements and assigns them the values of the name and address columns from the results. + $nameNode = $dom->createElement('name', htmlentities($stop['stop_name'])); + $descriptionNode = $dom->createElement('description', $description); + $placeNode->appendChild($nameNode); + $placeNode->appendChild($descriptionNode); + // Creates a Point element. + $pointNode = $dom->createElement('Point'); + $placeNode->appendChild($pointNode); + // Creates a coordinates element and gives it the value of the lng and lat columns from the results. + $coorStr = $stop['stop_lon'] . ',' . $stop['stop_lat']; + $coorNode = $dom->createElement('coordinates', $coorStr); + $pointNode->appendChild($coorNode); +} +$kmlOutput = $dom->saveXML(); +echo $kmlOutput; +?> --- a/include/common-session.inc.php +++ b/include/common-session.inc.php @@ -41,9 +41,6 @@ } } } - if ($_SESSION['lat'] != "" && isAnalyticsOn()) { - trackEvent("Geolocation", "Updated Location", "Geocoded - " . ($geocoded ? "Yes" : "No")); - } sessionUpdated(); } function sessionUpdated() @@ -63,3 +60,4 @@ return ($_SESSION['time'] ? $_SESSION['time'] : date("H:i:s")); } ?> + --- a/include/common.inc.php +++ b/include/common.inc.php @@ -163,7 +163,7 @@ $key => $val )); } - if ($sort_ascending) $array = array_reverse($temp_array); + if ($sort_ascending && isset($temp_array)) $array = array_reverse($temp_array); else $array = $temp_array; } function r_implode( $glue, $pieces ) --- a/include/db/route-dao.inc.php +++ b/include/db/route-dao.inc.php @@ -13,6 +13,7 @@ } return $query->fetch(PDO::FETCH_ASSOC); } + function getRoutes() { global $conn; --- a/include/db/stop-dao.inc.php +++ b/include/db/stop-dao.inc.php @@ -30,7 +30,7 @@ } $query.= " order by stop_name;"; $query = $conn->prepare($query); - $query->bindParam(":firstLetter", $firstLetter); + if ($firstLetter != "") $query->bindParam(":firstLetter", $firstLetter); $query->execute(); if (!$query) { databaseError($conn->errorInfo()); --- a/include/db/trip-dao.inc.php +++ b/include/db/trip-dao.inc.php @@ -16,40 +16,25 @@ } return $query->fetch(PDO::FETCH_ASSOC); } -function getTripShape() -{ - /* def handle_json_GET_tripstopTimes(self, params): - schedule = self.server.schedule - try: - trip = schedule.GetTrip(params.get('trip')) - except KeyError: - # if a non-existent trip is searched for, the return nothing - return - time_stops = trip.GetTimeInterpolatedStops() - stops = [] - times = [] - for arr,ts,is_timingpoint in time_stops: - stops.append(StopToTuple(ts.stop)) - times.append(arr) - return [stops, times] - - def handle_json_GET_tripshape(self, params): - schedule = self.server.schedule - try: - trip = schedule.GetTrip(params.get('trip')) - except KeyError: - # if a non-existent trip is searched for, the return nothing - return - points = [] - if trip.shape_id: - shape = schedule.GetShape(trip.shape_id) - for (lat, lon, dist) in shape.points: - points.append((lat, lon)) - else: - time_stops = trip.GetTimeStops() - for arr,dep,stop in time_stops: - points.append((stop.stop_lat, stop.stop_lon)) - return points*/ +function getTripShape($tripID) +{ + global $conn; + $query = "SELECT ST_AsKML(ST_MakeLine(geometry(a.position))) as the_route +FROM (SELECT position, + stop_sequence, trips.trip_id +FROM stop_times +join trips on trips.trip_id = stop_times.trip_id +join stops on stops.stop_id = stop_times.stop_id +WHERE trips.trip_id = :tripID ORDER BY stop_sequence) as a group by a.trip_id"; + debug($query, "database"); + $query = $conn->prepare($query); + $query->bindParam(":tripID", $tripID); + $query->execute(); + if (!$query) { + databaseError($conn->errorInfo()); + return Array(); + } + return $query->fetchColumn(0); } function getTimeInterpolatedTrip($tripID, $range = "") { --- a/index.php +++ b/index.php @@ -28,5 +28,4 @@ echo ' Busness R&D'; include_footer(true) ?> - --- a/labs/index.php +++ b/labs/index.php @@ -10,6 +10,8 @@

Analysis of route timing points

  • Bus Stop Density Map

    Analysis of bus stop coverage

  • +
  • Bus Stop Browser Map

    +

    Bus stop location/route browser

  • More coming soon!
  • --- a/labs/myway_api.json.php +++ b/labs/myway_api.json.php @@ -23,7 +23,7 @@ "DOBday" => "day", "DOByear" => "year", "secret_answer" => "pwrd", - "button" => "button" + "button" => "Submit" ); foreach (Array( "card_number", @@ -64,6 +64,7 @@ curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_REFERER, "https://www.action.act.gov.au/ARTS/getbalance.asp"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 30); //execute post @@ -75,6 +76,7 @@ if (!isset($return['error'])) { include_once ('lib/simple_html_dom.php'); + //print_r($pageHTML); $page = str_get_html($pageHTML); $pageAlerts = $page->find(".smartCardAlert"); if (sizeof($pageAlerts) > 0) { @@ -94,12 +96,14 @@ $tableColumns[$tableColumnNum] = cleanString($th->plaintext); $tableColumnNum++; } + //print_r($tableColumns); $tableRowNum = 0; foreach ($table->find("tr") as $tr) { $tableColumnNum = 0; foreach ($tr->find("td") as $td) { if ($tableNum == 1) $return[$tableName[$tableNum]][$tableColumns[$tableColumnNum]] = cleanString($td->plaintext); else $return[$tableName[$tableNum]][$tableRowNum][$tableColumns[$tableColumnNum]] = cleanString($td->plaintext); + //print_r($return); $tableColumnNum++; } $tableRowNum++; --- a/labs/mywaybalance.php +++ b/labs/mywaybalance.php @@ -29,8 +29,10 @@ echo '