Example #1
0
def best_matches_combine_cashback_une_selection_perdante(site, cote_minimale_selection, combi_max=0,
                                                         nb_matches=2, date_max=None, time_max=None,
                                                         date_min=None, time_min=None):
    """
    Calcule la meilleure combinaison de matches et les mises à jouer pour une promotion du type
    "Combiné remboursé si une seule selection perdante, sans limite du nombre de paris remboursés"
    """
    sport = "football"
    bet = 10000
    all_odds = sportsbetting.ODDS[sport]
    sportsbetting.ALL_ODDS_COMBINE = {}
    for combine in combinations(all_odds.items(), nb_matches):
        try:
            if all([odd >= cote_minimale_selection for odds in list(all_odds[match[0]]["odds"][site]
                                                                    for match in combine)
                    for odd in odds]):
                (sportsbetting
                    .ALL_ODDS_COMBINE[" / "
                    .join([match[0]
                           for match
                           in combine])]) = cotes_combine_all_sites(*[match[1]
                                                                      for match
                                                                      in combine])
        except KeyError:
            pass
    odds_function = lambda best_odds, odds_site, i: list(
        map(lambda x: x * (1 + combi_max) - combi_max,
            odds_site))
    profit_function = lambda odds_to_check, i: gain(odds_to_check, bet) - bet
    criteria = lambda odds_to_check, i: (odds_to_check[i] + combi_max) / (1 + combi_max) >= 1.1
    display_function = lambda x, i: mises(x, bet, True)
    return_function = lambda x, i: mises(x, bet, False)
    best_match_base(odds_function, profit_function, criteria, display_function,
                    return_function, site, sport, date_max, time_max, date_min,
                    time_min, True, nb_matches, one_site=True, recalcul=True)
def best_matches_combine(site,
                         minimum_odd,
                         bet,
                         sport="football",
                         nb_matches=2,
                         one_site=False,
                         date_max=None,
                         time_max=None,
                         date_min=None,
                         time_min=None,
                         minimum_odd_selection=1.01):
    """
    Retourne les meilleurs matches sur lesquels miser lorsqu'on doit miser une somme
    donnée à une cote donnée sur un combiné
    """
    all_odds = filter_dict_dates(sportsbetting.ODDS[sport], date_max, time_max,
                                 date_min, time_min)
    all_odds = filter_dict_minimum_odd(all_odds, minimum_odd_selection, site)
    sportsbetting.ALL_ODDS_COMBINE = {}
    nb_combine = binomial(len(all_odds), nb_matches)
    sportsbetting.PROGRESS = 0

    def compute_all_odds_combine(nb_combine, combine):
        sportsbetting.PROGRESS += 100 / nb_combine
        try:
            sportsbetting.ALL_ODDS_COMBINE[" / ".join([
                match[0] for match in combine
            ])] = cotes_combine_all_sites(*[match[1] for match in combine])
        except KeyError:
            pass

    ThreadPool(4).map(lambda x: compute_all_odds_combine(nb_combine, x),
                      combinations(all_odds.items(), nb_matches))
    sportsbetting.PROGRESS = 0
    odds_function = get_best_odds(one_site)
    profit_function = get_profit(bet, one_site)
    criteria = lambda odds_to_check, i: (
        (not one_site and odds_to_check[i] >= minimum_odd) or
        (one_site and all(odd >= minimum_odd for odd in odds_to_check)))
    display_function = lambda best_overall_odds, best_rank: (
        mises2(best_overall_odds, bet, best_rank, True)
        if not one_site else mises(best_overall_odds, bet, True))
    result_function = lambda best_overall_odds, best_rank: (
        mises2(best_overall_odds, bet, best_rank, False)
        if not one_site else mises(best_overall_odds, bet, False))
    best_match_base(odds_function,
                    profit_function,
                    criteria,
                    display_function,
                    result_function,
                    site,
                    sport,
                    date_max,
                    time_max,
                    date_min,
                    time_min,
                    True,
                    nb_matches,
                    one_site=one_site,
                    combine_opt=True)
Example #3
0
def best_match_under_conditions(site, minimum_odd, bet, sport="football", date_max=None,
                                time_max=None, date_min=None, time_min=None, one_site=False,
                                live=False):
    """
    Retourne le meilleur match sur lequel miser lorsqu'on doit miser une somme
    donnée à une cote donnée. Cette somme peut-être sur seulement une issue
    (one_site=False) ou bien répartie sur plusieurs issues d'un même match
    (one_site=True), auquel cas, chacune des cotes du match doivent respecter le
    critère de cote minimale.
    """
    odds_function = lambda best_odds, odds_site, i: ((best_odds[:i]
                                                      + [odds_site[i] * 0.9 if live else odds_site[
                i]]
                                                      + best_odds[i + 1:]) if not one_site
                                                     else (odds_site[:i]
                                                           + [odds_site[i] * 0.9 if live
                                                              else odds_site[i]]
                                                           + odds_site[i + 1:]))
    profit_function = lambda odds_to_check, i: (gain(odds_to_check, bet) - bet if one_site
                                                else gain2(odds_to_check, i, bet))
    criteria = lambda odds_to_check, i: ((not one_site and odds_to_check[i] >= minimum_odd)
                                         or (one_site and all(odd >= minimum_odd
                                                              for odd in odds_to_check)))
    display_function = lambda best_overall_odds, best_rank: (mises2(best_overall_odds, bet,
                                                                    best_rank, True) if not one_site
                                                             else mises(best_overall_odds, bet,
                                                                        True))
    result_function = lambda best_overall_odds, best_rank: (mises2(best_overall_odds, bet,
                                                                   best_rank, False) if not one_site
                                                            else mises(best_overall_odds, bet,
                                                                       False))
    best_match_base(odds_function, profit_function, criteria, display_function,
                    result_function, site, sport, date_max, time_max, date_min,
                    time_min, one_site=one_site)
Example #4
0
def best_matches_combine(site,
                         minimum_odd,
                         bet,
                         sport="football",
                         nb_matches=2,
                         one_site=False,
                         date_max=None,
                         time_max=None,
                         date_min=None,
                         time_min=None,
                         minimum_odd_selection=1.01):
    """
    Retourne les meilleurs matches sur lesquels miser lorsqu'on doit miser une somme
    donnée à une cote donnée sur un combiné
    """
    all_odds = filter_dict_dates(sportsbetting.ODDS[sport], date_max, time_max,
                                 date_min, time_min)
    sportsbetting.ALL_ODDS_COMBINE = {}
    for combine in combinations(all_odds.items(), nb_matches):
        try:
            if all([
                    odd >= minimum_odd_selection for odds in list(
                        all_odds[match[0]]["odds"][site] for match in combine)
                    for odd in odds
            ]):
                (sportsbetting.ALL_ODDS_COMBINE[" / ".join([
                    match[0] for match in combine
                ])]) = cotes_combine_all_sites(
                    *[match[1] for match in combine])
        except KeyError:
            pass
    odds_function = lambda best_odds, odds_site, i: (
        (best_odds[:i] + [odds_site[i]] + best_odds[i + 1:])
        if not one_site else odds_site)
    profit_function = lambda odds_to_check, i: (gain(odds_to_check, bet) - bet
                                                if one_site else gain2(
                                                    odds_to_check, i, bet))
    criteria = lambda odds_to_check, i: (
        (not one_site and odds_to_check[i] >= minimum_odd) or
        (one_site and all(odd >= minimum_odd for odd in odds_to_check)))
    display_function = lambda best_overall_odds, best_rank: (
        mises2(best_overall_odds, bet, best_rank, True)
        if not one_site else mises(best_overall_odds, bet, True))
    result_function = lambda best_overall_odds, best_rank: (
        mises2(best_overall_odds, bet, best_rank, False)
        if not one_site else mises(best_overall_odds, bet, False))
    best_match_base(odds_function,
                    profit_function,
                    criteria,
                    display_function,
                    result_function,
                    site,
                    sport,
                    date_max,
                    time_max,
                    date_min,
                    time_min,
                    True,
                    nb_matches,
                    one_site=one_site)
def best_matches_freebet_one_site(site,
                                  freebet,
                                  sport="football",
                                  nb_matches=2,
                                  minimum_odd=1.1,
                                  date_max=None,
                                  time_max=None,
                                  date_min=None,
                                  time_min=None):
    """
    Calcule la répartition des paris gratuits sur un unique site
    """
    all_odds = sportsbetting.ODDS[sport]
    sportsbetting.ALL_ODDS_COMBINE = {}
    for combine in combinations(all_odds.items(), nb_matches):
        (sportsbetting.ALL_ODDS_COMBINE[" / ".join([
            match[0] for match in combine
        ])]) = cotes_combine_all_sites(*[match[1] for match in combine])
    odds_function = lambda best_odds, odds_site, i: cotes_freebet(odds_site)
    profit_function = lambda odds_to_check, i: gain(odds_to_check, freebet
                                                    ) - freebet
    criteria = lambda odds_to_check, i: all(odd >= minimum_odd
                                            for odd in odds_to_check)
    display_function = lambda best_overall_odds, best_rank: mises(
        best_overall_odds, freebet, True)
    result_function = lambda best_overall_odds, best_rank: mises(
        best_overall_odds, freebet, False)
    best_match_base(odds_function,
                    profit_function,
                    criteria,
                    display_function,
                    result_function,
                    site,
                    sport,
                    date_max,
                    time_max,
                    date_min,
                    time_min,
                    True,
                    nb_matches,
                    True,
                    one_site=True)
Example #6
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)
def best_match_base(odds_function,
                    profit_function,
                    criteria,
                    display_function,
                    result_function,
                    site,
                    sport="football",
                    date_max=None,
                    time_max=None,
                    date_min=None,
                    time_min=None,
                    combine=False,
                    nb_matches_combine=2,
                    freebet=False,
                    one_site=False,
                    recalcul=False,
                    combine_opt=False):
    """
    Fonction de base de détermination du meilleur match sur lequel parier en
    fonction de critères donnés
    """
    try:
        if combine:
            all_odds = filter_dict_dates(sportsbetting.ALL_ODDS_COMBINE,
                                         date_max, time_max, date_min,
                                         time_min)
        else:
            all_odds = filter_dict_dates(sportsbetting.ODDS[sport], date_max,
                                         time_max, date_min, time_min)
    except NameError:
        print("""
        Merci de définir les côtes de base, appelez la fonction parse_football,
        parse_nba ou parse_tennis selon vos besoins""")
        return
    best_profit = -float("inf")
    best_rank = 0
    if combine:
        n = (2 + (sport not in ["tennis", "volleyball", "basketball", "nba"
                                ]))**nb_matches_combine
    else:
        n = 2 + (sport not in ["tennis", "volleyball", "basketball", "nba"])
    best_match = None
    best_overall_odds = None
    sites = None
    for match in all_odds:
        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)]
            if not one_site:
                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:
                for i in range(n):
                    try:
                        odds_to_check = odds_function(best_odds, odds_site, i)
                        if criteria(odds_to_check, i):
                            profit = profit_function(odds_to_check, i)
                            if profit > best_profit:
                                best_rank = i
                                best_profit = profit
                                best_match = match
                                best_overall_odds = odds_to_check
                                sites = best_sites[:i] + [
                                    site
                                ] + best_sites[i + 1:]
                    except ZeroDivisionError:  # Si calcul freebet avec cote de 1
                        pass
    if best_match:
        if combine_opt and combine:
            ref_combinaison = list(
                reversed(baseconvert.base(best_rank, 10,
                                          get_nb_issues(sport))))
            n_combi = len(ref_combinaison)
            for _ in range(nb_matches_combine - n_combi):
                ref_combinaison.append(0)
            stakes = result_function(best_overall_odds, best_rank)
            best_combine_reduit(best_match.split(" / "),
                                list(reversed(ref_combinaison)), site,
                                stakes[best_rank], sport)
        else:
            print(best_match)
            pprint(all_odds[best_match], compact=True)
            if recalcul:
                sum_almost_won = find_almost_won_matches(
                    best_match, result_function(best_overall_odds, best_rank),
                    sport)
                display_function = lambda x, y: mises(
                    x, 10000 * 50 / sum_almost_won, True)
                result_function = lambda x, y: mises(
                    x, 10000 * 50 / sum_almost_won, False)
                find_almost_won_matches(
                    best_match, result_function(best_overall_odds, best_rank),
                    sport, True)
            second_rank = display_function(best_overall_odds, best_rank)
            afficher_mises_combine(
                best_match.split(" / "), [sites],
                [result_function(best_overall_odds, best_rank)],
                all_odds[best_match]["odds"], sport,
                best_rank if freebet else None, one_site and freebet,
                best_overall_odds, second_rank)
    else:
        print("No match found")
Example #8
0
def best_match_base(odds_function,
                    profit_function,
                    criteria,
                    display_function,
                    result_function,
                    site,
                    sport="football",
                    date_max=None,
                    time_max=None,
                    date_min=None,
                    time_min=None,
                    combine=False,
                    nb_matches_combine=2,
                    freebet=False,
                    one_site=False,
                    recalcul=False):
    """
    Fonction de base de détermination du meilleur match sur lequel parier en
    fonction de critères donnés
    """
    try:
        if combine:
            all_odds = sportsbetting.ALL_ODDS_COMBINE
        else:
            all_odds = sportsbetting.ODDS[sport]
    except NameError:
        print("""
        Merci de définir les côtes de base, appelez la fonction parse_football,
        parse_nba ou parse_tennis selon vos besoins""")
        return
    best_profit = -float("inf")
    best_rank = 0
    hour_max, minute_max = 0, 0
    hour_min, minute_min = 0, 0
    if combine:
        n = (2 + (sport not in ["tennis", "volleyball", "basketball", "nba"
                                ]))**nb_matches_combine
    else:
        n = 2 + (sport not in ["tennis", "volleyball", "basketball", "nba"])
    if time_max:
        if time_max[-1] == 'h':
            hour_max = int(time_max[:-1])
        else:
            hour_max, minute_max = (int(_) for _ in time_max.split('h'))
    if date_max:
        day_max, month_max, year_max = (int(_) for _ in date_max.split('/'))
        datetime_max = datetime.datetime(year_max, month_max, day_max,
                                         hour_max, minute_max)
    else:
        datetime_max = None
    if time_min:
        if time_min[-1] == 'h':
            hour_min = int(time_min[:-1])
        else:
            hour_min, minute_min = (int(_) for _ in time_min.split('h'))
    if date_min:
        day_min, month_min, year_min = (int(_) for _ in date_min.split('/'))
        datetime_min = datetime.datetime(year_min, month_min, day_min,
                                         hour_min, minute_min)
    else:
        datetime_min = None
    for match in all_odds:
        if (site in all_odds[match]['odds']
                and (not date_max or all_odds[match]['date'] <= datetime_max
                     or all_odds[match]['date'] == "undefined")
                and (not date_min or all_odds[match]['date'] >= datetime_min
                     or all_odds[match]['date'] == "undefined")):
            odds_site = all_odds[match]['odds'][site]
            best_odds = copy.deepcopy(odds_site)
            best_sites = [site for _ in range(n)]
            if not one_site:
                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:
                for i in range(n):
                    try:
                        odds_to_check = odds_function(best_odds, odds_site, i)
                        if criteria(odds_to_check, i):
                            profit = profit_function(odds_to_check, i)
                            if profit > best_profit:
                                best_rank = i
                                best_profit = profit
                                best_match = match
                                best_overall_odds = odds_to_check
                                sites = best_sites[:i] + [
                                    site
                                ] + best_sites[i + 1:]
                    except ZeroDivisionError:  #Si calcul freebet avec cote de 1
                        pass
    try:
        print(best_match)
        pprint(all_odds[best_match], compact=True)
        if recalcul:
            sum_almost_won = find_almost_won_matches(
                best_match, result_function(best_overall_odds, best_rank),
                sport)
            display_function = lambda x, i: mises(x, 10000 * 50 /
                                                  sum_almost_won, True)
            result_function = lambda x, i: mises(x, 10000 * 50 /
                                                 sum_almost_won, False)
            find_almost_won_matches(
                best_match, result_function(best_overall_odds, best_rank),
                sport, True)
        second_rank = display_function(best_overall_odds, best_rank)
        afficher_mises_combine(best_match.split(" / "), [sites],
                               [result_function(best_overall_odds, best_rank)],
                               all_odds[best_match]["odds"], sport,
                               best_rank if freebet else None, one_site
                               and freebet, best_overall_odds, second_rank)
    except UnboundLocalError:
        print("No match found")