Source

Where we meet / first_time.py

from WhereWeMeet import *
if __name__ == '__main__':

    #gen a map of travel times for source. 
    #area analyzed is defined by global variables at top of file
    #This is a demonstration of how to use the program.

    #run this once per area you are analyzing.  You can add to this data set whenever
    #generate grid of lats and longs for the working area
    gen_grid_file(ll,ur,divisions=40)

    #generate traveling times* (time intensive)

    #  *for one address only:
    '''
    source = 'bennu coffee, Austin Tx 78702'
    results = time_map_from_address(source, filename='data/001.csv')
    print 'time map results: %s, errors: %s' % tuple(results)    
    '''
    #  *for addresses defined in ./data/_address_list.csv
    #if user was already processed, they wont be processed again when this is run
    address_file = 'data/_address_list.csv'
    process_users(address_file, output_path ="data/")
    
    #calculate total driving time of all users to each point on grid
    #a different function could weight users differently in making this map
    sum_files(source_path="data/",save_file='_TKandL.csv')
    
    #calculate contour data from csv file
    levels,colors,legend = get_contour_paths('data/_TKandL.csv',n=20)
    
    #set up map
    mymap = pygmaps.maps(center[0], center[1], 10)

    #display bounding box
    x1,y1 = ll
    x2,y2 = ur
    path = [(x1,y1), (x1,y2),(x2,y2),(x2,y1),(x1,y1)]
    mymap.addpath(path,color="#0000FF",fillcolor = "#000000", opacity=.2)

    #plot the acceptable area for final presentation
    acceptable_level = int(1)   #index to the contour level that is acceptable
    color = '#5555ee'
    print 'Highlighted area is under %s minutes.' % (legend[acceptable_level]/60.)
    for i,path in enumerate(levels[acceptable_level]):
            p =  map(tuple,path)   #contour includes full 
            mymap.addpath(p,color=color,fillcolor=color,opacity=.5)

    #plot the other contour levels
    #select approriate lines to plot from 'levels' using slices
    for i,paths in enumerate(levels[::3][:3]):
        #colors slowly turns from blue to red, slice it differently to get faster change in color
        color='#%0.2x%0.2x%0.2x' % tuple([q*255 for q in colors[i*4][0][:-1]])
        for i,path in enumerate(paths):
            p =  map(tuple,path)    
            mymap.addpath(p,color=color,fillcolor=color,opacity=0)

    print "contour values: %s" % (legend,) 
    mymap.draw('./html/mymap.html')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.