示例#1
0
def sim_scheduled_games(sch_game_dicts, n):
    """
    
    """
#    print sch_game_dicts.keys()
#    print
    prediction_dict = {}
    CandP = CombosAndPermuts()
    trifs = CandP.get_trifectas()
    str_trifs = [str(x[0]) + str(x[1]) + str(x[2]) for x in trifs]
#[x for x in range(1, self.numPlayers +1)]
    win = [x[0] for x in trifs] ; place = [x[1] for x in trifs] ; show = [x[2] for x in trifs]
    wpsTable = pd.DataFrame(data = {'First':win,'Second':place, 'Third':show}, index = str_trifs)
    #print wpsTable.head()
    #print wpsTable.columns.values.tolist()
   

    for game_name,game_data in sch_game_dicts.items():

        pwin_dict = rds.get_pwin_dict()

        point_percentage_data = None
        player_list = []
        enh_player_list = []
        #print game
#        for el in game:
#            print el
        enh_player_list = get_enhanced_player_list(game_data)

        #print game_name, enh_player_list
        if enh_player_list != None:
            #print
            #print game_name
            for player_dict in enh_player_list:
                
                player_list.append(':'.join(ut.sorted_and_lowered(player_dict['name'])))

#            point_percentage_data = sc.runGame_get_WPS_frequencies(player_list, n)

            point_percentage_data = sc.runGame_get_WPS_frequencies(player_list, pwin_dict, n)
            


            prediction_dict[game_name] = point_percentage_data
    pred_dict_df = pd.DataFrame.from_dict(prediction_dict)
    #print pred_dict_df.head()
    full_df = pd.merge(wpsTable, pred_dict_df, left_index = True, right_index = True )
    #print full_df.head()

    #print prediction_dict
    fh.write_dict(fh.prediction_dict_file_path,prediction_dict)
    for game_name in sch_game_dicts.keys():
        try:
#        if game_name in full_df.colnames(full_df):
            full_df[game_name] = full_df[game_name]/n
        except:
            pass

    #print full_df.columns.values.tolist()   
    return full_df, prediction_dict
示例#2
0
    def create_bet_list(self,df):
        CandP = CombosAndPermuts()
        #print df.head()
        #print df.shape
        self.bet_dict = self.top_df
        #print self.bet_dict.head()
        #print 'nn', self.top_df['predicted_prob']['ma-07-01-1998_sch_Milford_12']
        #print df['ma-07-01-1998_sch_Milford_12'][df['First'] == 1] 
        for game in self.game_list:
            for n in range(1, self.numPlayers + 1):
                self.bet_dict.loc[game +'_' + 'win'+ '_' + str(n), 'predicted_prob'] = sum(df[game][df['First'] == n])
#                print self.bet_dict.loc[game +'_' + 'win'+ '_' + str(n)]
                self.bet_dict.loc[game +'_' + 'place'+ '_' + str(n), 'predicted_prob'] = (sum(df[game][df['First'] == n]) + sum(df[game][df['Second'] == n]))/2
                self.bet_dict.loc[game +'_' + 'show'+ '_' + str(n), 'predicted_prob'] = (sum(df[game][df['First'] == n]) + sum(df[game][df['Second'] == n]) + sum(df[game][df['Third'] == n]))/3
                
                
                self.bet_dict.loc[game + '_' + 'win' +'_' + str(n), 'predicted_return'] = (self.bet_dict.loc[game + '_' + 'win' +'_' + str(n), 'predicted_prob'] * self.bet_dict.loc[game + '_' + 'win' +'_' + str(n), 'avg_dollar_return']) - 1
                if self.bet_dict.loc[game + '_' + 'win' +'_' + str(n), 'predicted_return'] > self.WPS_THRESHOLD:
                    self.bet_dict.loc[game + '_' + 'win' +'_' + str(n), 'selected'] = 1  


                self.bet_dict.loc[game + '_' + 'place' +'_' + str(n), 'predicted_return'] = (self.bet_dict.loc[game + '_' + 'place' +'_' + str(n), 'predicted_prob'] * self.bet_dict.loc[game + '_' + 'place' +'_' + str(n), 'avg_dollar_return']) - 1
                if self.bet_dict.loc[game + '_' + 'place' +'_' + str(n), 'predicted_return'] > self.WPS_THRESHOLD:
                    self.bet_dict.loc[game + '_' + 'place' +'_' + str(n), 'selected'] = 1                         

            

                self.bet_dict.loc[game + '_' + 'show' +'_' + str(n), 'predicted_return'] = (self.bet_dict.loc[game + '_' + 'show' +'_' + str(n), 'predicted_prob'] * self.bet_dict.loc[game + '_' + 'show' +'_' + str(n), 'avg_dollar_return']) - 1
                if self.bet_dict.loc[game + '_' + 'show' +'_' + str(n), 'predicted_return'] > self.WPS_THRESHOLD:
                    self.bet_dict.loc[game + '_' + 'show' +'_' + str(n), 'selected'] = 1                         
                    
                    
            
            quinielas = CandP.get_quinielas([n for n in range(1,self.numPlayers +1)],2)
            for some_2_list in quinielas:
                quin = str(some_2_list[0]) + str(some_2_list[1])
                self.bet_dict.loc[game + '_'+ 'quiniela' + '_' + str(quin), 'predicted_prob'] = sum(df[df['First'] == some_2_list[0]][game][df[df['First'] == some_2_list[0]]['Second'] == some_2_list[1]]) + sum(df[df['First'] == some_2_list[1]][game][df[df['First'] == some_2_list[1]]['Second'] == some_2_list[0]]) 
                
                
                self.bet_dict.loc[game + '_' + 'quiniela' +'_' + str(quin), 'predicted_return'] = (self.bet_dict.loc[game + '_' + 'quiniela' +'_' + str(quin), 'predicted_prob'] * self.bet_dict.loc[game + '_' + 'quiniela' +'_' + str(quin), 'avg_dollar_return']) - 1
                if self.bet_dict.loc[game + '_' + 'quiniela' +'_' + str(quin), 'predicted_return'] > self.QUINIELA_THRESHOLD:
                    self.bet_dict.loc[game + '_' + 'quiniela' +'_' + str(quin), 'selected'] = 1                
                
                
                
                
                

            trifectas = CandP.get_trifectas([n for n in range(1,self.numPlayers +1)],3)
            for some_list_of_3 in trifectas:
                
                trif = str(some_list_of_3[0]) + str(some_list_of_3[1]) + str(some_list_of_3[2])
                self.bet_dict.loc[game + '_' + 'trifecta' +'_' + str(trif), 'predicted_prob'] = sum(df[game][df['First'] ==some_list_of_3[0]][df[df['First'] ==some_list_of_3[0]]['Second'] == some_list_of_3[1]][df[df['First'] ==some_list_of_3[0]][df[df['First'] ==some_list_of_3[0]]['Second'] == some_list_of_3[1]]['Third'] == some_list_of_3[2]]) 
                
                
                self.bet_dict.loc[game + '_' + 'trifecta' +'_' + str(trif), 'predicted_return'] = (self.bet_dict.loc[game + '_' + 'trifecta' +'_' + str(trif), 'predicted_prob'] * self.bet_dict.loc[game + '_' + 'trifecta' +'_' + str(trif), 'avg_dollar_return']) - 1
                if self.bet_dict.loc[game + '_' + 'trifecta' +'_' + str(trif), 'predicted_return'] > self.TRIFECTA_THRESHOLD:
                    self.bet_dict.loc[game + '_' + 'trifecta' +'_' + str(trif), 'selected'] = 1
                    
            
            exactas = CandP.get_exactas()
            for some_2_list_ in exactas:
                exac = str(some_2_list_[0]) + str(some_2_list_[1])
                self.bet_dict.loc[game + '_' + 'exacta' +'_' + str(exac), 'predicted_prob'] = sum(df[df['First'] == some_2_list_[0]][game][df[df['First'] == some_2_list_[0]]['Second'] == some_2_list_[1]])
                self.bet_dict.loc[game + '_' + 'exacta' +'_' + str(exac), 'predicted_return'] = (self.bet_dict.loc[game + '_' + 'exacta' +'_' + str(exac), 'predicted_prob'] * self.bet_dict.loc[game + '_' + 'exacta' +'_' + str(exac), 'avg_dollar_return']) - 1
                if self.bet_dict.loc[game + '_' + 'exacta' +'_' + str(exac), 'predicted_return'] > self.EXACTA_THRESHOLD:
                    self.bet_dict.loc[game + '_' + 'exacta' +'_' + str(exac), 'selected'] = 1