from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random from datetime import date from django import forms class Constants(BaseConstants): name_in_url = 'UK_Survey_Part2' players_per_group = None tasks = ['A', 'B', 'C', 'D'] num_rounds = len(tasks) class Subsession(BaseSubsession): def creating_session(self): # randomize wedge if self.round_number == 1: for player in self.get_players(): 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.participant.vars['wedge1'] = player.wedge1 player.participant.vars['wedge2'] = player.wedge2 player.participant.vars['wedge3'] = player.wedge3 player.participant.vars['wedge4'] = player.wedge4 pass class Group(BaseGroup): pass class Player(BasePlayer): wedge1 = models.FloatField() wedge2 = models.FloatField() wedge3 = models.FloatField() wedge4 = models.FloatField() 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' 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_1_desiredresult = models.StringField(choices=['Win Southampton', 'Draw', 'Win Spurs', 'I don\'t care'], label='What result would you like to see?', widget=widgets.RadioSelect) match_2_desiredresult = models.StringField(choices=['Win Leicester', 'Draw', 'Win Liverpool', 'I don\'t care'], label='What result would you like to see?', widget=widgets.RadioSelect) match_3_desiredresult = models.StringField(choices=['Win Chelsea', 'Draw', 'Win Brighton', 'I don\'t care'], label='What result would you like to see?', widget=widgets.RadioSelect) match_4_desiredresult = models.StringField(choices=['Win Man United', 'Draw', 'Win Burnley', 'I don\'t care'], label='What result would you like to see?', widget=widgets.RadioSelect) MatchBet_a_time = models.FloatField() MatchBet_b_time = models.FloatField() MatchBet_c_time = models.FloatField() MatchBet_d_time = models.FloatField()