from otree.api import * import random import itertools # import string # import csv doc = """ Your app description """ def creating_session(subsession): scope = itertools.cycle([True, False]) for p in subsession.get_players(): p.ask_red = next(scope) def set_payoff_dotspot1(player): if player.red_dotspot == 1: if player.ask_red == 1: if abs(player.percentage_red - 65) < random.randint(0, 100): player.payoff_dotspot1=1 else: player.payoff_dotspot1=0 elif player.ask_red == 0: if abs(player.percentage_blue - 35) < random.randint(0, 100): player.payoff_dotspot1=1 else: player.payoff_dotspot1=1 if player.red_dotspot == 0: if player.ask_red == 1: if abs(player.percentage_red - 35) < random.randint(0, 100): player.payoff_dotspot1=1 else: player.payoff_dotspot1=0 elif player.ask_red == 0: if abs(player.percentage_blue - 65) < random.randint(0, 100): player.payoff_dotspot1=1 else: player.payoff_dotspot1=1 ########################################################################################################### ################################## MODELS ################################ ########################################################################################################### class Constants(BaseConstants): name_in_url = 'dot_spot' players_per_group = None num_rounds = 1 extra_payoff=6 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): #dot_spot_estimation = models.IntegerField( # label='Which fraction of the dots in the graphic were RED?',initial=None,min=0,max=100 #) percentage_red = models.IntegerField( label='Which percentage of the dots in the graphic were RED?', initial=None, min=0, max=100 ) percentage_blue = models.IntegerField( label='Which percentage of the dots in the graphic were BLUE?', initial=None, min=0, max=100 ) #dot_spot_estimation_b = models.IntegerField( # label='Which fraction of the dots in the graphic were RED?', initial=None, min=0, max=100 #) red_dotspot = models.BooleanField() ask_red = models.BooleanField() payoff_dotspot1 = models.IntegerField() details_dotspot_1 = models.BooleanField(initial=False) #button_clicks = models.IntegerField(initial=0) #dotspot_fifty_fifty = models.BooleanField(initial=False) ########################################################################################################### ################################## PAGES ################################ ########################################################################################################### class InstructionsA(Page): form_model = 'player' form_fields = ['details_dotspot_1'] @staticmethod def before_next_page(player, timeout_happened): player.red_dotspot = random.choice([True, False]) #player.ask_red = random.choice([True, False]) class InstructionsB(Page): @staticmethod def is_displayed(player: Player): return player.details_dotspot_1 == True class DotSpotShownRed(Page): @staticmethod def is_displayed(player: Player): return player.red_dotspot == True timeout_seconds = 8 class DotSpotShownBlue(Page): @staticmethod def is_displayed(player: Player): return player.red_dotspot == False timeout_seconds = 8 class EstimationRed(Page): @staticmethod def is_displayed(player: Player): return player.ask_red == True form_model = 'player' form_fields = ['percentage_red'] @staticmethod def before_next_page(player, timeout_happened): return dict( payoff_dotspot1=set_payoff_dotspot1(player), ) class EstimationBlue(Page): @staticmethod def is_displayed(player: Player): return player.ask_red == False form_model = 'player' form_fields = ['percentage_blue'] @staticmethod def before_next_page(player, timeout_happened): return dict( payoff_dotspot1 = set_payoff_dotspot1(player), ) #class DotSpotEstimation(Page): # form_model = 'player' # form_fields = ['dot_spot_estimation', 'button_clicks'] # @staticmethod #def live_method(player: Player, data): # if data == 'clicked-button': # player.button_clicks += 1 #class DotSpotEstimationB(Page): # @staticmethod # def is_displayed(player: Player): # return player.button_clicks == 0 #form_model = 'player' #form_fields = ['dot_spot_estimation_b','dotspot_fifty_fifty'] class Part3(Page): pass page_sequence = [ Part3, InstructionsA, InstructionsB, DotSpotShownRed, DotSpotShownBlue, EstimationRed, EstimationBlue, #DotSpotEstimation, #DotSpotEstimationB, ]