From: Maxious Date: Sun, 22 Jan 2012 07:48:08 +0000 Subject: Happy New Year! Remove Christmas special holiday timetable support. X-Git-Url: http://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=cce094e5aea458c0958da1d95fdaafb86008d936 --- Happy New Year! Remove Christmas special holiday timetable support. --- --- a/about.php +++ b/about.php @@ -35,7 +35,8 @@ Some icons by Joseph Wain / glyphish.com
Native clients also available for iPhone(cbrTimetable by Sandor Kolotenko , ACT Buses by David Sullivan) - , Android (MyBus 2.0 by Imagine Team) + , Android (MyBus 2.0 by Imagine Team, GetMe2 Canberra by +Colin Thompson ) and Windows Phone 7 (TransHub Canberra by Soul Solutions) Other web clients include iTranzit.
GTFS-realtime API: --- a/include/common-template.inc.php +++ b/include/common-template.inc.php @@ -175,7 +175,7 @@
'; if ($GTFSREnabled) { $overrides = getServiceOverride(); - if ($overrides['service_id']) { + if (isset($overrides['service_id'])) { if ($overrides['service_id'] == "noservice") { echo '
Buses are not running today due to industrial action/public holiday. See http://www.action.act.gov.au for details.
'; @@ -212,9 +212,37 @@ } echo "\n
"; } - +function timeSettings() { + global $service_periods; +echo '
+

Change Time (' . (isset($_REQUEST['time']) ? $_REQUEST['time'] : "Current Time,") . ' ' . ucwords(service_period()) . ')...

+
+ + + + +
+
+ + + Current Time? +
+
+ + + +
+ + +
+
'; +} function placeSettings() { - global $service_periods; + $geoerror = false; $geoerror = !isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == ""; --- a/include/common-transit.inc.php +++ b/include/common-transit.inc.php @@ -20,41 +20,44 @@ 'saturday', 'weekday' ); -function service_period_day ($spid) { - $idParts = explode("-",$spid); - return strtolower($idParts[2]); -} + function service_period($date = "") { - if (isset($_REQUEST['service_period'])) + if (isset($_REQUEST['service_period'])) { return $_REQUEST['service_period']; + } + $override = getServiceOverride($date); - if ($override['service_id']) { - return service_period_day ($override['service_id']); - } - - switch (date('w', ($date != "" ? $date : time()))) { - case 0: - return 'sunday'; - case 6: - return 'saturday'; - default: - return 'weekday'; - } -} + if (isset($override['service_id'])) { + return strtolower($override['service_id']); + } + $date = ($date != "" ? $date : time()); + $dow = date('w', $date); + + switch ($dow) { + case 0: + return 'sunday'; + case 6: + return 'saturday'; + default: + return 'weekday'; + } +} + function service_ids($service_period) { switch ($service_period) { case 'sunday': - return Array("2010-TUGGSUN-Sunday-20","2010-BELCSUN-Sunday-19"); + return Array("Sunday", "Sunday"); case 'saturday': - return Array("2010-BELCSAT-Saturday-19","2010-TUGGSAT-Saturday-19"); + return Array("Saturday", "Saturday"); default: //return 'weekday'; - return Array("2010-BELCMAST-Weekday-15","2010-TUGGMAST-Weekday-14"); - } -} + return Array("Weekday", "Weekday-SchoolVacation"); + } +} + function valid_service_ids() { - return array_merge(service_ids(""),service_ids('saturday'),service_ids('sunday')); + return array_merge(service_ids(""), service_ids('saturday'), service_ids('sunday')); } function midnight_seconds($time = "") { --- a/include/db/route-dao.inc.php +++ b/include/db/route-dao.inc.php @@ -46,11 +46,11 @@ function getRouteHeadsigns($routeID) { global $conn; - $query = "select stops.stop_name, direction_id,max(service_id) as service_id, count(*) + $query = "select stops.stop_name, trip_headsign, direction_id,max(service_id) as service_id, count(*) from routes join trips on trips.route_id = routes.route_id join stop_times on stop_times.trip_id = trips.trip_id join stops on stop_times.stop_id = stops.stop_id where trips.route_id = :routeID -and stop_times.stop_sequence = 1 group by stops.stop_name, direction_id having count(*) > 2"; +and stop_times.stop_sequence = 1 group by stops.stop_name, trip_headsign, direction_id having count(*) > 2"; debug($query, "database"); $query = $conn->prepare($query); $query->bindParam(":routeID", $routeID); @@ -260,25 +260,24 @@ $service_ids = service_ids($service_period); $sidA = $service_ids[0]; $sidB = $service_ids[1]; + global $conn; $query = "SELECT DISTINCT service_id,trips.route_id,route_short_name,route_long_name FROM stop_times join trips on trips.trip_id = stop_times.trip_id join routes on trips.route_id = routes.route_id join stops on stops.stop_id = stop_times.stop_id -WHERE zone_id LIKE ':suburb AND (service_id=:service_periodA OR service_id=:service_periodB) +WHERE stop_desc LIKE :suburb AND (service_id=:service_periodA OR service_id=:service_periodB) ORDER BY route_short_name"; debug($query, "database"); $query = $conn->prepare($query); $query->bindParam(":service_periodA", $sidA); $query->bindParam(":service_periodB", $sidB); - $query->bindParam(":service_period", $service_period); - $suburb = "%" . $suburb . ";%"; + $suburb = "%Suburb: %" . $suburb . "%"; $query->bindParam(":suburb", $suburb); $query->execute(); - if (!$query) { - databaseError($conn->errorInfo()); - return Array(); - } + + databaseError($conn->errorInfo()); + return $query->fetchAll(); } --- a/index.php +++ b/index.php @@ -20,7 +20,7 @@
-

busness time


Canberra Bus Timetables and Trip Planner +

busness time


Canberra Bus Timetables and Trip Planner
Launch Trip Planner... @@ -38,8 +38,12 @@
  • Nearby Routes
  • Busness R&D'; echo ' MyWay Balance and Timeliness Survey Results'; + include_footer(true) ?> --- a/routeList.php +++ b/routeList.php @@ -18,6 +18,7 @@ include ('include/common.inc.php'); function navbar() { + echo '
      @@ -28,6 +29,42 @@
    '; +} + +function displayRoutes($routes) { + global $nearby; + echo ' '; -} else if (isset($nearby) || isset($suburb)) { - $routes = Array(); +} else if (isset($suburb)) { + if ($suburb) { include_header($suburb . " - " . ucwords(service_period()), "routeList"); navbar(); - timePlaceSettings(); + timeSettings(); trackEvent("Route Lists", "Routes By Suburb", $suburb); - $routes = getRoutesBySuburb($suburb); + displayRoutes(getRoutesBySuburb($suburb)); } - if (isset($nearby)) { - include_header("Routes Nearby", "routeList", true, true); - trackEvent("Route Lists", "Routes Nearby", $_SESSION['lat'] . "," . $_SESSION['lon']); - navbar(); - placeSettings(); - if (!isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == "") { - include_footer(); - die(); - } - $routes = getRoutesNearby($_SESSION['lat'], $_SESSION['lon']); +} else if (isset($nearby)) { + $routes = Array(); + include_header("Routes Nearby", "routeList", true, true); + trackEvent("Route Lists", "Routes Nearby", $_SESSION['lat'] . "," . $_SESSION['lon']); + navbar(); + placeSettings(); + if (!isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == "") { + include_footer(); + die(); } - echo '
      '; - if ($routes) { - foreach ($routes as $route) { - echo '
    • ' . $route['route_short_name'] . "

      " . $route['route_long_name'] . " (" . ucwords($route['service_id']) . ")

      "; - if (isset($nearby)) { - $time = getRouteAtStop($route['route_id'], $route['stop_id']); - echo '' . ($time['arrival_time'] ? $time['arrival_time'] : "No more trips today") . "
      " . floor($route['distance']) . 'm away
      '; - } - echo "
    • \n"; - } + $routes = getRoutesNearby($_SESSION['lat'], $_SESSION['lon']); + + + if (sizeof($routes) > 0) { + displayRoutes($routes); } else { + echo '
        '; echo "
      • No routes nearby.
      • "; } } else if (isset($bynumber) || isset($numberSeries)) { @@ -118,39 +150,14 @@ } } else if ($numberSeries) { - $routes = getRoutesByNumberSeries($numberSeries); - $filteredRoutes = Array(); - foreach ($routes as $route) { - foreach (getRouteHeadsigns($route['route_id']) as $headsign) { - $start = $headsign['stop_name']; - $serviceday = service_period_day ( $headsign['service_id']); - $key = $route['route_short_name'].".".$headsign['direction_id']; - if (isset($filteredRoutes[$key])) { - $filteredRoutes[$key]['route_ids'][] = $route['route_id']; - $filteredRoutes[$key]['route_ids'] = array_unique($filteredRoutes[$key]['route_ids']); - } else { - $filteredRoutes[$key]['route_short_name'] = $route['route_short_name']; - $filteredRoutes[$key]['route_long_name'] = "Starting at ".$start; - $filteredRoutes[$key]['service_id'] = $serviceday; - $filteredRoutes[$key]['direction_id'] = $headsign['direction_id']; - } - } - } - foreach ($filteredRoutes as $key => $route) { - echo '
      • ' . $route['route_short_name'] . "

        - -

        " . $route['route_long_name'] . " (" . ucwords($route['service_id']) . ")

        -
      • \n"; - } + displayRoutes(getRoutesByNumberSeries($numberSeries)); } } else { include_header("Routes by Destination", "routeList"); navbar(); echo '
          '; if (isset($routeDestination)) { - foreach (getRoutesByDestination($routeDestination) as $route) { - echo '
        • ' . $route["route_short_name"] . '

          ' . $route["route_long_name"] . " (" . ucwords($route['service_id']) . ")

        • \n"; - } + displayRoutes(getRoutesByDestination($routeDestination)); } else { foreach (getRoutesByDestination() as $destination) { echo '
        • ' . $destination['route_long_name'] . "...
        • \n"; --- a/servicealerts/importer.py +++ b/servicealerts/importer.py @@ -1,5 +1,3 @@ -#dependencies http://code.google.com/p/python-twitter/ - # info # http://stackoverflow.com/questions/4206882/named-entity-recognition-with-preset-list-of-names-for-python-php/4207128#4207128 # http://alias-i.com/lingpipe/demos/tutorial/ne/read-me.html approximate dist @@ -12,11 +10,17 @@ # http://esa.act.gov.au/feeds/currentincidents.xml # source: https://gist.github.com/322906/90dea659c04570757cccf0ce1e6d26c9d06f9283 +# to install python -m nltk.downloader punkt import nltk -import twitter +import tweepy import psycopg2 +import pickle + +from iniparse import INIConfig + def insert_service_alert_sitewide(heading, message, url): - + print "NaN" + def insert_service_alert_for_street(streets, heading, message, url): conn_string = "host='localhost' dbname='energymapper' user='postgres' password='snmc'" # print the connection string we will use to connect @@ -29,30 +33,22 @@ cursor = conn.cursor() # execute our Query - cursor.execute("select max(value), extract(dow from max(time)) as dow, \ -extract(year from max(time))::text || lpad(extract(month from max(time))::text,2,'0') \ -|| lpad(extract(month from max(time))::text,2,'0') as yearmonthweek, to_char(max(time),'J') \ -from environmentdata_values where \"dataSourceID\"='NSWAEMODemand' \ -group by extract(dow from time), extract(year from time), extract(week from time) \ -order by extract(year from time), extract(week from time), extract(dow from time)") + cursor.execute("") # retrieve the records from the database records = cursor.fetchall() for record in records: ys.append(record[0]) -# >>> cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (42, 'bar')) -#>>> cur.statusmessage -#'INSERT 0 1' + # >>> cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (42, 'bar')) + #>>> cur.statusmessage + #'INSERT 0 1' except: # Get the most recent exception exceptionType, exceptionValue, exceptionTraceback = sys.exc_info() # Exit the script and print an error telling what happened. sys.exit("Database connection failed!\n ->%s" % (exceptionValue)) -def get_tweets(user): - tapi = twitter.Api() - return tapi.GetUserTimeline(user) def extract_entity_names(t): entity_names = [] @@ -86,3 +82,23 @@ # Print unique entity names print set(entity_names) +cfg = INIConfig(open('/tmp/aws.ini')) + +auth = tweepy.OAuthHandler(cfg.api_keys.twitter_consumer_key, cfg.api_keys.twitter_consumer_secret) +auth.set_access_token(cfg.api_keys.twitter_access_token, cfg.api_keys.twitter_access_token_secret) + +#api = tweepy.API(auth) +api = tweepy.API() +# If the authentication was successful, you should +# see the name of the account print out +#print api.me().name +# https://github.com/tweepy/tweepy/blob/master/tweepy/api.py +for status in api.user_timeline(screen_name="ACTPol_Traffic",exclude_replies='true'): + print status.text + print status.created_at + print extract_names(status.text) +# print api.update_status(status="test") + +last_tweet_ids = { "lion": "111", "kitty": "2222" } +pickle.dump( last_tweet_ids, open( "save.p", "wb" ) ) +last_tweet_ids = pickle.load( open( "save.p", "rb" ) ) --- /dev/null +++ b/servicealerts/punkt.zip --- a/stop.php +++ b/stop.php @@ -96,31 +96,7 @@ )); } -// time settings -echo '
          -

          Change Time (' . (isset($_REQUEST['time']) ? $_REQUEST['time'] : "Current Time,") . ' ' . ucwords(service_period()) . ')...

          -
          - - -
          -
          - - - Current Time? -
          -
          - - - -
          - - -
          -
          '; +timeSettings(); echo ''; echo '