from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import pandas as pd #fav_club_df = pd.read_excel('survey/fav_club.xlsx') #fav_club_df.phone_num = fav_club_df.phone_num.astype(str) #bookkeeper_odds_df = pd.read_excel('survey/bookkeeper_odds.xlsx') prescreen_numbers = pd.read_excel('kenya_survey/pre-screen_numbers.xlsx') prescreen_numbers.phone_numbers = prescreen_numbers.phone_numbers.astype(str).apply(lambda x: x.zfill(10)) from datetime import date from django import forms class Constants(BaseConstants): name_in_url = 'kenya_survey' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): # randomize to treatments for player in self.get_players(): player.payout_matchnum = random.choice(list(range(1, 5))) # player.benchmark_treat = random.choice(["Watford vs ManU", "Liverpool vs Arsenal"]) # player.payout_matchnum5 = random.choice(list(range(1, 11))) player.wedge1 = random.choice([-2.5, -1.5, -0.5, 0, 0.5, 1.5, 2.5]) player.wedge2 = random.choice([-2.5, -1.5, -0.5, 0, 0.5, 1.5, 2.5]) player.wedge3 = random.choice([-2.5, -1.5, -0.5, 0, 0.5, 1.5, 2.5]) player.wedge4 = random.choice([-2.5, -1.5, -0.5, 0, 0.5, 1.5, 2.5]) # player.wedge5 = random.choice([-2.5, -1.5, -0.5, 0, 0.5, 1.5, 2.5]) player.treat = random.choice(["Control", "Subj. Beliefs", "Bookmaker Beliefs"]) # player.wedge3a = random.choice([e for e in [-2.5, -1.5, -0.5, 0, 0.5, 1.5, 2.5] if e not in [player.wedge3]]) # player.wedge3b = random.choice([e for e in [-2.5, -1.5, -0.5, 0, 0.5, 1.5, 2.5] if e not in [player.wedge3, player.wedge3a]]) pass class Group(BaseGroup): pass class Player(BasePlayer): payout_matchnum = models.IntegerField() # benchmark_treat = models.StringField() wedge1 = models.FloatField() wedge2 = models.FloatField() wedge3 = models.FloatField() wedge4 = models.FloatField() # wedge5 = models.FloatField() # wedge3a = models.FloatField() # wedge3b = models.FloatField() treat = models.StringField() declaration = models.IntegerField(choices=[[1, 'I consent to participating'], [0, 'I do not consent to participating']], label='Do you consent to participating?', widget=widgets.RadioSelect) phone_num = models.StringField(label='') def phone_num_error_message(player, value): print('value is', value) if value not in prescreen_numbers.phone_numbers.values.tolist(): return 'The phone number you have entered is not eligible for this study' match_1_win = models.IntegerField(min=0, max=100, initial=0) match_1_draw = models.IntegerField(min=0, max=100, initial=0) match_1_lose = models.IntegerField(min=0, max=100, initial=0) match_1_sum = models.IntegerField() def match_1_sum_error_message(player, value): print('value is', value) if value != 100 : return 'Probabilities need to sum to 100%' match_2_win = models.IntegerField(min=0, max=100, initial=0) match_2_draw = models.IntegerField(min=0, max=100, initial=0) match_2_lose = models.IntegerField(min=0, max=100, initial=0) match_2_sum = models.IntegerField() def match_2_sum_error_message(player, value): print('value is', value) if value != 100: return 'Probabilities need to sum to 100%' match_3_win = models.IntegerField(min=0, max=100, initial=0) match_3_draw = models.IntegerField(min=0, max=100, initial=0) match_3_lose = models.IntegerField(min=0, max=100, initial=0) match_3_sum = models.IntegerField() def match_3_sum_error_message(player, value): print('value is', value) if value != 100: return 'Probabilities need to sum to 100%' # match_3_win_post = models.IntegerField(min=0, max=100, initial=0) # match_3_draw_post = models.IntegerField(min=0, max=100, initial=0) # match_3_lose_post = models.IntegerField(min=0, max=100, initial=0) # match_3_sum_post = models.IntegerField() # def match_3_sum_post_error_message(player, value): # print('value is', value) # if value != 100: # return 'Probabilities need to sum to 100%' match_4_win = models.IntegerField(min=0, max=100, initial=0) match_4_draw = models.IntegerField(min=0, max=100, initial=0) match_4_lose = models.IntegerField(min=0, max=100, initial=0) match_4_sum = models.IntegerField() def match_4_sum_error_message(player, value): print('value is', value) if value != 100: return 'Probabilities need to sum to 100%' # match_4_win_post = models.IntegerField(min=0, max=100, initial=0) # match_4_draw_post = models.IntegerField(min=0, max=100, initial=0) # match_4_lose_post = models.IntegerField(min=0, max=100, initial=0) # # match_4_sum_post = models.IntegerField() # def match_4_sum_post_error_message(player, value): # print('value is', value) # if value != 100: # return 'Probabilities need to sum to 100%' # match_5_win = models.IntegerField(min=0, max=100, initial=0) # match_5_draw = models.IntegerField(min=0, max=100, initial=0) # match_5_lose = models.IntegerField(min=0, max=100, initial=0) # match_5_sum = models.IntegerField() # def match_5_sum_error_message(player, value): # print('value is', value) # if value != 100: # return 'Probabilities need to sum to 100%' bet_primer1 = models.IntegerField(min=0, label="") bet_primer2 = models.IntegerField(min=0, label="") matchbet_1_win = models.IntegerField(min=0, max=100, initial=0) matchbet_1_draw = models.IntegerField(min=0, max=100, initial=0) matchbet_1_lose = models.IntegerField(min=0, max=100, initial=0) matchbet_1_winodds = models.FloatField() matchbet_1_drawodds = models.FloatField() matchbet_1_loseodds = models.FloatField() matchbet_1_sum = models.IntegerField() def matchbet_1_sum_error_message(player, value): print('value is', value) if value != 100: return 'Tokens need to sum to 100' matchbet_2_win = models.IntegerField(min=0, max=100, initial=0) matchbet_2_draw = models.IntegerField(min=0, max=100, initial=0) matchbet_2_lose = models.IntegerField(min=0, max=100, initial=0) matchbet_2_winodds = models.FloatField() matchbet_2_drawodds = models.FloatField() matchbet_2_loseodds = models.FloatField() matchbet_2_sum = models.IntegerField() def matchbet_2_sum_error_message(player, value): print('value is', value) if value != 100: return 'Tokens need to sum to 100' matchbet_3_win = models.IntegerField(min=0, max=100, initial=0) matchbet_3_draw = models.IntegerField(min=0, max=100, initial=0) matchbet_3_lose = models.IntegerField(min=0, max=100, initial=0) matchbet_3_winodds = models.FloatField() matchbet_3_drawodds = models.FloatField() matchbet_3_loseodds = models.FloatField() matchbet_3_sum = models.IntegerField() def matchbet_3_sum_error_message(player, value): print('value is', value) if value != 100: return 'Tokens need to sum to 100' matchbet_4_win = models.IntegerField(min=0, max=100, initial=0) matchbet_4_draw = models.IntegerField(min=0, max=100, initial=0) matchbet_4_lose = models.IntegerField(min=0, max=100, initial=0) matchbet_4_winodds = models.FloatField() matchbet_4_drawodds = models.FloatField() matchbet_4_loseodds = models.FloatField() matchbet_4_sum = models.IntegerField() def matchbet_4_sum_error_message(player, value): print('value is', value) if value != 100: return 'Tokens need to sum to 100' # matchbet_5_win = models.IntegerField(min=0, max=100, initial=0) # matchbet_5_draw = models.IntegerField(min=0, max=100, initial=0) # matchbet_5_lose = models.IntegerField(min=0, max=100, initial=0) # matchbet_5_winodds = models.FloatField() # matchbet_5_drawodds = models.FloatField() # matchbet_5_loseodds = models.FloatField() # matchbet_5_sum = models.IntegerField() # def matchbet_5_sum_error_message(player, value): # print('value is', value) # if value != 100: # return 'Tokens need to sum to 100' # matchbet_3a_win = models.IntegerField(min=0, max=100, initial=0) # matchbet_3a_draw = models.IntegerField(min=0, max=100, initial=0) # matchbet_3a_lose = models.IntegerField(min=0, max=100, initial=0) # matchbet_3a_winodds = models.FloatField() # matchbet_3a_drawodds = models.FloatField() # matchbet_3a_loseodds = models.FloatField() # matchbet_3a_sum = models.IntegerField() # def matchbet_3a_sum_error_message(player, value): # print('value is', value) # if value != 100: # return 'Tokens need to sum to 100' # matchbet_3b_win = models.IntegerField(min=0, max=100, initial=0) # matchbet_3b_draw = models.IntegerField(min=0, max=100, initial=0) # matchbet_3b_lose = models.IntegerField(min=0, max=100, initial=0) # matchbet_3b_winodds = models.FloatField() # matchbet_3b_drawodds = models.FloatField() # matchbet_3b_loseodds = models.FloatField() # matchbet_3b_sum = models.IntegerField() # def matchbet_3b_sum_error_message(player, value): # print('value is', value) # if value != 100: # return 'Tokens need to sum to 100' match_1_watch = models.StringField(choices=['Yes', 'No'], label= 'Are you planning to watch this match?', widget=widgets.RadioSelect) match_2_watch = models.StringField(choices=['Yes', 'No'], label='Are you planning to watch this match?', widget=widgets.RadioSelect) match_3_watch = models.StringField(choices=['Yes', 'No'], label='Are you planning to watch this match?', widget=widgets.RadioSelect) match_4_watch = models.StringField(choices=['Yes', 'No'], label='Are you planning to watch this match?', widget=widgets.RadioSelect) # match_5_watch = models.StringField(choices=['Yes', 'No'], label='Are you planning to watch this match?', widget=widgets.RadioSelect) match_1_desiredresult = models.StringField(choices=['Win Man United', 'Draw', 'Win Brighton', 'I don\'t care'], label='What result would you like to see?', widget=widgets.RadioSelect) match_2_desiredresult = models.StringField(choices=['Win Leeds', 'Draw', 'Win Arsenal', 'I don\'t care'], label='What result would you like to see?', widget=widgets.RadioSelect) match_3_desiredresult = models.StringField(choices=['Win Wolves', 'Draw', 'Win Chelsea', 'I don\'t care'], label='What result would you like to see?', widget=widgets.RadioSelect) match_4_desiredresult = models.StringField(choices=['Win Everton', 'Draw', 'Win Leicester', 'I don\'t care'], label='What result would you like to see?', widget=widgets.RadioSelect) # match_5_desiredresult = models.StringField(choices=['Win Liverpool', 'Draw', 'Win Aston Villa', 'I don\'t care'], label='What result would you like to see?', # widget=widgets.RadioSelect) # match_3_desiredresult = models.StringField(label='What result would you like to see?', # widget=widgets.RadioSelect) # match_4_desiredresult = models.StringField(label='What result would you like to see?', # widget=widgets.RadioSelect) # def match_3_desiredresult_choices(player): # if player.benchmark_treat == "Watford vs ManU": # choices = ['Win Liverpool', 'Draw', 'Win Arsenal', 'I don\'t care'] # else: # choices = ['Win Watford', 'Draw', 'Win Man United', 'I don\'t care'] # return choices # def match_4_desiredresult_choices(player): # if player.benchmark_treat == "Watford vs ManU": # choices = ['Win Watford', 'Draw', 'Win Man United', 'I don\'t care'] # else: # choices = ['Win Liverpool', 'Draw', 'Win Arsenal', 'I don\'t care'] # return choices match_1_changechoice = models.StringField(choices=['Yes', 'No'], label='', widget=widgets.RadioSelect) match_2_changechoice = models.StringField(choices=['Yes', 'No'], label='', widget=widgets.RadioSelect) match_3_changechoice = models.StringField(choices=['Yes', 'No'], label='', widget=widgets.RadioSelect) match_4_changechoice = models.StringField(choices=['Yes', 'No'], label='', widget=widgets.RadioSelect) # match_1_affectresult = models.StringField(choices=['Yes', 'No'], # label='Do you think your bet affects the result of this match?', # widget=widgets.RadioSelect) # match_2_affectresult = models.StringField(choices=['Yes', 'No'], # label='Do you think your bet affects the result of this match?', # widget=widgets.RadioSelect) # match_3_affectresult = models.StringField(choices=['Yes', 'No'], # label='Do you think your bet affects the result of this match?', # widget=widgets.RadioSelect) # match_4_affectresult = models.StringField(choices=['Yes', 'No'], # label='Do you think your bet affects the result of this match?', # widget=widgets.RadioSelect) # attn_chk = models.IntegerField(label='') matchbet_1_change_win = models.IntegerField(min=0, max=100, initial=0, blank=True) matchbet_1_change_draw = models.IntegerField(min=0, max=100, initial=0, blank=True) matchbet_1_change_lose = models.IntegerField(min=0, max=100, initial=0, blank=True) matchbet_1_change_sum = models.IntegerField() def matchbet_1_change_sum_error_message(player, value): print('value is', value) if value < 100 and value > 0: return 'Tokens need to sum to 100' matchbet_2_change_win = models.IntegerField(min=0, max=100, initial=0, blank=True) matchbet_2_change_draw = models.IntegerField(min=0, max=100, initial=0, blank=True) matchbet_2_change_lose = models.IntegerField(min=0, max=100, initial=0, blank=True) matchbet_2_change_sum = models.IntegerField() def matchbet_2_change_sum_error_message(player, value): print('value is', value) if value < 100 and value > 0: return 'Tokens need to sum to 100' matchbet_3_change_win = models.IntegerField(min=0, max=100, initial=0, blank=True) matchbet_3_change_draw = models.IntegerField(min=0, max=100, initial=0, blank=True) matchbet_3_change_lose = models.IntegerField(min=0, max=100, initial=0, blank=True) matchbet_3_change_sum = models.IntegerField() def matchbet_3_change_sum_error_message(player, value): print('value is', value) if value < 100 and value > 0: return 'Tokens need to sum to 100' matchbet_4_change_win = models.IntegerField(min=0, max=100, initial=0, blank=True) matchbet_4_change_draw = models.IntegerField(min=0, max=100, initial=0, blank=True) matchbet_4_change_lose = models.IntegerField(min=0, max=100, initial=0, blank=True) matchbet_4_change_sum = models.IntegerField() def matchbet_4_change_sum_error_message(player, value): print('value is', value) if value < 100 and value > 0: return 'Tokens need to sum to 100' completed = models.IntegerField(label='') Introduction_time = models.FloatField() PhoneNum_time = models.FloatField() KwaTreat_time = models.FloatField() # FavClub_time = models.FloatField() # BettingBehavior_time = models.FloatField() MatchBeliefs_a_time = models.FloatField() MatchBeliefs_b_time = models.FloatField() MatchBeliefs_c_time = models.FloatField() # MatchBeliefs_c_post_time = models.FloatField() MatchBeliefs_d_time = models.FloatField() # MatchBeliefs_e_time = models.FloatField() # MatchBeliefs_d_post_time = models.FloatField() BetIntro_time = models.FloatField() BetPrimer_time = models.FloatField() # BetPrimer_correct_time = models.FloatField() # BetPrimer_wrong_time = models.FloatField() MatchBet_a_time = models.FloatField() MatchBet_b_time = models.FloatField() MatchBet_c_time = models.FloatField() # Description_page_time = models.FloatField() MatchBet_d_time = models.FloatField() # MatchBet_e_time = models.FloatField() MatchBet_a_change_time = models.FloatField() MatchBet_b_change_time = models.FloatField() MatchBet_c_change_time = models.FloatField() MatchBet_d_change_time = models.FloatField() # Benchmark_Treat_time = models.FloatField() PotentialBonus_time = models.FloatField() # PotentialBonus_a_time = models.FloatField() # ThankYou_time = models.FloatField()