Display startup time of schedule_viewer.py
Display startup time of schedule_viewer.py

--- a/aws/awsStartup.sh
+++ b/aws/awsStartup.sh

--- a/aws/fastcgi.conf
+++ b/aws/fastcgi.conf

--- a/aws/modules.conf
+++ b/aws/modules.conf

--- a/aws/php.ini
+++ b/aws/php.ini

--- a/aws/rc.local
+++ b/aws/rc.local

--- a/common.inc.php
+++ b/common.inc.php
@@ -11,18 +11,27 @@
 
  // you have to open the session to be able to modify or remove it 
 session_start();
- if (isset($_REQUEST['service_period'])) $_SESSION['service_period'] = filter_var($_REQUEST['service_period'],FILTER_SANITIZE_STRING);
- if (isset($_REQUEST['time'])) $_SESSION['time'] = filter_var($_REQUEST['time'],FILTER_SANITIZE_STRING);
+ if (isset($_REQUEST['service_period'])) {
+   $_SESSION['service_period'] = filter_var($_REQUEST['service_period'],FILTER_SANITIZE_STRING);
+ }
+ if (isset($_REQUEST['time'])) {
+   $_SESSION['time'] = filter_var($_REQUEST['time'],FILTER_SANITIZE_STRING);
+ }
  if (isset($_REQUEST['geolocate'])) {
+   if (isset($_REQUEST['lat']) && isset($_REQUEST['lon'])) {
+      $_SESSION['lat'] = $_REQUEST['lat'];
+        $_SESSION['lon'] = $_REQUEST['lon'];
+   } else {
     $contents = geocode(var_filter($_REQUEST['geolocate'],FILTER_SANITIZE_URL),true);
     if (isset($contents[0]->centroid)) {
-        $session['lat'] = $contents[0]->centroid->coordinates[0];
-        $session['lon'] = $contents[0]->centroid->coordinates[1];
+        $_SESSION['lat'] = $contents[0]->centroid->coordinates[0];
+        $_SESSION['lon'] = $contents[0]->centroid->coordinates[1];
     }
     else {
-        $session['lat'] = "";
-        $session['lon'] = "";
-    }
+        $_SESSION['lat'] = "";
+        $_SESSION['lon'] = "";
+    }
+   }
  }
 //print_r ($_SESSION);
 function isDebug()
@@ -32,11 +41,11 @@
 
 function isMetricsOn()
 {
-    return true;
+    return false;
 }
 
 function debug($msg) {
-    if (isDebug()) echo "<!-- $msg -->";
+    if (isDebug()) echo "\n<!-- $msg -->\n";
 }
 function isFastDevice() {
     $fastDevices = Array("Mozilla/5.0 (X11;", "Mozilla/5.0 (Windows;", "Mozilla/5.0 (iP", "Mozilla/5.0 (Linux; U; Android", "Mozilla/4.0 (compatible; MSIE");
@@ -199,7 +208,7 @@
 curl_setopt( $ch, CURLOPT_HEADER, 0 );
           curl_setopt($ch,CURLOPT_TIMEOUT,30); 
 $page = curl_exec($ch);
- if(curl_errno($ch)) echo "<font color=red> Database temporarily unavailable: ".curl_errno($ch)." ".curl_error($ch)."</font>";
+ if(curl_errno($ch)) echo "<font color=red> Database temporarily unavailable: ".curl_errno($ch)." ".curl_error($ch)."</font><br>";
 curl_close($ch);
 return $page;
 }
@@ -368,7 +377,7 @@
 
 function geocode($query, $giveOptions) {
     global $cloudmadeAPIkey;
-       $url = "http://geocoding.cloudmade.com/$cloudmadeAPIkey/geocoding/v2/find.js?query=".$query."&bbox=-35.5,149.00,-35.15,149.1930&return_location=true&bbox_only=true";
+       $url = "http://geocoding.cloudmade.com/$cloudmadeAPIkey/geocoding/v2/find.js?query=".urlencode($query)."&bbox=-35.5,149.00,-35.15,149.1930&return_location=true&bbox_only=true";
       $contents = json_decode(getPage($url));
       if ($giveOptions) return $contents->features;
       elseif (isset($contents->features[0]->centroid)) return $contents->features[0]->centroid->coordinates[0].",".$contents->features[0]->centroid->coordinates[1];

 Binary files a/css/images/ajax-loader.png and b/css/images/ajax-loader.png differ
 Binary files a/css/images/form-check-off.png and b/css/images/form-check-off.png differ
 Binary files a/css/images/form-check-on.png and b/css/images/form-check-on.png differ
 Binary files a/css/images/form-radio-off.png and b/css/images/form-radio-off.png differ
 Binary files a/css/images/form-radio-on.png and b/css/images/form-radio-on.png differ
 Binary files a/css/images/icon-search-black.png and b/css/images/icon-search-black.png differ
 Binary files a/css/images/icons-18-black.png and b/css/images/icons-18-black.png differ
 Binary files a/css/images/icons-18-white.png and b/css/images/icons-18-white.png differ
 Binary files a/css/images/icons-36-black.png and b/css/images/icons-36-black.png differ
 Binary files a/css/images/icons-36-white.png and b/css/images/icons-36-white.png differ
--- a/css/jquery-mobile-1.0a3.css
+++ b/css/jquery-mobile-1.0a3.css

--- a/css/jquery.ui.datepicker.mobile.css
+++ b/css/jquery.ui.datepicker.mobile.css

--- a/feedback.php
+++ b/feedback.php

--- a/js/jQuery.ui.datepicker.js
+++ b/js/jQuery.ui.datepicker.js

--- a/js/jquery-1.5.js
+++ b/js/jquery-1.5.js

--- a/js/jquery-mobile-1.0a3.js
+++ b/js/jquery-mobile-1.0a3.js

--- a/js/jquery.effects.core.js
+++ b/js/jquery.effects.core.js

--- a/js/jquery.ui.autocomplete.js
+++ b/js/jquery.ui.autocomplete.js

--- a/js/jquery.ui.datepicker.mobile.js
+++ b/js/jquery.ui.datepicker.mobile.js

--- a/js/jquery.ui.position.js
+++ b/js/jquery.ui.position.js

--- a/js/jquery.ui.widget.js
+++ b/js/jquery.ui.widget.js

--- a/layar_api.php
+++ b/layar_api.php

--- a/schedule_viewer.py
+++ b/schedule_viewer.py
@@ -32,6 +32,7 @@
 import simplejson
 import socket
 import time
+import datetime
 import transitfeed
 from transitfeed import util
 import urllib
@@ -95,6 +96,8 @@
           float(stop.stop_lon), stop.location_type, stop.stop_code, stop.zone_id)
 
 class ScheduleRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+  cache = {}
+  
   def do_GET(self):
     scheme, host, path, x, params, fragment = urlparse.urlparse(self.path)
     parsed_params = {}
@@ -114,7 +117,7 @@
       handler_name = 'handle_json_GET_%s' % m.group(1)
       handler = getattr(self, handler_name, None)
       if callable(handler):
-        return self.handle_json_wrapper_GET(handler, parsed_params)
+        return self.handle_json_wrapper_GET(handler, parsed_params, handler_name)
 
     # Restrict allowable file names to prevent relative path attacks etc
     m = re.match(r'/file/([a-z0-9_-]{1,64}\.?[a-z0-9_-]{1,64})$', path)
@@ -243,11 +246,22 @@
     patterns.sort()
     return patterns
 
-  def handle_json_wrapper_GET(self, handler, parsed_params):
+  def handle_json_wrapper_GET(self, handler, parsed_params, handler_name):
     """Call handler and output the return value in JSON."""
     schedule = self.server.schedule
-    result = handler(parsed_params)
-    content = ResultEncoder().encode(result)
+    # round times to nearest 100 seconds
+    if "time" in parsed_params:
+      parsed_params['time'] = int(round(float(parsed_params['time']),-2))
+    paramkey = tuple(sorted(parsed_params.items()))
+    if handler_name in self.cache and paramkey in self.cache[handler_name] :
+      print ("Cache hit for ",handler_name," params ",parsed_params)
+    else:
+      print ("Cache miss for ",handler_name," params ",parsed_params)
+      result = handler(parsed_params)
+      if not handler_name in self.cache:
+        self.cache[handler_name] = {}
+      self.cache[handler_name][paramkey] = ResultEncoder().encode(result)
+    content = self.cache[handler_name][paramkey]
     self.send_response(200)
     self.send_header('Content-Type', 'text/plain')
     self.send_header('Content-Length', str(len(content)))
@@ -566,12 +580,13 @@
 
   if options.key and os.path.isfile(options.key):
     options.key = open(options.key).read().strip()
-
+  
   schedule = transitfeed.Schedule(problem_reporter=transitfeed.ProblemReporter())
   print 'Loading data from feed "%s"...' % options.feed_filename
   print '(this may take a few minutes for larger cities)'
+  t0 = datetime.datetime.now()
   schedule.Load(options.feed_filename)
-
+  print ("Loaded in", (datetime.datetime.now() - t0).seconds , "seconds")
   server = StoppableHTTPServer(server_address=('', options.port),
                                RequestHandlerClass=RequestHandlerClass)
   server.key = options.key
@@ -579,6 +594,8 @@
   server.file_dir = options.file_dir
   server.host = options.host
   server.feed_path = options.feed_filename
+  
+
 
   print ("To view, point your browser at http://localhost:%d/" %
          (server.server_port))

--- a/staticmaplite/.gitignore
+++ b/staticmaplite/.gitignore
@@ -1,3 +1,4 @@
 cache/tiles
 cache/map
+cache/maps
 

file:a/stop.php -> file:b/stop.php
--- a/stop.php
+++ b/stop.php
@@ -28,7 +28,10 @@
 {
 echo  '<li>';
 echo '<h3><a href="trip.php?stopid='.$_REQUEST['stopid'].'&tripid='.$row[1][0].'">'.$row[1][1];
-echo '<br><small>Via: '.viaPointNames($row[1][0],$_REQUEST['stopid']).'</small> </a></h3>';      
+if (isFastDevice()) {
+    $viaPoints = viaPointNames($row[1][0],$_REQUEST['stopid']);
+    if ($viaPoints != "") echo '<br><small>Via: '.$viaPoints.'</small> </a></h3>';
+}
 echo '<p class="ui-li-aside"><strong>'.midnight_seconds_to_time($row[0]).'</strong></p>';
 echo '</li>';  
 }