<s> from graphserver . util import TimeHelpers <EOL> import graphserver . core <EOL> from graphserver . ext . gtfs . gtfsdb import GTFSDatabase <EOL> from graphserver . ext . osm . osmdb import OSMDB <EOL> try : <EOL> import json <EOL> except ImportError : <EOL> import simplejson as json <EOL> class NarrativeEvent : <EOL> def __init__ ( self , what , where , when , geom ) : <EOL> self . what = what <EOL> self . where = where <EOL> self . when = when <EOL> self . geom = geom <EOL> def to_jsonable ( self ) : <EOL> return { '<STR_LIT>' : self . what , <EOL> '<STR_LIT>' : self . where , <EOL> '<STR_LIT>' : self . when , <EOL> '<STR_LIT>' : self . geom } <EOL> class BoardEvent : <EOL> def __init__ ( self , gtfsdb_filename , timezone_name = "<STR_LIT>" ) : <EOL> self . gtfsdb = GTFSDatabase ( gtfsdb_filename ) <EOL> self . timezone_name = timezone_name <EOL> @ staticmethod <EOL> def applies_to ( vertex1 , edge , vertex2 ) : <EOL> return edge is not None and isinstance ( edge . payload , graphserver . core . TripBoard ) <EOL> def __call__ ( self , vertex1 , edge , vertex2 , context ) : <EOL> event_time = vertex2 . state . time <EOL> trip_id = vertex2 . state . trip_id <EOL> stop_id = vertex1 . label . split ( "<STR_LIT:->" ) [ - <NUM_LIT:1> ] <EOL> route_desc = "<STR_LIT:->" . join ( [ str ( x ) for x in list ( self . gtfsdb . execute ( "<STR_LIT>" , ( trip_id , ) ) ) [ <NUM_LIT:0> ] ] ) <EOL> stop_desc = list ( self . gtfsdb . execute ( "<STR_LIT>" , ( stop_id , ) ) ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> lat , lon = list ( self . gtfsdb . execute ( "<STR_LIT>" , ( stop_id , ) ) ) [ <NUM_LIT:0> ] <EOL> what = "<STR_LIT>" % route_desc <EOL> where = stop_desc <EOL> when = str ( TimeHelpers . unix_to_localtime ( event_time , self . timezone_name ) ) <EOL> geom = ( lon , lat ) <EOL> return NarrativeEvent ( what , where , when , geom ) <EOL> class DescribeCrossingAtAlightEvent : <EOL> def __init__ ( self , gtfsdb_filename , timezone_name = "<STR_LIT>" ) : <EOL> self . gtfsdb = GTFSDatabase ( gtfsdb_filename ) <EOL> self . timezone_name = timezone_name <EOL> @ staticmethod <EOL> def applies_to ( vertex1 , edge , vertex2 ) : <EOL> return edge is not None and isinstance ( edge . payload , graphserver . core . TripAlight ) and vertex1 . state . stop_sequence == vertex2 . state . stop_sequence <EOL> def __call__ ( self , vertex1 , edge , vertex2 , context ) : <EOL> stop_sequence_of_boarding = vertex1 . state . stop_sequence <EOL> trip_id = vertex1 . state . trip_id <EOL> alighting_trip_id , alighting_time , alighting_stop_sequences = edge . payload . get_alighting_by_trip_id ( trip_id ) <EOL> what = "<STR_LIT>" % ( trip_id , vertex1 . state . stop_sequence , alighting_stop_sequences ) <EOL> where = None <EOL> when = None <EOL> geom = self . gtfsdb . shape_between ( trip_id , vertex1 . state . stop_sequence , alighting_stop_sequences ) <EOL> return NarrativeEvent ( what , where , when , geom ) <EOL> class AlightEvent : <EOL> def __init__ ( self , gtfsdb_filename , timezone_name = "<STR_LIT>" ) : <EOL> self . gtfsdb = GTFSDatabase ( gtfsdb_filename ) <EOL> self . timezone_name = timezone_name <EOL> @ staticmethod <EOL> def applies_to ( vertex1 , edge , vertex2 ) : <EOL> return edge is not None and isinstance ( edge . payload , graphserver . core . TripAlight ) <EOL> def __call__ ( self , vertex1 , edge , vertex2 , context ) : <EOL> event_time = vertex1 . state . time <EOL> stop_id = vertex2 . label . split ( "<STR_LIT:->" ) [ - <NUM_LIT:1> ] <EOL> stop_desc = list ( self . gtfsdb . execute ( "<STR_LIT>" , ( stop_id , ) ) ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> lat , lon = list ( self . gtfsdb . execute ( "<STR_LIT>" , ( stop_id , ) ) ) [ <NUM_LIT:0> ] <EOL> what = "<STR_LIT>" <EOL> where = stop_desc <EOL> when = str ( TimeHelpers . unix_to_localtime ( event_time , self . timezone_name ) ) <EOL> geom = ( lon , lat ) <EOL> return NarrativeEvent ( what , where , when , geom ) <EOL> class HeadwayBoardEvent : <EOL> def __init__ ( self , gtfsdb_filename , timezone_name = "<STR_LIT>" ) : <EOL> self . gtfsdb = GTFSDatabase ( gtfsdb_filename ) <EOL> self . timezone_name = timezone_name <EOL> @ staticmethod <EOL> def applies_to ( vertex1 , edge , vertex2 ) : <EOL> return edge is not None and isinstance ( edge . payload , graphserver . core . HeadwayBoard ) <EOL> def __call__ ( self , vertex1 , edge , vertex2 , context ) : <EOL> event_time = vertex2 . state . time <EOL> trip_id = vertex2 . state . trip_id <EOL> stop_id = vertex1 . label . split ( "<STR_LIT:->" ) [ - <NUM_LIT:1> ] <EOL> route_desc = "<STR_LIT:->" . join ( list ( self . gtfsdb . execute ( "<STR_LIT>" , ( trip_id , ) ) ) [ <NUM_LIT:0> ] ) <EOL> stop_desc = list ( self . gtfsdb . execute ( "<STR_LIT>" , ( stop_id , ) ) ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> lat , lon = list ( self . gtfsdb . execute ( "<STR_LIT>" , ( stop_id , ) ) ) [ <NUM_LIT:0> ] <EOL> what = "<STR_LIT>" % route_desc <EOL> where = stop_desc <EOL> when = "<STR_LIT>" % str ( TimeHelpers . unix_to_localtime ( event_time , self . timezone_name ) ) <EOL> geom = ( lon , lat ) <EOL> return NarrativeEvent ( what , where , when , geom ) <EOL> class HeadwayAlightEvent : <EOL> def __init__ ( self , gtfsdb_filename , timezone_name = "<STR_LIT>" ) : <EOL> self . gtfsdb = GTFSDatabase ( gtfsdb_filename ) <EOL> self . timezone_name = timezone_name <EOL> @ staticmethod <EOL> def applies_to ( vertex1 , edge , vertex2 ) : <EOL> return edge is not None and isinstance ( edge . payload , graphserver . core . HeadwayAlight ) <EOL> def __call__ ( self , vertex1 , edge , vertex2 , context ) : <EOL> event_time = vertex1 . state . time <EOL> stop_id = vertex2 . label . split ( "<STR_LIT:->" ) [ - <NUM_LIT:1> ] <EOL> stop_desc = list ( self . gtfsdb . execute ( "<STR_LIT>" , ( stop_id , ) ) ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> lat , lon = list ( self . gtfsdb . execute ( "<STR_LIT>" , ( stop_id , ) ) ) [ <NUM_LIT:0> ] <EOL> what = "<STR_LIT>" <EOL> where = stop_desc <EOL> when = "<STR_LIT>" % str ( TimeHelpers . unix_to_localtime ( event_time , self . timezone_name ) ) <EOL> geom = ( lon , lat ) <EOL> return NarrativeEvent ( what , where , when , geom ) <EOL> class StreetEvent : <EOL> def __init__ ( self , osmdb_filename , timezone_name = "<STR_LIT>" ) : <EOL> self . osmdb = OSMDB ( osmdb_filename ) <EOL> self . timezone_name = timezone_name <EOL> @ staticmethod <EOL> def applies_to ( vertex1 , edge , vertex2 ) : <EOL> return edge is not None and isinstance ( edge . payload , graphserver . core . Street ) <EOL> def __call__ ( self , vertex1 , edge , vertex2 , context ) : <EOL> geometry_chunk = self . osmdb . edge ( edge . payload . name ) [ <NUM_LIT:5> ] <EOL> if edge . payload . reverse_of_source : <EOL> context [ '<STR_LIT>' ] . extend ( reversed ( geometry_chunk ) ) <EOL> else : <EOL> context [ '<STR_LIT>' ] . extend ( geometry_chunk ) <EOL> context [ '<STR_LIT>' ] += edge . payload . length <EOL> context [ '<STR_LIT>' ] += edge . payload . rise <EOL> context [ '<STR_LIT>' ] += edge . payload . fall <EOL> return None <EOL> class CrossingEvent : <EOL> def __init__ ( self , gtfsdb_filename , timezone_name = "<STR_LIT>" ) : <EOL> self . gtfsdb = GTFSDatabase ( gtfsdb_filename ) <EOL> self . timezone_name = timezone_name <EOL> @ staticmethod <EOL> def applies_to ( vertex1 , edge , vertex2 ) : <EOL> return edge is not None and isinstance ( edge . payload , graphserver . core . Crossing ) <EOL> def __call__ ( self , v1 , e , v2 , context ) : <EOL> trip_id = v1 . state . trip_id <EOL> return ( str ( v1 . state ) , str ( e ) , str ( v2 . state ) ) <EOL> from math import asin , acos , degrees <EOL> def mag ( vec ) : <EOL> return sum ( [ a ** <NUM_LIT:2> for a in vec ] ) ** <NUM_LIT:0.5> <EOL> def vector_angle ( p1 , p2 , p3 , p4 ) : <EOL> a = ( ( p2 [ <NUM_LIT:0> ] - p1 [ <NUM_LIT:0> ] ) , ( p2 [ <NUM_LIT:1> ] - p1 [ <NUM_LIT:1> ] ) ) <EOL> b = ( ( p4 [ <NUM_LIT:0> ] - p3 [ <NUM_LIT:0> ] ) , ( p4 [ <NUM_LIT:1> ] - p3 [ <NUM_LIT:1> ] ) ) <EOL> a_cross_b = a [ <NUM_LIT:0> ] * b [ <NUM_LIT:1> ] - a [ <NUM_LIT:1> ] * b [ <NUM_LIT:0> ] <EOL> a_dot_b = a [ <NUM_LIT:0> ] * b [ <NUM_LIT:0> ] + a [ <NUM_LIT:1> ] * b [ <NUM_LIT:1> ] <EOL> sin_theta = a_cross_b / ( mag ( a ) * mag ( b ) ) <EOL> cos_theta = a_dot_b / ( mag ( a ) * mag ( b ) ) <EOL> if a_dot_b >= <NUM_LIT:0> : <EOL> return - degrees ( asin ( sin_theta ) ) <EOL> else : <EOL> if a_cross_b <= <NUM_LIT:0> : <EOL> return degrees ( acos ( cos_theta ) ) <EOL> else : <EOL> return - degrees ( acos ( cos_theta ) ) <EOL> def angle_from_north ( p3 , p4 ) : <EOL> p1 = [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> p2 = [ <NUM_LIT:0> , <NUM_LIT:1> ] <EOL> return vector_angle ( p1 , p2 , p3 , p4 ) <EOL> def description_from_north ( p3 , p4 ) : <EOL> afn = angle_from_north ( p3 , p4 ) <EOL> if afn > - <NUM_LIT> and afn <= <NUM_LIT> : <EOL> return "<STR_LIT>" <EOL> if afn > <NUM_LIT> and afn <= <NUM_LIT> : <EOL> return "<STR_LIT>" <EOL> if afn > <NUM_LIT> and afn <= <NUM_LIT> : <EOL> return "<STR_LIT>" <EOL> if afn > <NUM_LIT> and afn <= <NUM_LIT> : <EOL> return "<STR_LIT>" <EOL> if afn > <NUM_LIT> : <EOL> return "<STR_LIT>" <EOL> if afn < - <NUM_LIT> and afn >= - <NUM_LIT> : <EOL> return "<STR_LIT>" <EOL> if afn < - <NUM_LIT> and afn >= - <NUM_LIT> : <EOL> return "<STR_LIT>" <EOL> if afn < - <NUM_LIT> and afn >= - <NUM_LIT> : <EOL> return "<STR_LIT>" <EOL> if afn < - <NUM_LIT> : <EOL> return "<STR_LIT>" <EOL> def test_vector_angle ( ) : <EOL> assert vector_angle ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:2> ) ) == <NUM_LIT:0.0> <EOL> assert round ( vector_angle ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:5> , <NUM_LIT:10> ) ) , <NUM_LIT:4> ) == <NUM_LIT> <EOL> assert vector_angle ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) ) == <NUM_LIT> <EOL> assert round ( vector_angle ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:1> , <NUM_LIT> ) ) , <NUM_LIT:4> ) == <NUM_LIT> <EOL> assert vector_angle ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) == <NUM_LIT> <EOL> assert round ( vector_angle ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( - <NUM_LIT:1> , <NUM_LIT> ) ) , <NUM_LIT:4> ) == - <NUM_LIT> <EOL> assert vector_angle ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( - <NUM_LIT:1> , <NUM_LIT:1> ) ) == - <NUM_LIT> <EOL> assert round ( vector_angle ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( - <NUM_LIT:5> , <NUM_LIT:10> ) ) , <NUM_LIT:4> ) == - <NUM_LIT> <EOL> def turn_narrative ( p1 , p2 , p3 , p4 ) : <EOL> angle = vector_angle ( p1 , p2 , p3 , p4 ) <EOL> turn_mag = abs ( angle ) <EOL> if turn_mag < <NUM_LIT:7> : <EOL> return "<STR_LIT>" <EOL> elif turn_mag < <NUM_LIT:20> : <EOL> verb = "<STR_LIT>" <EOL> elif turn_mag < <NUM_LIT> : <EOL> verb = "<STR_LIT>" <EOL> else : <EOL> verb = "<STR_LIT>" <EOL> if angle > <NUM_LIT:0> : <EOL> direction = "<STR_LIT:right>" <EOL> else : <EOL> direction = "<STR_LIT:left>" <EOL> return ( "<STR_LIT>" % ( verb , direction ) ) . strip ( ) <EOL> class StreetStartEvent : <EOL> def __init__ ( self , osmdb_filename , timezone_name = "<STR_LIT>" ) : <EOL> self . osmdb = OSMDB ( osmdb_filename ) <EOL> self . timezone_name = timezone_name <EOL> @ staticmethod <EOL> def applies_to ( edge1 , vertex , edge2 ) : <EOL> return ( edge1 is None or not isinstance ( edge1 . payload , graphserver . core . Street ) ) and ( edge2 and isinstance ( edge2 . payload , graphserver . core . Street ) ) <EOL> def __call__ ( self , edge1 , vertex , edge2 , context ) : <EOL> context [ '<STR_LIT>' ] = [ ] <EOL> context [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> context [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> context [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> context [ '<STR_LIT>' ] = vertex . state . time <EOL> osm_way2 = edge2 . payload . name . split ( "<STR_LIT:->" ) [ <NUM_LIT:0> ] <EOL> street_name2 = self . osmdb . way ( osm_way2 ) . tags . get ( '<STR_LIT:name>' , "<STR_LIT>" ) <EOL> osm_id = vertex . label . split ( "<STR_LIT:->" ) [ <NUM_LIT:1> ] <EOL> osm_node_id , osm_node_tags , osm_node_lat , osm_node_lon , osm_node_refcount = self . osmdb . node ( osm_id ) <EOL> osm_edge2 = self . osmdb . edge ( edge2 . payload . name ) <EOL> osm_edge2_startnode = osm_edge2 [ <NUM_LIT:2> ] <EOL> osm_edge2_geom = osm_edge2 [ <NUM_LIT:5> ] <EOL> if osm_id != osm_edge2_startnode : <EOL> osm_edge2_geom . reverse ( ) <EOL> startseg = osm_edge2_geom [ : <NUM_LIT:2> ] <EOL> direction = description_from_north ( startseg [ <NUM_LIT:0> ] , startseg [ <NUM_LIT:1> ] ) <EOL> what = "<STR_LIT>" <EOL> where = "<STR_LIT>" % ( street_name2 , direction ) <EOL> when = "<STR_LIT>" % str ( TimeHelpers . unix_to_localtime ( vertex . state . time , self . timezone_name ) ) <EOL> geom = [ osm_node_lon , osm_node_lat ] <EOL> return NarrativeEvent ( what , where , when , geom ) <EOL> class StreetEndEvent : <EOL> def __init__ ( self , osmdb_filename , timezone_name = "<STR_LIT>" ) : <EOL> self . osmdb = OSMDB ( osmdb_filename ) <EOL> self . timezone_name = timezone_name <EOL> @ staticmethod <EOL> def applies_to ( edge1 , vertex , edge2 ) : <EOL> return ( edge2 is None or not isinstance ( edge2 . payload , graphserver . core . Street ) ) and ( edge1 and isinstance ( edge1 . payload , graphserver . core . Street ) ) <EOL> def __call__ ( self , edge1 , vertex , edge2 , context ) : <EOL> osm_way1 = edge1 . payload . name . split ( "<STR_LIT:->" ) [ <NUM_LIT:0> ] <EOL> street_name1 = self . osmdb . way ( osm_way1 ) . tags . get ( '<STR_LIT:name>' , "<STR_LIT>" ) <EOL> osm_id = vertex . label . split ( "<STR_LIT:->" ) [ <NUM_LIT:1> ] <EOL> osm_node_id , osm_node_tags , osm_node_lat , osm_node_lon , osm_node_refcount = self . osmdb . node ( osm_id ) <EOL> average_speed = context [ '<STR_LIT>' ] / ( vertex . state . time - context [ '<STR_LIT>' ] ) if vertex . state . time - context [ '<STR_LIT>' ] > <NUM_LIT:0> else <NUM_LIT> <EOL> what = "<STR_LIT>" % ( context [ '<STR_LIT>' ] , context [ '<STR_LIT>' ] , context [ '<STR_LIT>' ] , average_speed ) <EOL> where = "<STR_LIT>" % ( street_name1 ) <EOL> when = "<STR_LIT>" % str ( TimeHelpers . unix_to_localtime ( vertex . state . time , self . timezone_name ) ) <EOL> geom = [ osm_node_lon , osm_node_lat ] <EOL> return NarrativeEvent ( what , where , when , geom ) <EOL> class GeomAtStreetEndEvent : <EOL> def __init__ ( self , timezone_name = "<STR_LIT>" ) : <EOL> self . timezone_name = timezone_name <EOL> @ staticmethod <EOL> def applies_to ( edge1 , vertex , edge2 ) : <EOL> return ( edge2 is None or not isinstance ( edge2 . payload , graphserver . core . Street ) ) and ( edge1 and isinstance ( edge1 . payload , graphserver . core . Street ) ) <EOL> def __call__ ( self , edge1 , vertex , edge2 , context ) : <EOL> what = "<STR_LIT>" <EOL> where = None <EOL> when = None <EOL> geom = context [ '<STR_LIT>' ] <EOL> return NarrativeEvent ( what , where , when , geom ) <EOL> class StreetTurnEvent : <EOL> def __init__ ( self , osmdb_filename , timezone_name = "<STR_LIT>" ) : <EOL> self . osmdb = OSMDB ( osmdb_filename ) <EOL> self . timezone_name = timezone_name <EOL> @ staticmethod <EOL> def applies_to ( edge1 , vertex , edge2 ) : <EOL> return edge1 and edge2 and isinstance ( edge1 . payload , graphserver . core . Street ) and isinstance ( edge2 . payload , graphserver . core . Street ) and edge1 . payload . way != edge2 . payload . way <EOL> def __call__ ( self , edge1 , vertex , edge2 , context ) : <EOL> osm_id = vertex . label . split ( "<STR_LIT:->" ) [ <NUM_LIT:1> ] <EOL> osm_way_id1 = edge1 . payload . name . split ( "<STR_LIT:->" ) [ <NUM_LIT:0> ] <EOL> osm_way_id2 = edge2 . payload . name . split ( "<STR_LIT:->" ) [ <NUM_LIT:0> ] <EOL> osm_edge1 = self . osmdb . edge ( edge1 . payload . name ) <EOL> osm_edge2 = self . osmdb . edge ( edge2 . payload . name ) <EOL> osm_edge1_endnode = osm_edge1 [ <NUM_LIT:3> ] <EOL> osm_edge2_startnode = osm_edge2 [ <NUM_LIT:2> ] <EOL> osm_edge1_geom = osm_edge1 [ <NUM_LIT:5> ] <EOL> osm_edge2_geom = osm_edge2 [ <NUM_LIT:5> ] <EOL> if osm_id != osm_edge1_endnode : <EOL> osm_edge1_geom . reverse ( ) <EOL> if osm_id != osm_edge2_startnode : <EOL> osm_edge2_geom . reverse ( ) <EOL> endseg = osm_edge1_geom [ - <NUM_LIT:2> : ] <EOL> startseg = osm_edge2_geom [ : <NUM_LIT:2> ] <EOL> direction = turn_narrative ( endseg [ <NUM_LIT:0> ] , endseg [ <NUM_LIT:1> ] , startseg [ <NUM_LIT:0> ] , startseg [ <NUM_LIT:1> ] ) <EOL> street_name1 = self . osmdb . way ( osm_way_id1 ) . tags . get ( "<STR_LIT:name>" , "<STR_LIT>" ) <EOL> street_name2 = self . osmdb . way ( osm_way_id2 ) . tags . get ( "<STR_LIT:name>" , "<STR_LIT>" ) <EOL> osm_node_id , osm_node_tags , osm_node_lat , osm_node_lon , osm_node_refcount = self . osmdb . node ( osm_id ) <EOL> average_speed = context [ '<STR_LIT>' ] / ( vertex . state . time - context [ '<STR_LIT>' ] ) if vertex . state . time - context [ '<STR_LIT>' ] > <NUM_LIT:0> else <NUM_LIT> <EOL> what = "<STR_LIT>" % ( direction , street_name2 , context [ '<STR_LIT>' ] , context [ '<STR_LIT>' ] , context [ '<STR_LIT>' ] , average_speed ) <EOL> where = "<STR_LIT>" % ( street_name1 , street_name2 ) <EOL> when = "<STR_LIT>" % str ( TimeHelpers . unix_to_localtime ( vertex . state . time , self . timezone_name ) ) <EOL> geom = ( osm_node_lon , osm_node_lat ) <EOL> context [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> context [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> context [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> context [ '<STR_LIT>' ] = vertex . state . time <EOL> return NarrativeEvent ( what , where , when , geom ) <EOL> class AllVertexEvent : <EOL> def __init__ ( self ) : <EOL> pass <EOL> @ staticmethod <EOL> def applies_to ( e1 , v , e2 ) : <EOL> return True <EOL> def __call__ ( self , e1 , v , e2 , context ) : <EOL> return NarrativeEvent ( "<STR_LIT>" , str ( e1 ) , str ( v ) , str ( e2 ) ) <EOL> class AllEdgeEvent : <EOL> def __init__ ( self ) : <EOL> pass <EOL> @ staticmethod <EOL> def applies_to ( v1 , e , v2 ) : <EOL> return True <EOL> def __call__ ( self , v1 , e , v2 , context ) : <EOL> return NarrativeEvent ( "<STR_LIT>" , str ( v1 ) , str ( e ) , str ( v2 ) ) </s>
