Esempio n. 1
0
def get_roster_list():
    """
    Tested
    Accepts a top level data directory
    If the roster list does not exist for the top level data directory
    it is created, otherwise it is just returned from a file location
    Returns a list of lists with each player, and 2 player team in a list :
    [['player1'],['player2','player3'], ....]    
    """
    fh.set_up_paths(DATA_DIR)
    roster_list = []
    temp_list = []
    fin_list = []
    if fh.file_exists(fh.roster_list_file):
        roster_list = fh.file_to_list(fh.roster_list_file)
        for l in roster_list:
            #print l
            temp_list.append(l)
        for ll in temp_list:
#            print 'll : '+ str(ll),
#            print ll.split(':')
            roster_list.append(ll.split(':'))
        ret_roster_list = dp.get_names_from_list(roster_list)
        for name in ret_roster_list:
            if name not in roster_list:
                fin_list.append(name)
    else:
        fin_list = create_roster_list()
        fh.write_list_of_lists_file(fin_list, fh.roster_list_file)
#    print fin_list
    return fin_list    
Esempio n. 2
0
def get_pos_freq_actuals(prediction_dict, res_games_dict):
    # To create the results vector - copy the prediction vector and set everything to 0
    if fh.file_exists(fh.prediction_actual_results_dict_file_path) == False:    
    
        res_freq_dict = prediction_dict.copy()
        #print prediction_dict
        for k,v in res_freq_dict.items():
            for k1 in v.keys():
                #print k1, v[k1]
                v[k1] = 0
        #print res_freq_dict
        for game_name, game_data in prediction_dict.items():
            #game_player_list = [game_data[x].keys() for x in range(len(game_data))]
            res_dict = res_games_dict.get(game_name.replace("sch", "res"))
            #print res_dict
            if res_dict != None:
                top_1 = res_dict['WIN'][0]
                top_2 = res_dict['PLACE'][0]
                top_3 = res_dict['SHOW'][0]
                top_123 = str(top_1) + str(top_2) + str(top_3)
                res_freq_dict[game_name][top_123] += 1
                #res_dict[top_123] += 1
        #print res_freq_dict
        fh.write_dict(fh.prediction_actual_results_dict_file_path,res_freq_dict)
        return res_freq_dict
    else:
        pass
Esempio n. 3
0
def get_player_season_records():
    """
    If the player season record does not exist for the top level data directory
    it is created, otherwise it is just returned from a file location
    Returns a dictionary of dictionaries for the player season record in the form:
    {eggy:richard [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 3]]} called all_player_season_records
    """
    fh.set_up_paths(DATA_DIR)
    all_player_season_records = {}
    if fh.file_exists(fh.player_season_records_file_path):
        all_player_season_records = fh.read_dict(fh.player_season_records_file_path)
    else:
        all_player_season_records = create_player_season_records()
        fh.write_dict(fh.player_season_records_file_path,all_player_season_records)
#    print fin_list
    return all_player_season_records  
Esempio n. 4
0
def rem_pwin(some_dir):
    file_path = os.path.join(some_dir,'pwin_dict.txt')
    if fh.file_exists(file_path):
        os.unlink(file_path)
Esempio n. 5
0
def run_experiment():
    """

    """
    start_time = time.time()
    replicates = 5
    #gamma_range = [0.2,0.4,0.6,0.8,1.0,1.2]
    gamma_range = [0.6]
    serve_adv_range = [-0.05]    
    n = 100000
    WPS_THRESHOLD = 0.3
    TRIFECTA_THRESHOLD = 1
    QUINIELA_THRESHOLD = 1
    EXACTA_THRESHOLD = 1
    rds.PWIN_DICT_POINTS_PLAYED_THRESHOLD = 140
    
    
    start_time = time.time()
    #ilf = 0
    experiment_dict = {}
    logging.info('starting at %s', (time.time() - start_time)/60)    
    fh.set_up_paths(DATA_DIR)
       


    
    rds.DATA_DIR = DATA_DIR

    logging.info('run_data_setup() at %s', (time.time() - start_time)/60)    
    for replicate in range(1,replicates+1):
        logging.info('Replicate : %s at %s', replicate, (time.time() - start_time)/60)
        for gamma in gamma_range:
            logging.info('gamma : %s at %s', gamma, (time.time() - start_time)/60)    
            psp.gamma = gamma
            for serve_adv in serve_adv_range:
                if fh.file_exists(fh.prediction_actual_results_dict_file_path):
                    os.remove(fh.prediction_actual_results_dict_file_path)
#                if fh.file_exists(fh.pwin_dict_file_path):
#                    os.remove(fh.pwin_dict_file_path) 
                logging.info('removing files at %s', (time.time() - start_time)/60) 
                rds.run_data_setup()
                logging.info('run_data_setup at %s', (time.time() - start_time)/60)                 
                
                
                logging.info('serve adv : %s at %s', serve_adv, (time.time() - start_time)/60)                
                run_dict = {}
                psp.doublesServerAdvantage = serve_adv
                sch_game_dicts = set_up_sch_game_dicts(DATA_DIR)
                logging.info('set_up_sch_game_dicts complete at %s', (time.time() - start_time)/60) 
                res_game_dicts = set_up_res_games_dicts(DATA_DIR, sch_game_dicts)
                
                #sch_game_dicts, res_game_dicts = remove_know_sub_games(sch_game_dicts, res_game_dicts)
    
    
                wps_prob_table, prediction_dict = sim_scheduled_games(sch_game_dicts, n)
                logging.info('serve adv : sim_scheduled_games complete at %s',(time.time() - start_time)/60)                 
                bet_table = BetTable(wps_prob_table)
                bet_table.WPS_THRESHOLD = WPS_THRESHOLD
                bet_table.EXACTA_THRESHOLD = EXACTA_THRESHOLD
                bet_table.QUINIELA_THRESHOLD = QUINIELA_THRESHOLD
                bet_table.TRIFECTA_THRESHOLD = TRIFECTA_THRESHOLD
                bet_table.create_bet_list(wps_prob_table)
                logging.info('serve adv : bet_table.create_bet_list complete at %s',(time.time() - start_time)/60)               
                
                get_pos_freq_actuals(prediction_dict, res_game_dicts) 
                logging.info('get_pos_freq_actuals complete at %s',(time.time() - start_time)/60)    
                
                my_stakes, my_gross_return, my_return = bet_table.get_returns(prediction_dict, res_game_dicts)
    
                #qlf,ilf = calculate_quadratic_loss_function()
                #ilf = calculate_ilf(n)
                run_dict['rds.PWIN_DICT_POINTS_PLAYED_THRESHOLD'] = rds.PWIN_DICT_POINTS_PLAYED_THRESHOLD
                run_dict['rds.DATA_DIR'] = rds.DATA_DIR
                run_dict['DATA_DIR'] = DATA_DIR
                run_dict['n'] = n   
                run_dict['psp.doublesServerAdvantage'] = psp.doublesServerAdvantage
                run_dict['psp.gamma'] = psp.gamma
                #run_dict['ilf'] = ilf
                #run_dict['qlf'] = qlf
                run_dict['my_stakes'] = my_stakes ; run_dict['my_gross_return'] = my_gross_return
                run_dict['replicate'] = replicate
                run_dict['my_return'] = my_return
                run_dict['WPS_THRESHOLD'] = bet_table.WPS_THRESHOLD
                run_dict['EXACTA_THRESHOLD'] = bet_table.EXACTA_THRESHOLD
                run_dict['QUINIELA_THRESHOLD'] = bet_table.QUINIELA_THRESHOLD
                run_dict['TRIFECTA_THRESHOLD'] = bet_table.TRIFECTA_THRESHOLD
                experiment_dict[str(psp.gamma) + '_' + str(psp.doublesServerAdvantage)+ '_' + str(replicate)] = run_dict
                print
                for k,v in run_dict.items():
                    print k, v
                print 'out ', run_dict['my_stakes']
                print 'in ' , run_dict['my_gross_return']
                print 'NET : ' , run_dict['my_return']
                logging.info('instance completed at %s', (time.time() - start_time)/60)             
    fh.write_dict(fh.experiment_results_file_path,experiment_dict)
#    for k, v in experiment_dict.items():
##        print
#        print k,v['psp.gamma'],v['psp.doublesServerAdvantage'],v['qlf']
    num_trials = len(experiment_dict.keys())
#    print
    print "To complete %.0f replicates of %.0f runs took %.2f minutes at n = %.0f over %.0f games" %(replicates, num_trials,(time.time() - start_time)/60,n, len(prediction_dict))