Пример #1
0
def plt_barchart_grupped(data, param_dict, mode='object', output_path=None):
    '''
    data: rows = list of dicts(): keywords with neat naming straight to put in charts
    param_dict: dictionary with settings as follows:
    {'x':'name of column to put on x axis',
     'y':'name of column to put in y axis',
     'agg':'name of aggregate function: 'sum'/'count' /etc',
     'color':'name of name of column to create siloses by/to apply aggr funct',
     'tooltips':['list() of strings with column names to put in tooltip cloud']}
    mode: 'object'/'save'/'show'/'embed' - either returns plot object / saves to path + returns True / saves to path and shows plot
    output_path: string with html ext to save chart to. If None then emmbed is returned
    returns: True(saved to file) or emmbed data code
    '''
    # tooltips=[
    # ("Date", "$x"),
    # ("version", "@HVAC_version")]

    # p = Bar(data, label='Date', values='HVAC_version', agg='count', group='HVAC_version',
    # title="Median MPG by YR, grouped by ORIGIN", legend='bottom_right', bar_width=3.0,
    # plot_width=1000, plot_height=400, tooltips = tooltips)
    # p.legend.background_fill_alpha = 0.8

    # output_file("bar.html")

    # show(p)
    #to_date(data,'%Y-%m-01')
    tooltips = create_tooltips(param_dict)

    title = "{} of {} by {}, grouped by {}".format(param_dict['agg'],
                                                   param_dict['y'].upper(),
                                                   param_dict['x'].upper(),
                                                   param_dict['color'].upper())

    p = Bar(data=data,
            label=param_dict['x'],
            values=param_dict['y'],
            agg=param_dict['agg'],
            group=param_dict['color'],
            title=title,
            legend='bottom_right',
            bar_width=3.0,
            plot_width=1000,
            plot_height=600,
            tooltips=tooltips)
    #legend_sort_field = param_dict['group'])
    p.legend.background_fill_alpha = 0.8

    if type(data[0][param_dict['x']]) == str:
        x_rng = sort_axis(data, param_dict['x'], False, True)
        p.x_range = x_rng

    if type(data[0][param_dict['y']]) == str:
        y_rng = sort_axis(data, param_dict['y'], False, True)
        p.y_range = y_rng

    return do_output(p, mode, output_path)
Пример #2
0
def leagues():
    grouped = df_squads.groupby('year')
    club_country = df_squads.club_country.unique()
    club_country.sort()
    df_clb_ctry = pd.DataFrame({"club_country":club_country})
    
    for year in df_squads.year.unique():
        country_to_club = grouped.club_country.value_counts()[year] / grouped.team.value_counts()[year]
        df_clb_ctry = df_clb_ctry.join(country_to_club.to_frame(year))
        
    df_clb_ctry = df_clb_ctry.fillna(0) # If NaN, country league not represented at the world cup
    df_clb_ctry = df_clb_ctry.T
    
    plot_nat_leagues = figure(tools=TOOLS,
                  x_axis_label='World Cup Year',
                  toolbar_location=None
                  )
    
    # take the top 11 countries and plot
    for num, country in enumerate(df_clb_ctry.sum().sort_values(ascending=False).head(11).index):
        plot_nat_leagues.scatter(df_clb_ctry.index, df_clb_ctry[country],legend=country,color=RdBu11[num],size=8, alpha=0.5)
    
    plot_nat_leagues.legend.location = "top_left"
    
    df_expats = df_league_data[df_league_data.nation!=df_league_data.nationality]
    
    seasons = df_expats.season.unique()
    
    min = int(seasons[0].split('-')[0])
    max = int(seasons[-1].split('-')[0])
    
    wc_year_slider = Slider(start=min, end=max, value=max, step=1, title="Soccer Season")
    
    for season in seasons:
        nationality_expats = df_expats.groupby('season').nationality.value_counts()[season].head(5)
        nation_expats = df_expats.groupby('season').nation.value_counts()[season]
    
    plot_expats = Bar(nationality_expats, toolbar_location=None)
    plot_expats.x_range = FactorRange(factors=nationality_expats.index.tolist())
    
    plot_dict = {"nations":plot_nat_leagues, "expats":plot_expats}
    
    script, div = components(plot_dict)
    
    return render_template('league.html', js_resources=js_resources, script=script, div=div)
def bar_plot_table(table, **kwargs):
    """Plot a tabular DataFrame with an index and multiple columns representing
    categories using a Bokeh bar chart.

    In addition to the keyword parameters accepted by bokeh.charts.Bar, this
    function accepts the following additional keyword arguments:

    number_of_categories: integer
        The number of categories ranked by total value to use.
    xaxis_formatter: TickFormatter
        The formatter to use for x axis values.
    yaxis_formatter: TickFormatter
        The formatter to use for y axis values.
    x_range: Range1d
        A range to use for the X-axis.
    y_range: Range1d
        A range to use for the Y-axis.
    """
    if kwargs.has_key('number_of_categories'):
        revenue_table = analysis.select_top_n_columns(
            table, kwargs['number_of_categories'])
    else:
        revenue_table = table
    revenue_stacked = revenue_table.stack().reset_index()
    revenue_stacked.columns = ['year', 'commodity_desc', 'value']
    revenue_plot = Bar(
        revenue_stacked,
        label='year',
        stack='commodity_desc',
        values='value',
        **_remove_custom_keys(kwargs)
    )
    if kwargs.has_key('x_range'):
        revenue_plot.x_range = kwargs['x_range']
    if kwargs.has_key('y_range'):
        revenue_plot.y_range = kwargs['y_range']
    else:
        revenue_plot.y_range = Range1d(0, revenue_table.max().sum())
    if kwargs.has_key('xaxis_formatter'):
        revenue_plot._xaxis.formatter = kwargs['xaxis_formatter']
    if kwargs.has_key('yaxis_formatter'):
        revenue_plot._yaxis.formatter = kwargs['yaxis_formatter']
    return revenue_plot
Пример #4
0
def generate_chart(year):
    data = get_data(year)

    plot_data = {
        'country': data.index.tolist(),
        'count': [float(i) for i in data.values.tolist()]
    }

    barchart = Bar(plot_data,
                   label='country',
                   values='count',
                   color="red",
                   xgrid=False,
                   ygrid=False,
                   plot_width=800,
                   plot_height=500,
                   tools="pan,wheel_zoom,box_zoom,reset,resize")

    barchart.title = "Formula SAE Michigan " + year + " Countries"

    barchart.x_range = FactorRange(factors=data.index.tolist())

    barchart._xaxis.axis_label = "Country"
    barchart._xaxis.axis_line_color = None
    barchart._xaxis.major_tick_line_color = None
    barchart._xaxis.minor_tick_line_color = None

    barchart._yaxis.axis_label = "Number of Teams"
    barchart._yaxis.axis_line_color = None
    barchart._yaxis.major_tick_line_color = None
    barchart._yaxis.minor_tick_line_color = None

    barchart.outline_line_color = None

    barchart.toolbar_location = 'right'

    barchart.logo = None

    hover = HoverTool(tooltips=[("Country", '@x'), ("# Teams", '@height')])

    barchart.add_tools(hover)

    return barchart
Пример #5
0
def bar_plot_table(table, **kwargs):
    """Plot a tabular DataFrame with an index and multiple columns representing
    categories using a Bokeh bar chart.

    In addition to the keyword parameters accepted by bokeh.charts.Bar, this
    function accepts the following additional keyword arguments:

    number_of_categories: integer
        The number of categories ranked by total value to use.
    xaxis_formatter: TickFormatter
        The formatter to use for x axis values.
    yaxis_formatter: TickFormatter
        The formatter to use for y axis values.
    x_range: Range1d
        A range to use for the X-axis.
    y_range: Range1d
        A range to use for the Y-axis.
    """
    if kwargs.has_key('number_of_categories'):
        revenue_table = analysis.select_top_n_columns(
            table, kwargs['number_of_categories'])
    else:
        revenue_table = table
    revenue_stacked = revenue_table.stack().reset_index()
    revenue_stacked.columns = ['year', 'commodity_desc', 'value']
    revenue_plot = Bar(revenue_stacked,
                       label='year',
                       stack='commodity_desc',
                       values='value',
                       **_remove_custom_keys(kwargs))
    if kwargs.has_key('x_range'):
        revenue_plot.x_range = kwargs['x_range']
    if kwargs.has_key('y_range'):
        revenue_plot.y_range = kwargs['y_range']
    else:
        revenue_plot.y_range = Range1d(0, revenue_table.max().sum())
    if kwargs.has_key('xaxis_formatter'):
        revenue_plot._xaxis.formatter = kwargs['xaxis_formatter']
    if kwargs.has_key('yaxis_formatter'):
        revenue_plot._yaxis.formatter = kwargs['yaxis_formatter']
    return revenue_plot
Пример #6
0
def generate_chart(year):
    data = get_data(year)

    plot_data = {'country': data.index.tolist(),
                 'count': [float(i) for i in data.values.tolist()]}

    barchart = Bar(plot_data,
                   label='country',
                   values='count',
                   color="red",
                   xgrid=False, ygrid=False,
                   plot_width=800, plot_height=500,
                   tools="pan,wheel_zoom,box_zoom,reset,resize")

    barchart.title = "Formula SAE Michigan " + year + " Countries"

    barchart.x_range = FactorRange(factors=data.index.tolist())

    barchart._xaxis.axis_label = "Country"
    barchart._xaxis.axis_line_color = None
    barchart._xaxis.major_tick_line_color = None
    barchart._xaxis.minor_tick_line_color = None

    barchart._yaxis.axis_label = "Number of Teams"
    barchart._yaxis.axis_line_color = None
    barchart._yaxis.major_tick_line_color = None
    barchart._yaxis.minor_tick_line_color = None

    barchart.outline_line_color = None

    barchart.toolbar_location = 'right'

    barchart.logo = None

    hover = HoverTool(tooltips=[("Country", '@x'),
                                ("# Teams", '@height')])

    barchart.add_tools(hover)

    return barchart
Пример #7
0
def fun():
    plot_transfer_fee = figure(tools=TOOLS,
                      title='World Record Soccer Transfer Fee',
                      x_axis_label='Year',
                      y_axis_label=u"Fee (\u00A3)",
                      toolbar_location=None
                      )
    
    plot_transfer_fee.line(df_tranfer['year'], df_tranfer['fee_pounds'],color=RdBu11[0],line_width=4)

    month_map = {k: v for k,v in enumerate(calendar.month_abbr)}
    
    df_mth = df_squads.birth_month.value_counts().sort_index()
    df_mth.index = df_mth.index.map(lambda x: month_map[x])
    
    plot_mth_of_birth = Bar(df_mth, toolbar_location=None)
    plot_mth_of_birth.x_range = FactorRange(factors=df_mth.index.tolist())
    
    plots = {"plt_trans_fee": plot_transfer_fee, "plt_mth_birth": plot_mth_of_birth}
    
    script, div = components(plots)
    
    return render_template('interesting.html', js_resources=js_resources, script=script, div=div)
Пример #8
0
        # Display just the given columns in the tooltips
        hover.tooltips = [(c, '@' + c) for c in cols]

    hover.tooltips.append(('index', '$index'))

    # Finally add/enable the tool
    fig.add_tools(hover)
    
    return fig


p2 = scatter_with_hover(test2, 'abs_third_less_adv_simple', 'abs_third_less_adv', marker='circle', fig_width=800, fig_height=800, cols=['bea_code', 'date', 'abs_third_less_adv_simple', 'abs_third_less_adv'], size=20)
p2.title ="Offsetting revisions"
p2.xaxis.axis_label="Absolute (third less adv)"
p2.yaxis.axis_label="Aggregate absolute (third less adv)"
p2.x_range= Range1d(0,test2['abs_third_less_adv_simple'].max()*1.1)
p2.y_range= Range1d(0,test2['abs_third_less_adv'].max()*1.1)

sum_rev = test2['abs_third_less_adv']
simple = test2['abs_third_less_adv_simple']

regression = np.polyfit(simple, sum_rev, 1)
r_x, r_y = zip(*((i, i*regression[0] + regression[1]) for i in range(len(test2['abs_third_less_adv']))))
p2.line(r_x, r_y, color="red", line_width=6)
output_file("regression.html")
show(p2)




		second = elem[1]
		list_of_words.append(first)
		list_of_num.append(second)
	return list_of_words, list_of_num


a = [(u'colada', 1.06465), (u'mmmmmmmmmmmmmmmmmmmmm', 0.85172), (u'brunched', 0.85172), (u'combinacion', 0.85172), (u'altar', 0.85172), (u'heckled', 0.70977), (u'guitarist', 0.70977), (u'benched', 0.60837), (u'suprisingly', 0.60837), (u'jombot', 0.60837), (u'cpt', 0.53232), (u'pubgrub', 0.53232), (u'prepaired', 0.53232), (u'bestpapersonaltrainercom', 0.53232), (u'touristic', 0.47318), (u'delucas', 0.47318), (u'stickler', 0.47318), (u'parfaits', 0.47318), (u'mochas', 0.45543), (u'bearclaw', 0.42586), (u'isntead', 0.42586), (u'portapottys', 0.42586), (u'centerpieces', 0.42586), (u'newcastle', 0.42586), (u'anf', 0.42586), (u'hollywoodlanes', 0.42586), (u'hideaway', 0.38715), (u'haiku', 0.38715), (u'muffaletta', 0.38715), (u'anazing', 0.38715),(u'balboa', 0.06347), (u'novak', 0.06342), (u'aamco', 0.06337), (u'faded', 0.06317), (u'jojo', 0.06312), (u'unos', 0.06309), (u'proves', 0.06309), (u'refurbish', 0.06309), (u'fleet', 0.06309), (u'koh', 0.06309)]

list_of_words, list_of_num = parse_elements(a)

model = {'TF-IDF': list_of_num, 'Words': list_of_words}
df1 = df(data = model, columns = ['TF-IDF','Words'])

graph1 = Bar(df1, 'Words', values = 'TF-IDF', title = "TF-IDF of top positive words", ylabel = 'TF-IDF  scores', width = 800, height = 400, color = 'blue')
graph1.left[0].formatter.use_scientific= False
graph1.x_range = FactorRange(factors=df1['Words'].tolist())



c = [(u'hoofah', 4.2586), (u'ewwww', 4.2586), (u'disconnected', 0.70977), (u'precooked', 0.70977), (u'crimes', 0.60837), (u'greasiest', 0.60837), (u'redevelopment', 0.60837), (u'sloooooow', 0.53232), (u'yucky', 0.53232), (u'horrifying', 0.53232), (u'rancho', 0.47318), (u'crisco', 0.47318), (u'grabn', 0.42586), (u'gnocci', 0.42586), (u'strictest', 0.38715), (u'clout', 0.38715), (u'unenjoyable', 0.38715), (u't3', 0.36502), (u'terriable', 0.32758), (u'foe', 0.32758), (u'pararell', 0.32758), (u'thrifters', 0.32758), (u'society', 0.30419), (u'cremation', 0.28391), (u'fabricated', 0.28391), (u'yiengling', 0.28391), (u'delish', 0.27475), (u'uncover', 0.26616), (u'm8n', 0.26616), (u'pepparoni', 0.26616),(u'drops', 0.03097), (u'scheduling', 0.03097), (u'towed', 0.03089), (u'stark', 0.03086), (u'bjork', 0.03086), (u'arrogance', 0.03086), (u'maitre', 0.03086), (u'electronica', 0.03086), (u'basing', 0.03086), (u'caters', 0.03086)]
list_of_words2, list_of_num2 = parse_elements(c)
model2 = {'TF-IDF': list_of_num2, 'Words': list_of_words2}
df2 = df(data = model2, columns = ['TF-IDF','Words'])

graph2 = Bar(df2, 'Words', values = 'TF-IDF', title = "TF-IDF of top negative words", ylabel = 'TF-IDF  scores', width = 800, height = 400, color = 'red')
graph2.left[0].formatter.use_scientific= False
graph2.x_range = FactorRange(factors=df2['Words'].tolist())

output_file("swag1.html")
total = vplot(graph1, graph2)
show(total)
Пример #10
0
def templateCoefRegression(c='c00001'):
    data = pd.read_csv(DATA + 'LogisticRegressionCoef_' + c + '_true.csv', header=0)

    data_month = data.ix[12:23, ]
    data_month = data_month.reindex([16, 15, 19, 12, 20, 18, 17, 13, 23, 22, 21, 14])

    data_empl = data.ix[0:11, ]
    data_empl = data_empl.reindex([10, 0, 2, 3, 4, 5, 6, 7, 8, 9, 1, 11])

    data_state = data.ix[24:74, ]
    data_other = data.ix[75:76, ]

    pMonth = Bar(data_month, 'coef', values='val', legend=False, tools='hover')
    pMonth.x_range = FactorRange(factors=data_month['coef'].tolist())
    pMonth.xaxis.axis_label = 'Coefficients'
    pMonth.yaxis.axis_label = 'Value'
    hover = pMonth.select_one(HoverTool)
    hover.point_policy = "follow_mouse"
    hover.tooltips = [
        ("Coef: ", "@coef"),
        ("Value: ", "@height")
    ]
    # show(pMonth)

    pEmpl = Bar(data_empl, 'coef', values='val', legend=False, tools='hover')
    pEmpl.x_range = FactorRange(factors=data_empl['coef'].tolist())
    pEmpl.xaxis.axis_label = 'Coefficients'
    pEmpl.yaxis.axis_label = 'Value'
    hover = pEmpl.select_one(HoverTool)
    hover.point_policy = "follow_mouse"
    hover.tooltips = [
        ("Coef: ", "@coef"),
        ("Value: ", "@height")

    ]
    # show(pEmpl)

    pState = Bar(data_state, 'coef', values='val', legend=False, tools='hover', width=1200)
    # # pState.x_range = FactorRange(factors=dm['coef'].tolist())
    pState.xaxis.axis_label = 'Coefficients'
    pState.yaxis.axis_label = 'Value'
    hover = pState.select_one(HoverTool)
    hover.point_policy = "follow_mouse"
    hover.tooltips = [
        ("Coef: ", "@coef"),
        ("Value: ", "@height")

    ]

    # show(pState)

    pOther = Bar(data_other, 'coef', values='val', legend=False, tools='hover')
    pOther.xaxis.axis_label = 'Coefficients'
    pOther.yaxis.axis_label = 'Value'
    # pOther.x_range = FactorRange(factors=data_other['coef'].tolist())
    hover = pOther.select_one(HoverTool)
    hover.point_policy = "follow_mouse"
    hover.tooltips = [
        ("Coef: ", "@coef"),
        ("Value: ", "@height")

    ]

    # show(pOther)

    scriptM, divM = components(pMonth)
    scriptE, divE = components(pEmpl)
    scriptS, divS = components(pState)
    scriptO, divO = components(pOther)

    dic_r = {'month': [scriptM, divM], 'empl': [scriptE, divE], 'state': [scriptS, divS], 'other': [scriptO, divO]}

    return dic_r
Пример #11
0
from bokeh.charts import Bar, output_file, show, vplot
from numpy.random import rand
from pandas import DataFrame

N = 10
data = DataFrame({'A': rand(N), 'B': rand(N), 'C': rand(N)})
# Stack columns A,B,C and convert the multiindices to columns
sdata = data.stack().reset_index()
sdata.columns = ['labels', 'stack', 'values']

bar = Bar(sdata, values='values', label='labels', stack='stack', legend='top_right')
bar2 = Bar(sdata, values='values', label='labels', stack='stack', legend='top_right')
bar2.x_range = bar.x_range  # Link the x axes

output_file("stacked_bar.html")
show(vplot(bar, bar2))
Пример #12
0
def predict():
    
    def weighted_choice(choices):
        total = sum(w for c, w in choices)
        r = random.uniform(0, total)
        upto = 0
        for c, w in choices:
            if upto + w >= r:
                return c
            upto += w
        assert False, "Shouldn't get here"
    
    df_fifa_latest_rank
    
    z = np.polyfit(df_prob_win_fifa_rank.rank_diff, df_prob_win_fifa_rank.prob, 4)
    p_win = np.poly1d(z)
    
    # p_win(_some_rank)
    
    z = np.polyfit(df_prob_draw_fifa_rank.rank_diff.values, df_prob_draw_fifa_rank.prob.values, 3)
    p_draw = np.poly1d(z)
    
    country_codes = {
        "Albania": "ALB",
        "Austria": "AUT",
        "Belgium": "BEL",
        "Croatia": "CRO",
        "Czech Republic": "CZE",
        "England": "ENG",
        "France": "FRA",
        "Germany": "GER",
        "Hungary": "HUN",
        "Iceland": "ISL",
        "Italy": "ITA",
        "Northern Ireland": "NIR",
        "Poland": "POL",
        "Portugal": "POR",
        "Republic of Ireland": "IRL",
        "Romania": "ROU",
        "Russia": "RUS",
        "Slovakia": "SVK",
        "Spain": "ESP",
        "Sweden": "SWE",
        "Switzerland": "SUI",
        "Turkey": "TUR",
        "Ukraine": "UKR",
        "Wales": "WAL",
    }
    
    country_from_codes = {
        "ALB": "Albania",
        "AUT": "Austria",
        "BEL": "Belgium",
        "CRO": "Croatia",
        "CZE": "Czech Republic",
        "ENG": "England",
        "FRA": "France",
        "GER": "Germany",
        "HUN": "Hungary",
        "ISL": "Iceland",
        "ITA": "Italy",
        "NIR": "Northern Ireland",
        "POL": "Poland",
        "POR": "Portugal",
        "IRL": "Republic of Ireland",
        "ROU": "Romania",
        "RUS": "Russia",
        "SVK": "Slovakia",
        "ESP": "Spain",
        "SWE": "Sweden",
        "SUI": "Switzerland",
        "TUR": "Turkey",
        "UKR": "Ukraine",
        "WAL": "Wales",
    }
    
    grp_A_matches = [
        ['2016-06-10', 'France', 'Romania'],
        ['2016-06-11', 'Albania', 'Switzerland'],
        ['2016-06-15', 'Romania', 'Switzerland'],
        ['2016-06-15', 'France', 'Albania'],
        ['2016-06-19', 'Switzerland', 'France'],
        ['2016-06-19', 'Romania', 'Albania'],
    ]
    
    grp_B_matches = [
        ['2016-06-11', 'Wales', 'Slovakia'],
        ['2016-06-11', 'England', 'Russia'],
        ['2016-06-15', 'Russia', 'Slovakia'],
        ['2016-06-16', 'England', 'Wales'],
        ['2016-06-20', 'Slovakia', 'England'],
        ['2016-06-20', 'Russia', 'Wales'],
    ]
    
    grp_C_matches = [
        ['2016-06-12', 'Poland', 'Northern Ireland'],
        ['2016-06-12', 'Germany', 'Ukraine'],
        ['2016-06-16', 'Ukraine', 'Northern Ireland'],
        ['2016-06-16', 'Germany', 'Poland'],
        ['2016-06-21', 'Northern Ireland', 'Germany'],
        ['2016-06-21', 'Ukraine', 'Poland'],
    ]
    
    grp_D_matches = [
        ['2016-06-12', 'Turkey', 'Croatia'],
        ['2016-06-13', 'Spain', 'Czech Republic'],
        ['2016-06-17', 'Czech Republic', 'Croatia'],
        ['2016-06-17', 'Spain', 'Turkey'],
        ['2016-06-21', 'Croatia', 'Spain'],
        ['2016-06-21', 'Czech Republic', 'Turkey'],
    ]
    
    grp_E_matches = [
        ['2016-06-13', 'Republic of Ireland', 'Sweden'],
        ['2016-06-13', 'Belgium', 'Italy'],
        ['2016-06-17', 'Italy', 'Sweden'],
        ['2016-06-18', 'Belgium', 'Republic of Ireland'],
        ['2016-06-22', 'Sweden', 'Belgium'],
        ['2016-06-22', 'Italy', 'Republic of Ireland'],
    ]
    
    grp_F_matches = [
        ['2016-06-14', 'Austria', 'Hungary'],
        ['2016-06-14', 'Portugal', 'Iceland'],
        ['2016-06-18', 'Iceland', 'Hungary'],
        ['2016-06-18', 'Portugal', 'Austria'],
        ['2016-06-22', 'Iceland', 'Austria'],
        ['2016-06-22', 'Hungary', 'Portugal'],
    ]
    
    grp_matchs = grp_A_matches + grp_B_matches + grp_C_matches + grp_D_matches + grp_E_matches + grp_F_matches
    
    df_ctry_codes = df_fifa_latest_rank.country_code
    probailities = []
    plot_dict = {}
    prediction_dict = {}
    results = {}
    for k, match in enumerate(grp_matchs,1):
        rank_diff = df_fifa_latest_rank[df_ctry_codes==country_codes[match[1]]].ranking.values - df_fifa_latest_rank[df_ctry_codes==country_codes[match[2]]].ranking.values
        probs = [p_win(rank_diff*-1)[0], p_draw(abs(rank_diff))[0], p_win(rank_diff)[0]]
        probs = [float(i)/sum(probs) for i in probs]
        probailities = [country_codes[match[1]], 'DRAW', country_codes[match[2]]] + probs
        choices = [(country_codes[match[1]], probs[0]), ('DRAW', probs[1]), (country_codes[match[2]], probs[2])]
        
        prediction = weighted_choice(choices)
        if prediction=='DRAW':
            prediction_dict["match_{0}".format(k)] = prediction
        else:
            prediction_dict["match_{0}".format(k)] = country_from_codes[prediction]
        
        df = pd.DataFrame(probailities[3:], probailities[:3])
        df.columns = ['probability']
        plot_probs = Bar(df, toolbar_location=None, plot_width=200, plot_height=200, agg='mean')
        plot_probs.x_range = FactorRange(factors=probailities[:3])
        plot_dict["match_{0}".format(k)] = plot_probs
    
    gp_A = dict.fromkeys(["France","Romania","Albania","Switzerland"], 0)
    gp_B = dict.fromkeys(["England","Russia","Wales","Slovakia"], 0)
    gp_C = dict.fromkeys(["Germany","Ukraine","Poland","Northern Ireland"], 0)
    gp_D = dict.fromkeys(["Spain","Czech Republic","Turkey","Croatia"], 0)
    gp_E = dict.fromkeys(["Belgium","Italy","Republic of Ireland","Sweden"], 0)
    gp_F = dict.fromkeys(["Portugal","Iceland","Austria","Hungary"], 0)
    for k, match in enumerate(grp_A_matches,1):
        result = prediction_dict["match_{0}".format(k)]
        if result == 'DRAW':
            gp_A[match[1]] += 1
            gp_A[match[2]] += 1
        else:
            gp_A[result] += 3
    
    for k, match in enumerate(grp_B_matches,7):
        result = prediction_dict["match_{0}".format(k)]
        if result == 'DRAW':
            gp_B[match[1]] += 1
            gp_B[match[2]] += 1
        else:
            gp_B[result] += 3

    for k, match in enumerate(grp_C_matches,13):
        result = prediction_dict["match_{0}".format(k)]
        if result == 'DRAW':
            gp_C[match[1]] += 1
            gp_C[match[2]] += 1
        else:
            gp_C[result] += 3

    for k, match in enumerate(grp_D_matches,19):
        result = prediction_dict["match_{0}".format(k)]
        if result == 'DRAW':
            gp_D[match[1]] += 1
            gp_D[match[2]] += 1
        else:
            gp_D[result] += 3

    for k, match in enumerate(grp_E_matches,25):
        result = prediction_dict["match_{0}".format(k)]
        if result == 'DRAW':
            gp_E[match[1]] += 1
            gp_E[match[2]] += 1
        else:
            gp_E[result] += 3

    for k, match in enumerate(grp_F_matches,31):
        result = prediction_dict["match_{0}".format(k)]
        if result == 'DRAW':
            gp_F[match[1]] += 1
            gp_F[match[2]] += 1
        else:
            gp_F[result] += 3
            
    all_groups = [gp_A,gp_B,gp_C,gp_D,gp_E,gp_F]
    gp_labels = {1:"A",2:"B",3:"C",4:"D",5:"E",6:"F"}
    table_html = {}
    for k, group in enumerate(all_groups,1):
        table_string = ['      <table style="width:100%">']
        group_standings = {'team':[], 'points':[]}
        for j in xrange(1,len(group)+1):
            table_string.append('        <tr>')
            top = max(group, key=group.get)
            points = group.get(top)
            group_standings['team'].append(top)
            group_standings['points'].append(points)
            group.pop(top)
            table_string.append('          <td>{0}</td>'.format(j))
            table_string.append('          <td>{0}</td>'.format(top))
            table_string.append('          <td>{0}</td>'.format(points))
            table_string.append('        </tr>')
        table_string.append('        </table>')
        table_html["gp_{0}".format(gp_labels[k])] = '\n'.join(table_string) 
    
    script, div = components(plot_dict)
    
    return render_template('euro.html', js_resources=js_resources, script=script, div=div, pred=prediction_dict, table=table_html)