Esempio n. 1
0
    def test_basic(self):
	assert TimeHelpers.localtime_to_unix(2008,10,12,6,0,0,"Europe/Paris") == 1223784000
	assert str(TimeHelpers.unix_to_localtime(1199181360, "America/New_York")) == "2008-01-01 04:56:00-05:00"
	assert TimeHelpers.unixtime_to_daytimes(1219834260, "America/Los_Angeles") == (13860, 100260, 186660)
	assert str(TimeHelpers.unix_to_localtime(1221459000, "America/Chicago")) == "2008-09-15 01:10:00-05:00" 
	assert TimeHelpers.unixtime_to_daytimes(1230354000, "America/Chicago") == (82800, 169200, 255600)
	assert TimeHelpers.unix_time(2008,8,27,12,0,0,-7*3600) == 1219863600
	assert TimeHelpers.localtime_to_unix(2008,8,27,12,0,0,"America/Los_Angeles") == 1219863600
	assert str(TimeHelpers.unix_to_localtime(1219863600, "America/Los_Angeles")) == "2008-08-27 12:00:00-07:00"
Esempio n. 2
0
 def contour(self, lat, lon, year, month, day, hour, minute, second, cutoff, step=60*15, encoded=False, speed=0.85):
     if step is not None and step < 600:
         raise Exception( "Step cannot be less than 600 seconds" )
     
     starttime = TimeHelpers.localtime_to_unix( year, month, day, hour, minute, second, "America/Los_Angeles" )
     
     #=== get osm vertex ==
     print( "getting nearest vertex" )
     
     #find osmid of origin intersection
     t0 = time.time()
     range = 0.001
     bbox = (lon-range, lat-range, lon+range, lat+range)
     candidates = self.index.intersection( bbox )
     vlabel, vlat, vlon, vdist = self.osmdb.nearest_of( lat, lon, candidates )
     t1 = time.time()
     print( "done, took %s seconds"%(t1-t0) )
     
     #vlabel, vlat, vlon, vdist = self.osmdb.nearest_node( lat, lon )
     
     if vlabel is None:
         return json.dumps( "NO NEARBY INTERSECTION" )
     
     print( "found - %s"%vlabel )
     
     contours = self._contour( "osm"+vlabel, starttime, cutoff, step, speed )
     
     if encoded:
         encoded_contours = []
         for contour in contours:
             encoded_contour = []
             for ring in contour:
                 encoded_contour.append( encode_pairs( [(lat,lon) for lon,lat in ring] ) )
             encoded_contours.append( encoded_contour )
             
         contours = encoded_contours
     
     return json.dumps( contours )
Esempio n. 3
0
 def _surface(self, lat, lon, year, month, day, hour, minute, second, cutoff, speed, cellsize=0.004):
     
     starttime = TimeHelpers.localtime_to_unix( year, month, day, hour, minute, second, "America/Los_Angeles" )
     
     #=== get osm vertex ==
     print( "getting nearest vertex" )
     
     #find osmid of origin intersection
     t0 = time.time()
     range = 0.001
     bbox = (lon-range, lat-range, lon+range, lat+range)
     candidates = self.index.intersection( bbox )
     vlabel, vlat, vlon, vdist = self.osmdb.nearest_of( lat, lon, candidates )
     t1 = time.time()
     print( "done, took %s seconds"%(t1-t0) )
     
     #vlabel, vlat, vlon, vdist = self.osmdb.nearest_node( lat, lon )
     
     if vlabel is None:
         return json.dumps( "NO NEARBY INTERSECTION" )
     
     print( "found - %s"%vlabel )
     
     #=== get points which comprise ETA surface ===
     points = self._points( "osm"+vlabel, starttime, cutoff, speed )
     
     #=== create regular grid from ETA surface ===
     print "creating surface...",
     
     t0 = time.time()
     ret = points_to_surface_grid( points, cutoff=cutoff, fudge=1.1, margin=2, closure_tolerance=0.05, cellsize=cellsize )
     #ret = travel_time_surface( points, cutoff=cutoff, cellsize=0.004, fudge=1.7 )
     print "%s sec"%(time.time()-t0)
     print "done. here you go..."
     
     return ret