class CustomPlayer(Player): def __init__(self, competition): super(CustomPlayer, self).__init__(competition, NAME) self.account = RecoverAccount(self.competition.user.account_manager) self.team = None self.event_id = None self.event_data = {} self.odd_id = 0 self.min_week = 2 self.shutdown_event.set() async def forecast(self): table = self.competition.table.table # type: List[Dict] self.team = table[0].get('team') league_games = self.competition.league_games # type: Dict[int, Dict] week_games = league_games.get(self.competition.week) # type: Dict[int, Dict] for event_id, event_data in week_games.items(): player_a = event_data.get('A') player_b = event_data.get('B') if player_a == self.team or player_b == self.team: self.event_id = event_id self.event_data = event_data if player_a == self.team: self.odd_id = 0 else: self.odd_id = 1 self._bet = True break else: continue odds = self.event_data.get('odds') participants = self.event_data.get('participants') ticket = Ticket(self.competition.game_id, self.name) event = Event(self.event_id, self.competition.league, self.competition.week, participants) market_id, odd_name, odd_index = Player.get_market_info(str(self.odd_id)) odd_value = float(odds[odd_index]) if odd_value < 1.02: return [] stake = self.account.normalize_stake(5) bet = Bet(self.odd_id, market_id, odd_value, odd_name, stake) event.add_bet(bet) win = round(stake * odd_value, 2) min_win = win max_win = win logger.info(f'[{self.competition.user.username}:{self.competition.game_id}] {self.name} ' f'{event.get_formatted_participants()}[{self.odd_id} : {odd_value}]') ticket.add_event(event) ticket.stake = stake ticket.min_winning = min_win ticket.max_winning = max_win ticket.total_won = 0 ticket.grouping = 1 ticket.winning_count = 1 ticket.system_count = 1 return [ticket]
class CustomPlayer(Player): def __init__(self, competition): super(CustomPlayer, self).__init__(competition, NAME) self.account = RecoverAccount(self.competition.user.account_manager) self.account._initial_token = 5 self.team = None self.event_id = None self.event_data = {} self.odd_id = 0 self.min_week = 3 self.bet_flag = False self.reset_flag = True self.shutdown_event.set() async def forecast(self): table = self.competition.table.table # type: List[Dict] league_games = self.competition.league_games # type: Dict[int, Dict] if self.competition.week == 3: self.team = table[-1].get('team') self.bet_flag = False if self.reset_flag: self.account.reset_lost_amount() if not self.team or self.competition.week not in self.required_weeks: return [] if not self.bet_flag: return [] week_games = league_games.get( self.competition.week) # type: Dict[int, Dict] for event_id, event_data in week_games.items(): player_a = event_data.get('A') player_b = event_data.get('B') if player_a == self.team or player_b == self.team: self.event_id = event_id self.event_data = event_data if player_a == self.team: self.odd_id = 1 else: self.odd_id = 0 self._bet = True break else: continue if not self._bet: return [] odds = self.event_data.get('odds') participants = self.event_data.get('participants') ticket = Ticket(self.competition.game_id, self.name) event = Event(self.event_id, self.competition.league, self.competition.week, participants) market_id, odd_name, odd_index = Player.get_market_info( str(self.odd_id)) odd_value = float(odds[odd_index]) if odd_value < 1.02: return [] stake = self.account.normalize_stake(self.account.get_stake(odd_value)) bet = Bet(self.odd_id, market_id, odd_value, odd_name, stake) event.add_bet(bet) win = round(stake * odd_value, 2) min_win = win max_win = win logger.info( f'[{self.competition.user.username}:{self.competition.game_id}] {self.name} ' f'{event.get_formatted_participants()}[{self.odd_id} : {odd_value}]' ) ticket.add_event(event) ticket.stake = stake ticket.min_winning = min_win ticket.max_winning = max_win ticket.total_won = 0 ticket.grouping = 1 ticket.winning_count = 1 ticket.system_count = 1 return [ticket] async def on_result(self): if self.team: if self.competition.week == self.competition.max_week - ( self.margin - self.width): ready_table = self.competition.table.ready_table team_data = ready_table.get(self.team, {}) streak = team_data.get('streak') last = streak[-self.width:] print(last) if sum(last) >= 4: self.bet_flag = True async def on_ticket_resolve(self, ticket: Ticket): if ticket.total_won > 0: self.current_league_complete = True def get_required_weeks(self): self.required_weeks = [ i for i in range(self.competition.max_week - self.margin, self.competition.max_week + 1) ]
class CustomPlayer(Player): def __init__(self, competition): super(CustomPlayer, self).__init__(competition, NAME) self.account = RecoverAccount(self.competition.user.account_manager) self.team = None self.prev_team = None self.event_id = None self.event_data = {} self.odd_id = 0 self.shutdown_event.set() def can_forecast(self): return self._forecast async def forecast(self): table = self.competition.table.table # type: List[Dict] league_games = self.competition.league_games # type: Dict[int, Dict] if self.competition.week == self.competition.max_week: self.prev_team = table[0].get('team') if not self.team or self.competition.week not in self.required_weeks: return [] week_games = league_games.get( self.competition.week) # type: Dict[int, Dict] for event_id, event_data in week_games.items(): player_a = event_data.get('A') player_b = event_data.get('B') if player_a == self.team or player_b == self.team: self.event_id = event_id self.event_data = event_data if player_a == self.team: self.odd_id = 0 else: self.odd_id = 1 self._bet = True break else: continue if not self._bet: return [] odds = self.event_data.get('odds') participants = self.event_data.get('participants') ticket = Ticket(self.competition.game_id, self.name) event = Event(self.event_id, self.competition.league, self.competition.week, participants) market_id, odd_name, odd_index = Player.get_market_info( str(self.odd_id)) odd_value = float(odds[odd_index]) if odd_value < 1.02: return [] stake = self.account.normalize_stake(self.account.get_stake(odd_value)) bet = Bet(self.odd_id, market_id, odd_value, odd_name, stake) event.add_bet(bet) win = round(stake * odd_value, 2) min_win = win max_win = win logger.info( f'[{self.competition.user.username}:{self.competition.game_id}] {self.name} ' f'{event.get_formatted_participants()}[{self.odd_id} : {odd_value}]' ) ticket.add_event(event) ticket.stake = stake ticket.min_winning = min_win ticket.max_winning = max_win ticket.total_won = 0 ticket.grouping = 1 ticket.winning_count = 1 ticket.system_count = 1 # print(ticket) return [ticket] def get_required_weeks(self): self.team = self.prev_team if self.team: required_weeks = [] league_games = self.competition.league_games # type: Dict[int, Dict] for week, week_games in league_games.items(): for event_id, event_data in week_games.items(): player_a = event_data.get('A') player_b = event_data.get('B') odds = event_data.get('odds') if player_a == self.team or player_b == self.team: if player_a == self.team: odd_id = 0 else: odd_id = 1 market_id, odd_name, odd_index = Player.get_market_info( str(odd_id)) odd_value = float(odds[odd_index]) if 1.9 > odd_value > 1.4: if week not in required_weeks: required_weeks.append(week) if len(required_weeks) >= 5: self.required_weeks = required_weeks else: super().get_required_weeks()
class CustomPlayer(Player): def __init__(self, competition): super(CustomPlayer, self).__init__(competition, NAME) self.account = RecoverAccount(self.competition.user.account_manager) self.team = None self.event_id = None self.event_data = {} self.odd_id = 0 def can_forecast(self): if self.competition.week < 8: return False return self._forecast async def forecast(self): table = self.competition.table.table # type: List[Dict] self.team = table[0].get('team') league_games = self.competition.league_games # type: Dict[int, Dict] week_games = league_games.get(self.competition.week) # type: Dict[int, Dict] for event_id, event_data in week_games.items(): player_a = event_data.get('A') player_b = event_data.get('B') if player_a == self.team or player_b == self.team: self.event_id = event_id self.event_data = event_data self._bet = True break else: continue odds = self.event_data.get('odds') participants = self.event_data.get('participants') ticket = Ticket(self.competition.game_id, self.name) event = Event(self.event_id, self.competition.league, self.competition.week, participants) ticket.add_event(event) min_win = 0 max_win = 0 total_stake = 0 a = [i for i in range(15, 43)] b = [] for _ in a: market_id, odd_name, odd_index = Player.get_market_info(str(_)) b.append(1 / float(odds[odd_index])) target_odd_ids = secrets.SystemRandom().choices(a, b, k=20) for odd_id in [73, 75]: market_id, odd_name, odd_index = Player.get_market_info(str(odd_id)) odd_value = float(odds[odd_index]) if odd_value < 1.02: return [] stake = self.account.normalize_stake(10) total_stake += stake bet = Bet(odd_id, market_id, odd_value, odd_name, stake) event.add_bet(bet) win = round(stake * odd_value, 2) min_win = win if win < min_win else min_win max_win = win if max_win > max_win else max_win logger.info(f'[{self.competition.user.username}:{self.competition.game_id}] {self.name} ' f'{event.get_formatted_participants()}[{odd_id} : {odd_value}]') ticket.stake = total_stake ticket.min_winning = min_win ticket.max_winning = max_win ticket.total_won = 0 ticket.grouping = 1 ticket.winning_count = len(target_odd_ids) ticket.system_count = len(target_odd_ids) return [ticket]
class CustomPlayer(Player): def __init__(self, competition): super(CustomPlayer, self).__init__(competition, NAME) self.account = RecoverAccount(self.competition.user.account_manager) self.team = None self.event_id = None self.event_data = {} self.odd_id = 73 def predict(self, week): league_games = self.competition.league_games # type: Dict[int, Dict] week_games = league_games.get( self.competition.week) # type: Dict[int, Dict] stats = self.competition.table.get_week_stats(week) for event_id, event_data in week_games.items(): player_a = event_data.get('A') player_b = event_data.get('B') event_stats = stats.get(event_id) if event_stats: team_to_team = event_stats.get('teamToTeam') head_to_head = team_to_team.get('headToHead') last_result = team_to_team.get('lastResult') x, y = self.get_result_ratio(last_result) event_valid = True z = x - y if abs(z) > 60: if z > 0: self.odd_id = 0 else: self.odd_id = 1 else: event_valid = False ''' for score in head_to_head: a = int(score[0]) b = int(score[1]) if ((a + b) > 3) and (a != 0 and b != 0): continue else: event_valid = False break ''' if event_valid: self.team = player_a if self.team: break async def forecast(self): if self.team: pass else: self.predict(self.competition.week) if not self.team: return [] league_games = self.competition.league_games # type: Dict[int, Dict] week_games = league_games.get( self.competition.week) # type: Dict[int, Dict] for event_id, event_data in week_games.items(): player_a = event_data.get('A') player_b = event_data.get('B') if player_a == self.team or player_b == self.team: self.event_id = event_id self.event_data = event_data self._bet = True break else: continue odds = self.event_data.get('odds') participants = self.event_data.get('participants') ticket = Ticket(self.competition.game_id, self.name) event = Event(self.event_id, self.competition.league, self.competition.week, participants) market_id, odd_name, odd_index = Player.get_market_info( str(self.odd_id)) odd_value = float(odds[odd_index]) if odd_value < 1.02: return [] stake = self.account.normalize_stake(5) bet = Bet(self.odd_id, market_id, odd_value, odd_name, stake) event.add_bet(bet) win = round(stake * odd_value, 2) min_win = win max_win = win logger.info( f'[{self.competition.user.username}:{self.competition.game_id}] {self.name} ' f'{event.get_formatted_participants()}[{self.odd_id} : {odd_value}]' ) ticket.add_event(event) ticket.stake = stake ticket.min_winning = min_win ticket.max_winning = max_win ticket.total_won = 0 ticket.grouping = 1 ticket.winning_count = 1 ticket.system_count = 1 return [ticket] async def on_ticket_resolve(self, ticket: Ticket): # if ticket.total_won != 0: self.team = None