Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2020 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of betbot.
6betbot is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11betbot is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with betbot. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from math import sqrt
21from typing import List, Tuple
22from betbot.api.Bet import Bet
23from betbot.api.Match import Match
24from betbot.data.OddsPortal import OddsPortal
25from betbot.prediction.Predictor import Predictor
28class BettingOddsPredictor(Predictor):
29 """
30 Class that determinalistically predicts matches based on Tipico quotes
31 """
33 @classmethod
34 def name(cls) -> str:
35 """
36 :return: The name of the predictor
37 """
38 return "betting-odds"
40 def predict(self, matches: List[Match]) -> List[Bet]:
41 """
42 Performs the prediction
43 :param matches: The matches to predict
44 :return: The predictions as Bet objects
45 """
46 bets = []
47 oddsportal = OddsPortal()
48 odds = oddsportal.get_odds(self.league)
49 for match in matches:
50 match_tuple = (match.home_team, match.away_team)
51 match_odds = odds.get(match_tuple)
52 if match_odds is None:
53 continue
54 home_score, away_score = self.generate_scores(*match_odds)
55 bets.append(Bet(match, home_score, away_score))
56 return bets
58 # noinspection PyMethodMayBeStatic
59 def generate_scores(
60 self,
61 home_odds: float,
62 draw_odds: float,
63 away_odds: float
64 ) -> Tuple[int, int]:
65 """
66 Generates a scoreline based on the quote data
67 :param home_odds: The odds that the home team wins
68 :param draw_odds: The odds that the match ends in a draw
69 :param away_odds: The odds that the away team wins
70 :return: The generated bet
71 """
72 winner = int(sqrt(abs(home_odds - away_odds) * 2))
73 loser = int(min(home_odds, away_odds) - 1)
75 if home_odds < away_odds:
76 home_score, away_score = winner, loser
77 else:
78 home_score, away_score = loser, winner
80 if draw_odds > home_odds and draw_odds > away_odds:
81 home_score += 1
82 away_score += 1
84 return home_score, away_score