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
 

 Binary files a/staticmaplite/cache/maps/01/14/c6e6e108859a72d2a1788d80dcca.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/01/8e/2802d509249cc647933f722af1ec.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/01/f9/821c0d716435f60c89db9be59878.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/0a/c0/3cac615b707496a2e4626e35d347.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/0f/03/444c437c3e88cc187e5efba943aa.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/11/60/56a2e06ac6336d7962a2c43bb2a5.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/13/54/be1781bb626f8f8d81df528eda69.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/16/6d/a15b2feea5a36c00baaca471b7f6.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/16/e7/c07b8d2d17e32528368a09bef070.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/18/c7/ee45caf9b2c492f515ec9b0757df.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/19/58/f04b3d84f289c7b7e284828f2c2b.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/1a/44/b7d7510ad29915f14b115834fd08.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/1d/3d/6a52b662e1a05de1c2fae3a414fc.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/1d/a6/63336b21f9c6425860f9f89ae435.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/1f/ec/816972efa33287c46f0939766886.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/24/c2/ab8600227da30733cc5c6b07f0d4.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/2c/f7/86a92f478ddd4c93a131aa1b8b6a.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/31/3c/6e31c77abcf6f323115e466aee8b.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/3c/1d/2be4b564c6cb9579c119e66be5d7.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/3c/58/18358a67893fe0690eac2577073b.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/3c/7e/fbccb14edad70ff856053e3819e4.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/3f/10/d71a0fd38365ff65ee4c37af38f8.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/43/3a/a51f781d5c7d3fd086089a0d46b4.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/48/5d/cc06dd33314f96cdd89c46766328.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/4d/f3/9656e77647fbc975f45bd3c2bac2.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/4e/25/07fb22a605dc8197a1df1aeacc99.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/51/ad/dbcbacdfa7135285b30940be177b.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/55/3b/9d6b7ce7526047cf592dedceecad.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/56/90/fd99f1d22e045c7dfac4a7bea20f.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/56/bd/4fc6c29b896724be00820f863e62.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/58/6c/b1289e988a043f9b2925ff42e549.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/5d/61/0611c7a40f9f84cc8bf9129d0a7e.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/5e/e0/1d1a2f5fc95238a0e261c4001a53.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/5e/e6/7af3c78b383c7bcb98877cc40c30.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/5f/ef/32d9f12202c8c6668a1fbb2ec913.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/61/c7/027ef50ab42e608b6ef02daf9264.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/65/e6/082ee13e5d74898885f81ff2f95a.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/66/31/d69d9526356db44824af6c898f65.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/66/43/773a49a7d2031a4e1aaa9953120d.png and /dev/null differ
 Binary files a/staticmaplite/cache/maps/69/01/021968fe22ac6651ce199a197528.png and /dev/null differ
file: