from otree import settings from otree.api import * import time from pathlib import Path import io, base64 #SESSION class C(BaseConstants): NAME_IN_URL = 'sg_noimplementation' PLAYERS_PER_GROUP = None NUM_ROUNDS = 6 #INSTRUCTIONS spectator_instructions = __name__ + "/shortinstructions.html" #SUBSESSION class Subsession(BaseSubsession): pass #GROUP class Group(BaseGroup): pass #PLAYER class Player(BasePlayer): task = models.IntegerField(label='Task', choices=[[0, 'Productivity. A:6; B:0'], [4, 'Productivity. A:0; B:6'], [5, 'Luck. A:6; B:0'], [9, 'Luck. A:0; B:6'], [10, 'Productivity. No default'], [11, 'Luck. No default']], ) reason = models.IntegerField(label='Reason', choices=[[0, 'Productivity'], [1, 'Luck']], ) statusquo = models.IntegerField(label='Initial bonus for Agent B', choices=[[0, 'A:6; B:0'], [6, 'A:0; B:6'], [99, 'No default']], ) game_alloc0 = models.FloatField(min=0,max=6) game_alloc1 = models.FloatField(min=0,max=6) rule = models.IntegerField(label='Decision rule', choices=[[0, 'No change'], [1, '50/50'], [2, 'Winner receives full bonus']], widget=widgets.RadioSelect, blank=True ) time_start = models.FloatField(label='Time: Start') time_prior = models.FloatField(label='Time: Prior') time_sg = models.FloatField(label='Time: Spectator Game') # FUNCTIONS def agents_label(player): agent0= 'A' agent1= 'B' return agent0, agent1 def rule_error_message(player, value): if value not in [0, 1, 2]: return 'You have to select one of the options.' # PAGES class Instructions0(Page): form_model = 'player' @staticmethod def is_displayed(player): first_round = {1} return player.round_number in first_round class Prior(Page): form_model = 'player' timeout_seconds = 10 @staticmethod def vars_for_template(player): participant = player.participant task_num = player.round_number - 1 player.task = participant.noimplementation_list[task_num] player.reason = ( 0 if player.task in {0, 4, 10} else 1 if player.task in {5, 9, 11} else None ) player.statusquo = ( 0 if player.task in {0, 5} else 6 if player.task in {4, 9} else 99 if player.task in {10, 11} else None ) return dict(round=player.round_number,reason=player.reason,statusquo=player.statusquo) @staticmethod def before_next_page(player, timeout_happened): player.time_prior = round(time.time(),3) class Game(Page): form_model = 'player' form_fields = ['game_alloc0','game_alloc1','rule'] @staticmethod def vars_for_template(player): agents= agents_label(player) agent0= agents[0] agent1= agents[1] return dict(round=player.round_number,reason=player.reason,statusquo=player.statusquo, agent0=agent0,agent1=agent1) @staticmethod def before_next_page(player, timeout_happened): player.time_sg = round(time.time(),3) page_sequence = [Instructions0, Prior, Game]