"""Two certainty-state transfer decisions after the 5 uncertain situations.""" from otree.api import * from interfer_shared import Config import random import time class C(BaseConstants): NAME_IN_URL = 'certainty_decisions' PLAYERS_PER_GROUP = None NUM_ROUNDS = 2 W = Config.W TRANSFER_STEP = Config.TRANSFER_STEP BELIEF_BONUS = Config.BELIEF_BONUS class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): stage = models.StringField(initial='certainty') hidden_state = models.StringField(initial='') message_revealed = models.BooleanField(initial=False) message = models.StringField(initial='') transfer = models.FloatField(blank=True) decision_saved_at = models.FloatField(initial=0) complete = models.BooleanField(initial=False) def creating_session(subsession): if subsession.round_number != 1:return for player in subsession.get_players(): states = ['Luck', 'Performance'] random.shuffle(states) for rnd,state in enumerate(states,1): player.in_round(rnd).hidden_state = state class CertaintyIntro(Page): @staticmethod def is_displayed(player): return player.round_number == 1 and player.participant.vars.get('consent_given',False) class Decision(Page): form_model = 'player' form_fields = ['transfer'] @staticmethod def is_displayed(player): return player.participant.vars.get('consent_given',False) @staticmethod def vars_for_template(player): return dict(W=C.W,w_display=C.W,step=C.TRANSFER_STEP, is_uncertain=False,prior=-1,performance=-1,icons=[]) @staticmethod def error_message(player,values): t=values.get('transfer') if t is None or not 0<=t<=C.W or abs(round(t/C.TRANSFER_STEP)*C.TRANSFER_STEP-t)>0.00001: return dict(transfer='Choose a transfer between $0 and the full prize using the slider.') @staticmethod def before_next_page(player,timeout_happened): player.decision_saved_at=time.time() player.complete=True page_sequence = [CertaintyIntro, Decision]