In [120]:
import plotly
from plotly import tools
from plotly.offline import iplot
from plotly import graph_objs as go
plotly.offline.init_notebook_mode()
print(69)


69

In [64]:
INTEGER_HOUR_TO_PRETTY_HOUR = {
    0: '12:00 AM',
    1: '1:00 AM',
    2: '2:00 AM',
    3: '3:00 AM',
    4: '4:00 AM',
    5: '5:00 AM',
    6: '6:00 AM',
    7: '7:00 AM',
    8: '8:00 AM',
    9: '9:00 AM',
    10: '10:00 AM',
    11: '11:00 AM',
    12: '12:00 PM',
    13: '1:00 PM',
    14: '2:00 PM',
    15: '3:00 PM',
    16: '4:00 PM',
    17: '5:00 PM',
    18: '6:00 PM',
    19: '7:00 PM',
    20: '8:00 PM',
    21: '9:00 PM',
    22: '10:00 PM',
    23: '11:00 PM',
}
BASE_LAYOUT = {
    'title': 'Average travel time in 2016',
    'xaxis': {'title': 'Hour of day'},
    'yaxis': {'title': 'Duration in minutes'},
}
RED = '#d62728'
BLUE = '#1f77b4'

In [118]:
files = [
    {
        'path': 'results/duration_by_hour/1_triangle-to-republic_2016*.csv',
        'name': '1',
        'color': BLUE,
        'trip': 'core',
    },
    {
        'path': 'results/duration_by_hour/801_triangle-to-republic_2016*.csv',
        'name': '801',
        'color': RED,
        'trip': 'core',
    },
    {
        'path': 'results/duration_by_hour/1_techridge-to-cannon_2016*.csv',
        'name': '1',
        'color': BLUE,
        'trip': 'end to end',
    },
    {
        'path': 'results/duration_by_hour/801_techridge-to-southpark_2016*.csv',
        'name': '801',
        'color': RED,
        'trip': 'end to end',
    },
    {
        'path': 'results/duration_by_hour/801_triangle-to-republic_2015-05*.csv',
        'name': '801',
        'color': RED,
        'trip': '2015 may end to end',
    },
    {
        'path': 'results/duration_by_hour/1_triangle-to-republic_2015-05*.csv',
        'name': '1',
        'color': BLUE,
        'trip': '2015 may end to end',
    },    
    {
        'path': 'results/duration_by_hour/803_northloop-to-republic_2016*.csv',
        'name': '803',
        'color': RED,
        'trip': 'core',
    },
    {
        'path': 'results/duration_by_hour/3_northloop-to-republic_2016*.csv',
        'name': '3',
        'color': BLUE,
        'trip': 'core',
    },
    # {
    #     'path': 'results/duration_by_hour/803_northloop-to-republic_2016*.csv',
    #     'name': '803',
    #     'color': RED,
    #     'trip': 'end to end',
    # },
    # {
    #     'path': 'results/duration_by_hour/3_northloop-to-republic_2016*.csv',
    #     'name': '3',
    #     'color': BLUE,
    #     'trip': 'end to end',
    # },
]

In [121]:
def draw(targets, title):
    dfs = []
    traces = []
    for target in targets:
        df = pd.read_csv(target['path'], sep='\t')
        df.hour = df.hour.apply(lambda x: INTEGER_HOUR_TO_PRETTY_HOUR[x])
        df['mean'] = df['mean'] / 60

        trace = go.Scatter(
            x = df.hour,
            y = df['mean'],
            mode='lines',
            name=target['name'],
            line={'color': target['color']},
        )
        traces.append(trace)

    layout = BASE_LAYOUT.copy()
    layout['title'] = title
    fig = go.Figure(
        data=traces,
        layout=layout,
    )
    iplot(fig)

In [102]:
draw([files[0], files[1]], '801 vs 1 between triangle and republic square')



In [105]:
draw([files[2], files[3]], '801 vs 1 end to end')



In [119]:
draw([files[4], files[5]], '801 vs 1 2015 May core')