carpool_test_notebook



In [5]:
import demo_funcs
from demo_funcs import *
import bokeh.plotting as bk
from bokeh.models.mappers import LinearColorMapper
bk.output_notebook(force=True)


BokehJS successfully loaded.

Warning: BokehJS previously loaded


In [4]:
users = create_users()
route_shapes = []
for user in users:
    route = create_route(user)
    route_shapes.append(get_line_shape(route))

In [15]:
bk.figure(plot_width=1100, plot_height=750, title="Users Homes and Destinations", tools="pan, box_zoom, reset")
bk.hold(True)
bk1 = bk.patches(county_xs, county_ys, fill_color="#A49480", line_color="white", line_width=0.5)

In [16]:
for index, user in enumerate(users):
    home_latitudes = [user["home_latitude"]]
    home_longitudes = [user["home_longitude"]]
    work_latitudes = [user["work_latitude"]]
    work_longitudes = [user["work_longitude"]]
    user['color'] = colors[index]
    bk.scatter(home_longitudes, home_latitudes, color=colors[index], line_width=2)
    bk.scatter(work_longitudes, work_latitudes, color=colors[index], marker="square", line_width=2)

In [17]:
bk.xgrid().grid_line_color = None
bk.ygrid().grid_line_color = None
bk.hold(False)
bk.show()



In [15]:
bk.figure(plot_width=850, plot_height=500, title="Individuals Routes", tools="pan, box_zoom, reset")
bk.hold(True)
bk1 = bk.patches(county_xs, county_ys, fill_color="#A49480", line_color="white", line_width=0.3)

In [16]:
shape_colors = []
for index, user in enumerate(users):
    latitudes = [user["home_latitude"], user["work_latitude"]]
    longitudes = [user["home_longitude"], user["work_longitude"]]
    bk.scatter(longitudes, latitudes, color=user['color'], line_width=4)
    shape_colors.append(user['color'])
for index, shape_list in enumerate(route_shapes):
    latitudes, longitudes = parse_request(shape_list)
    bk.line(longitudes, latitudes, line_width=3, color=shape_colors[index], alpha=.5)

In [17]:
bk.xgrid().grid_line_color = None
bk.ygrid().grid_line_color = None
bk.hold(False)
bk.show()



In [18]:
carpools = pair_users(users)

In [19]:
bk.figure(plot_width=850, plot_height=500, title="Calculated Pairs", tools="pan, box_zoom, reset")
bk.hold(True)
bk1 = bk.patches(county_xs, county_ys, fill_color="#A49480", line_color="white", line_width=0.5)

In [20]:
for index, user in enumerate(users):
    latitudes = [user["home_latitude"], user["work_latitude"]]
    longitudes = [user["home_longitude"], user["work_longitude"]]
    bk.scatter(longitudes, latitudes, color=user['color'], line_width=4)
    
for index, carpool in enumerate(carpools):
    home_latitudes = [carpool[0]["home_latitude"], carpool[1]["home_latitude"]]
    home_longitudes = [carpool[0]["home_longitude"], carpool[1]["home_longitude"]]
    work_latitudes = [carpool[0]["work_latitude"], carpool[1]["work_latitude"]]
    work_longitudes = [carpool[0]["work_longitude"], carpool[1]["work_longitude"]]
    bk.line(home_longitudes, home_latitudes, line_width=3, color=carpool[0]['color'], alpha=1)
    bk.line(work_longitudes, work_latitudes, line_width=3, color=carpool[0]['color'], alpha=1)

In [21]:
bk.xgrid().grid_line_color = None
bk.ygrid().grid_line_color = None
bk.hold(False)
bk.show()



In [22]:
route_shapes = []
carpool_colors = []
for carpool in carpools:
    route, driver = determine_best_route(carpool)
    if route:
        route_shapes.append(route)
        carpool_colors.append(driver['color'])

In [23]:
bk.figure(plot_width=850, plot_height=500, title="Rideo!!!", tools="pan, box_zoom, reset")
bk.hold(True)
bk1 = bk.patches(county_xs, county_ys, fill_color="#A49480", line_color="white", line_width=0.5)

In [24]:
for index, user in enumerate(users):
    latitudes = [user["home_latitude"], user["work_latitude"]]
    longitudes = [user["home_longitude"], user["work_longitude"]]
    bk.scatter(longitudes, latitudes, color=user['color'], line_width=4, )
    
    
for index, shape_list in enumerate(route_shapes):
    latitudes, longitudes = parse_request(shape_list)
    bk.line(longitudes, latitudes, line_width=3, color=carpool_colors[index], alpha=0.5)

In [25]:
bk.xgrid().grid_line_color = None
bk.ygrid().grid_line_color = None
bk.hold(False)
bk.show()



In [ ]:


In [ ]: