Via points and Stops by Suburb added
[bus.git] / busui / schedule_viewer.py
blob:a/busui/schedule_viewer.py -> blob:b/busui/schedule_viewer.py
--- a/busui/schedule_viewer.py
+++ b/busui/schedule_viewer.py
@@ -89,10 +89,10 @@
   """Return tuple as expected by javascript function addStopMarkerFromList"""
   return (stop.stop_id, stop.stop_name, float(stop.stop_lat),
           float(stop.stop_lon), stop.location_type, stop.stop_code)
-def StopCodeToTuple(stop, code):
+def StopZoneToTuple(stop):
+  """Return tuple as expected by javascript function addStopMarkerFromList"""
   return (stop.stop_id, stop.stop_name, float(stop.stop_lat),
-          float(stop.stop_lon), stop.location_type, code)
-
+          float(stop.stop_lon), stop.location_type, stop.stop_code, stop.zone_id)
 
 class ScheduleRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
   def do_GET(self):
@@ -360,10 +360,8 @@
     schedule = self.server.schedule
     matches = []
     for s in schedule.GetStopList():
-      #wtf, stop_code changes into stop_name after .find()
-      virginstopCode = s.stop_code
       if s.stop_code.find("Wj") == -1:
-        matches.append(StopCodeToTuple(s,virginstopCode))
+        matches.append(StopToTuple(s))
     return matches
 
   def handle_json_GET_stopsearch(self, params):
@@ -389,10 +387,17 @@
     query = params.get('q', None).lower()
     matches = []
     for s in schedule.GetStopList():
-      #wtf, stop_code changes into stop_name after .find()
-      virginstopCode = s.stop_code
       if s.stop_code.lower().find(query) != -1:
-        matches.append(StopCodeToTuple(s,virginstopCode))
+        matches.append(StopToTuple(s))
+    return matches
+
+  def handle_json_GET_stopzonesearch(self, params):
+    schedule = self.server.schedule
+    query = params.get('q', None).lower()
+    matches = []
+    for s in schedule.GetStopList():
+      if s.zone_id != None and s.zone_id.lower().find(query) != -1:
+        matches.append(StopToTuple(s))
     return matches
 
   def handle_json_GET_stop(self, params):
@@ -416,7 +421,6 @@
     # Need make a tuple to find correct bisect point
     time_trips = time_trips[bisect.bisect_left(time_trips, (time, 0)):]
     time_trips = time_trips[:15]
-    # TODO: combine times for a route to show next 2 departure times
     result = []
     for time, (trip, index), tp in time_trips:
       headsign = None
@@ -436,8 +440,9 @@
         if len(trip_name):
           trip_name += " - "
         trip_name += route.route_long_name
-      if headsign:
-        trip_name += " (Direction: %s)" % headsign
+        # comment out directions because we already have them in the long name
+      #if headsign:
+      #  trip_name += " (Direction: %s)" % headsign
       if service_period == None or trip.service_id == service_period:
         result.append((time, (trip.trip_id, trip_name, trip.service_id), tp))
     return result