예제 #1
0
def best_combine_reduit_interface(window, values, visible_combi_opt):
    match_list = []
    combi_boostee = []
    sport = values["SPORT_COMBI_OPT"][0]
    issues = ["1", "N", "2"] if sport and get_nb_outcomes(sport) == 3 else ["1", "2"]
    for i in range(visible_combi_opt):
        match_list.append(values["MATCH_COMBI_OPT_" + str(i)].split(" / ")[0])
        for j, issue in enumerate(issues):
            if values[issue + "_RES_COMBI_OPT_" + str(i)]:
                combi_boostee.append(j)
                break
    site_booste = values["SITE_COMBI_OPT"]
    mise_max = float(values["STAKE_COMBI_OPT"])
    cote_boostee = float(values["ODD_COMBI_OPT"])
    old_stdout = sys.stdout  # Memorize the default stdout stream
    sys.stdout = buffer = io.StringIO()
    best_combine_booste(match_list, combi_boostee, site_booste, mise_max, sport, cote_boostee)
    sys.stdout = old_stdout  # Put the old stream back in place
    what_was_printed = buffer.getvalue()
    match, date = infos(what_was_printed)
    window["MATCH_COMBI_OPT"].update(match)
    window["DATE_COMBI_OPT"].update(date)
    window["ODDS_COMBI_OPT"].update(visible=True)
    window["RESULT_COMBI_OPT"].update(stakes(what_was_printed), visible=True)
    window["TEXT_COMBI_OPT"].update(visible=True)
    for i, elem in enumerate(indicators(what_was_printed)):
        window["INDICATORS_COMBI_OPT" + str(i)].update(elem[0].capitalize(), visible=True)
        window["RESULTS_COMBI_OPT" + str(i)].update(elem[1], visible=True)
    buffer.close()
    sb.ODDS_INTERFACE = what_was_printed
예제 #2
0
def best_match_under_conditions2(site,
                                 minimum_odd,
                                 stake,
                                 sport="football",
                                 date_max=None,
                                 time_max=None,
                                 date_min=None,
                                 time_min=None,
                                 miles=False,
                                 rate_eur_miles=0,
                                 multiplicator=1):
    all_odds = filter_dict_dates(sb.ODDS[sport], date_max, time_max, date_min,
                                 time_min)
    best_profit = -float("inf")
    best_match = None
    sites = None
    nb_matches = len(all_odds)
    n = get_nb_outcomes(sport)
    for match in all_odds:
        sb.PROGRESS += 100 / nb_matches
        if site in all_odds[match]['odds']:
            odds_site = all_odds[match]['odds'][site]
            best_odds = copy.deepcopy(odds_site)
            best_sites = [site for _ in range(n)]
            for odds in all_odds[match]['odds'].items():
                for i in range(n):
                    if odds[1][i] > best_odds[i] and (odds[1][i] >= 1.1
                                                      or odds[0] == "pmu"):
                        best_odds[i] = odds[1][i]
                        best_sites[i] = odds[0]
            for odd_i, site_i in zip(best_odds, best_sites):
                if odd_i < 1.1 and site_i != "pmu":
                    break
            else:
                profit = gain3(odds_site, best_odds, stake, minimum_odd, miles,
                               rate_eur_miles, multiplicator)
                if profit > best_profit:
                    best_profit = profit
                    best_odds_site = copy.deepcopy(odds_site)
                    best_best_odds = copy.deepcopy(best_odds)
                    best_match = match
                    stakes, best_indices = mises3(odds_site, best_odds, stake,
                                                  minimum_odd, False, miles,
                                                  rate_eur_miles,
                                                  multiplicator)
                    sites = [
                        site if i in best_indices else best_sites[i]
                        for i in range(n)
                    ]
    if best_match:
        print(best_match)
        pprint(all_odds[best_match])
        mises3(best_odds_site, best_best_odds, stake, minimum_odd, True, miles,
               rate_eur_miles, multiplicator)
        afficher_mises_combine([best_match], [sites], [stakes],
                               all_odds[best_match]["odds"], sport)
    else:
        print("No match found")
예제 #3
0
def compute_odds(window, values):
    try:
        sport = values["SPORT_ODDS"][0]
        stake = float(values["STAKE_ODDS"])
        match = values["MATCHES_ODDS"][0]
        _, bookmakers, best_odds = trj_match(sb.ODDS[sport][match])
    except (ValueError, IndexError) as _:
        return
    if values["OUTCOME_ODDS_SPLIT_STAKE"]:
        old_stdout = sys.stdout  # Memorize the default stdout stream
        sys.stdout = buffer = io.StringIO()
        mises(best_odds, stake, True)
        sys.stdout = old_stdout  # Put the old stream back in place
        what_was_printed = buffer.getvalue()
        profit = float(what_was_printed.split("\n")[4].split(' = ')[1])
        stakes = eval(what_was_printed.split("\n")[5].split(' = ')[1])
    else:
        outcomes = ["1", "2"]
        if get_nb_outcomes(sport) == 3:
            outcomes.insert(1, "N")
        outcome = 0
        for i, outcome_i in enumerate(outcomes):
            if values["OUTCOME_ODDS_"+outcome_i]:
                outcome = i
                break
        old_stdout = sys.stdout  # Memorize the default stdout stream
        sys.stdout = buffer = io.StringIO()
        mises2(best_odds, stake, outcome, True)
        sys.stdout = old_stdout  # Put the old stream back in place
        what_was_printed = buffer.getvalue()
        profit = float(what_was_printed.split("\n")[5].split(' = ')[1])
        stakes = eval(what_was_printed.split("\n")[6].split(' = ')[1])
    teams = match.split(" - ")
    if get_nb_outcomes(sport) == 3:
        teams.insert(1, "Nul")
    totals = [round(stake_i * odd_i, 2) for stake_i, odd_i in zip(stakes, best_odds)]
    table = {"Issue": teams, "Bookmaker": bookmakers, "Cote": best_odds, "Mise": stakes, "Total": totals}
    text = tabulate.tabulate(table, headers='keys', tablefmt='fancy_grid')
    window["RESULT_ODDS"].update(text + "\nPlus-value : {}".format(profit), visible=True)
    if sys.platform.startswith("win"):
        copy_to_clipboard(text)
예제 #4
0
def convert_indices_to_opponents(combination_indices, matches, sport):
    combination_opponents = []
    matches_outcomes = [match.split(" - ") for match in matches]
    if get_nb_outcomes(sport) == 3:
        for match in matches_outcomes:
            match.insert(1, "Nul")
    for indices in combination_indices:
        opponents = []
        for i, index in enumerate(indices):
            if index == float("inf"):
                continue
            opponents.append(matches_outcomes[i][index])
        combination_opponents.append(tuple(opponents))
    return combination_opponents
예제 #5
0
def best_match_pari_gagnant(site,
                            minimum_odd,
                            bet,
                            sport="football",
                            date_max=None,
                            time_max=None,
                            date_min=None,
                            time_min=None,
                            nb_matches_combine=1):
    """
    Retourne le meilleur match sur lequel miser lorsqu'on doit gagner un pari à
    une cote donnée sur un site donné.
    """
    stakes = []
    n = get_nb_outcomes(sport)
    for _ in range(n**nb_matches_combine):
        stakes.append([bet, site, minimum_odd])
    best_match_stakes_to_bet(stakes, nb_matches_combine, sport, date_max,
                             time_max, True)
예제 #6
0
def best_matches_freebet2(site, freebet, sport, nb_matches=2):
    #     all_odds = sb.ODDS[sport]
    all_odds = get_matches_with_best_trj(sport, 10)
    best_profit = float("-inf")
    combis = list(combinations(all_odds.items(), nb_matches))
    nb_combis = len(combis)
    best_combine = None
    best_bets = None
    choices = list(
        product(*[range(get_nb_outcomes(sport)) for _ in range(nb_matches)]))
    for combi in combis:
        if any([site not in x[1]["odds"] for x in combi]):
            continue
        matches = [x[0] for x in combi]
        for choice in choices:
            choice_list = list(choice)
            odd = 1
            for match, outcome in zip(combi, choice_list):
                odd *= match[1]["odds"][site][outcome]
            profit = best_combine_reduit(matches,
                                         choice_list,
                                         site,
                                         freebet,
                                         sport,
                                         odd - 1,
                                         output=False)
            if profit < best_profit:
                continue
            best_profit = profit
            best_matches = matches
            best_choice = choice_list
            best_odd = odd
    best_combine_reduit(best_matches,
                        best_choice,
                        site,
                        freebet,
                        sport,
                        best_odd - 1,
                        freebet=True)
         window['MATCHES_ODDS'].update(values=[])
 elif event == "MATCHES_ODDS":
     odds_match_interface(window, values)
 elif event == "DELETE_SITE_ODDS":
     delete_site_interface(window, values)
     save_odds(sb.ODDS, PATH_DATA)
 elif event == "DELETE_MATCH_ODDS":
     delete_odds_interface(window, values)
     save_odds(sb.ODDS, PATH_DATA)
 elif event == "ADD_COMBI_OPT":
     sport = ""
     if values["SPORT_COMBI_OPT"]:
         sport = values["SPORT_COMBI_OPT"][0]
     if visible_combi_opt < 9:
         window["MATCH_COMBI_OPT_" + str(visible_combi_opt)].update(visible=True)
         issues = ["1", "N", "2"] if sport and get_nb_outcomes(sport) == 3 else ["1", "2"]
         for issue in issues:
             window[issue+"_RES_COMBI_OPT_" + str(visible_combi_opt)].update(visible=True)
         visible_combi_opt += 1
 elif event == "REMOVE_COMBI_OPT":
     if visible_combi_opt > 1:
         visible_combi_opt -= 1
         window["MATCH_COMBI_OPT_" + str(visible_combi_opt)].update(visible=False)
         for issue in ["1", "N", "2"]:
             window[issue+"_RES_COMBI_OPT_" + str(visible_combi_opt)].update(visible=False)
 elif event == "BEST_COMBI_OPT":
     best_combine_reduit_interface(window, values, visible_combi_opt)
 elif event == "SPORT_COMBI_OPT":
     sport = values["SPORT_COMBI_OPT"][0]
     for i in range(visible_combi_opt):
         if get_nb_outcomes(sport) == 2:
예제 #8
0
def best_match_stakes_to_bet(stakes,
                             nb_matches=1,
                             sport="football",
                             date_max=None,
                             time_max=None,
                             identical_stakes=False):
    second_sites = {stake[1] for stake in stakes}
    main_sites = sb.BOOKMAKERS
    all_odds = filter_dict_dates(sb.ODDS[sport], date_max, time_max)
    best_profit = -sum(stake[0] for stake in stakes)
    n = get_nb_outcomes(sport)**nb_matches
    nb_stakes = len(stakes)
    all_odds_combine = {}
    combis = list(combinations(all_odds.items(), nb_matches))
    nb_combis = len(combis)
    best_combine = None
    best_bets = None
    main_site_odds = []
    main_sites_distribution = []
    sb.PROGRESS = 0
    for i, combine in enumerate(combis):
        sb.PROGRESS += 100 / nb_combis
        match_combine = " / ".join([match[0] for match in combine])
        all_odds_combine[match_combine] = cotes_combine_all_sites(
            *[match[1] for match in combine])
        for main0 in main_sites:
            try:
                main_sites_distribution = [main0 for _ in range(n)]
                main_site_odds = copy.deepcopy(
                    all_odds_combine[match_combine]["odds"][main0])
                break
            except KeyError:
                pass
        for main in main_sites[:i] + main_sites[i + 1:]:
            try:
                potential_odds = all_odds_combine[match_combine]["odds"][main]
                for j, odd in enumerate(potential_odds):
                    if odd > main_site_odds[j]:
                        main_site_odds[j] = odd
                        main_sites_distribution[j] = main
            except KeyError:
                pass
        second_odds = {
            second_site: all_odds_combine[match_combine]["odds"][second_site]
            for second_site in second_sites
            if second_site in all_odds_combine[match_combine]["odds"]
        }
        if not second_odds:
            continue
        dict_combine_odds = copy.deepcopy(second_odds)
        for perm in permutations(range(n), nb_stakes):
            valid_perm = True
            defined_second_sites = [[perm[j], stake[0], stake[1]]
                                    for j, stake in enumerate(stakes)]
            for j, stake in enumerate(stakes):
                if dict_combine_odds[defined_second_sites[j][2]][
                        defined_second_sites[j][0]] < stake[2]:
                    valid_perm = False
                    break
            if not valid_perm:
                if identical_stakes:
                    break
                continue
            defined_bets_temp = defined_bets(main_site_odds, dict_combine_odds,
                                             main_sites_distribution,
                                             defined_second_sites)
            profit = defined_bets_temp[0] - np.sum(defined_bets_temp[1])
            if profit > best_profit:
                best_profit = profit
                best_combine = combine
                best_bets = defined_bets_temp
            if identical_stakes:
                break
    if best_combine:
        best_match_combine = " / ".join([match[0] for match in best_combine])
        odds_best_match = copy.deepcopy(all_odds_combine[best_match_combine])
        all_sites = main_sites + list(second_sites)
        for site in all_odds_combine[best_match_combine]["odds"]:
            if site not in all_sites:
                del odds_best_match["odds"][site]
        print(best_match_combine)
        pprint(odds_best_match, compact=1)
        print("Plus-value =", round(best_profit, 2))
        print("Gain référence =", round(best_bets[0], 2))
        print("Somme des mises =", round(np.sum(best_bets[1]), 2))
        afficher_mises_combine([x[0] for x in best_combine], best_bets[2],
                               best_bets[1],
                               all_odds_combine[best_match_combine]["odds"],
                               sport)
    else:
        print("No match found")