from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import pandas as pd from math import sqrt bookkeeper_odds_df = pd.read_excel('prescreening_UK/bookkeeper_odds_part2.xlsx') class MatchBet_a(Page): form_model = 'player' form_fields = ['matchbet_1_win', 'matchbet_1_lose', 'matchbet_1_sum', 'matchbet_1_winodds', 'matchbet_1_loseodds', 'MatchBet_a_time'] def vars_for_template(self): bm_home = bookkeeper_odds_df['match1_home_team_odds'].iloc[0] bm_away = bookkeeper_odds_df['match1_away_team_odds'].iloc[0] wedge = self.player.participant.vars['part2_wedge1'] if wedge != 0: probability_wedge = (sqrt((4*bm_away*bm_home*(wedge**2)) + (bm_away*(-wedge) - bm_away + (bm_home*wedge) - bm_home)**2) + bm_away*(-wedge) - bm_away + (bm_home*wedge) - bm_home) / (2 * bm_away * bm_home * wedge) else: probability_wedge = 0 home_team_odds = round(1 / ((1/bm_home) + probability_wedge), 2) away_team_odds = round(1 / ((1/bm_away) - probability_wedge), 2) return dict( match_num = 1, home_team_abbv = bookkeeper_odds_df['match1_home_team_abbv'].iloc[0], home_team_odds = home_team_odds, away_team_abbv = bookkeeper_odds_df['match1_away_team_abbv'].iloc[0], away_team_odds = away_team_odds, home_team=bookkeeper_odds_df['match1_home_team'].iloc[0], away_team=bookkeeper_odds_df['match1_away_team'].iloc[0], ) def before_next_page(self): self.player.participant.vars['part2_matchbet_1_win'] = self.player.matchbet_1_win self.player.participant.vars['part2_matchbet_1_lose'] = self.player.matchbet_1_lose self.player.participant.vars['part2_matchbet_1_winodds'] = self.player.matchbet_1_winodds self.player.participant.vars['part2_matchbet_1_loseodds'] = self.player.matchbet_1_loseodds class MatchBet_b(Page): form_model = 'player' form_fields = ['matchbet_2_win', 'matchbet_2_lose', 'matchbet_2_sum', 'matchbet_2_winodds', 'matchbet_2_loseodds', 'MatchBet_b_time'] def vars_for_template(self): bm_home = bookkeeper_odds_df['match2_home_team_odds'].iloc[0] bm_away = bookkeeper_odds_df['match2_away_team_odds'].iloc[0] wedge = self.player.participant.vars['part2_wedge2'] if wedge != 0: probability_wedge = (sqrt((4*bm_away*bm_home*(wedge**2)) + (bm_away*(-wedge) - bm_away + (bm_home*wedge) - bm_home)**2) + bm_away*(-wedge) - bm_away + (bm_home*wedge) - bm_home) / (2 * bm_away * bm_home * wedge) else: probability_wedge = 0 home_team_odds = round(1 / ((1/bm_home) + probability_wedge), 2) away_team_odds = round(1 / ((1/bm_away) - probability_wedge), 2) return dict( match_num = 2, home_team_abbv = bookkeeper_odds_df['match2_home_team_abbv'].iloc[0], home_team_odds = home_team_odds, away_team_abbv = bookkeeper_odds_df['match2_away_team_abbv'].iloc[0], away_team_odds = away_team_odds, home_team=bookkeeper_odds_df['match2_home_team'].iloc[0], away_team=bookkeeper_odds_df['match2_away_team'].iloc[0], ) def before_next_page(self): self.player.participant.vars['part2_matchbet_2_win'] = self.player.matchbet_2_win self.player.participant.vars['part2_matchbet_2_lose'] = self.player.matchbet_2_lose self.player.participant.vars['part2_matchbet_2_winodds'] = self.player.matchbet_2_winodds self.player.participant.vars['part2_matchbet_2_loseodds'] = self.player.matchbet_2_loseodds class MatchBet_c(Page): form_model = 'player' form_fields = ['matchbet_3_win', 'matchbet_3_lose', 'matchbet_3_sum', 'matchbet_3_winodds', 'matchbet_3_loseodds', 'MatchBet_c_time'] def vars_for_template(self): bm_home = bookkeeper_odds_df['match3_home_team_odds'].iloc[0] bm_away = bookkeeper_odds_df['match3_away_team_odds'].iloc[0] wedge = self.player.participant.vars['part2_wedge3'] if wedge != 0: probability_wedge = (sqrt((4*bm_away*bm_home*(wedge**2)) + (bm_away*(-wedge) - bm_away + (bm_home*wedge) - bm_home)**2) + bm_away*(-wedge) - bm_away + (bm_home*wedge) - bm_home) / (2 * bm_away * bm_home * wedge) else: probability_wedge = 0 home_team_odds = round(1 / ((1/bm_home) + probability_wedge), 2) away_team_odds = round(1 / ((1/bm_away) - probability_wedge), 2) return dict( match_num = 3, home_team_abbv = bookkeeper_odds_df['match3_home_team_abbv'].iloc[0], home_team_odds = home_team_odds, away_team_abbv = bookkeeper_odds_df['match3_away_team_abbv'].iloc[0], away_team_odds = away_team_odds, home_team=bookkeeper_odds_df['match3_home_team'].iloc[0], away_team=bookkeeper_odds_df['match3_away_team'].iloc[0], ) def before_next_page(self): self.player.participant.vars['part2_matchbet_3_win'] = self.player.matchbet_3_win self.player.participant.vars['part2_matchbet_3_lose'] = self.player.matchbet_3_lose self.player.participant.vars['part2_matchbet_3_winodds'] = self.player.matchbet_3_winodds self.player.participant.vars['part2_matchbet_3_loseodds'] = self.player.matchbet_3_loseodds class MatchBet_d(Page): form_model = 'player' form_fields = ['matchbet_4_win', 'matchbet_4_lose', 'matchbet_4_sum', 'matchbet_4_winodds', 'matchbet_4_loseodds', 'MatchBet_d_time'] def vars_for_template(self): bm_home = bookkeeper_odds_df['match4_home_team_odds'].iloc[0] bm_away = bookkeeper_odds_df['match4_away_team_odds'].iloc[0] wedge = self.player.participant.vars['part2_wedge4'] if wedge != 0: probability_wedge = (sqrt((4*bm_away*bm_home*(wedge**2)) + (bm_away*(-wedge) - bm_away + (bm_home*wedge) - bm_home)**2) + bm_away*(-wedge) - bm_away + (bm_home*wedge) - bm_home) / (2 * bm_away * bm_home * wedge) else: probability_wedge = 0 home_team_odds = round(1 / ((1/bm_home) + probability_wedge), 2) away_team_odds = round(1 / ((1/bm_away) - probability_wedge), 2) return dict( match_num = 4, home_team_abbv = bookkeeper_odds_df['match4_home_team_abbv'].iloc[0], home_team_odds = home_team_odds, away_team_abbv = bookkeeper_odds_df['match4_away_team_abbv'].iloc[0], away_team_odds = away_team_odds, home_team=bookkeeper_odds_df['match4_home_team'].iloc[0], away_team=bookkeeper_odds_df['match4_away_team'].iloc[0], ) def before_next_page(self): self.player.participant.vars['part2_matchbet_4_win'] = self.player.matchbet_4_win self.player.participant.vars['part2_matchbet_4_lose'] = self.player.matchbet_4_lose self.player.participant.vars['part2_matchbet_4_winodds'] = self.player.matchbet_4_winodds self.player.participant.vars['part2_matchbet_4_loseodds'] = self.player.matchbet_4_loseodds page_sequence = [ MatchBet_a, MatchBet_b, MatchBet_c, MatchBet_d ]