from otree.api import * from random import sample from otree.settings import settings import time #VARIABLES class C(BaseConstants): NAME_IN_URL = 'communication' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): start_time_communication = models.FloatField() time_spent_communication = models.FloatField() treatment_group = models.StringField() show_low_first = models.BooleanField() struct_message_sent_multiplier_low = models.FloatField( choices=[ [0.6, "The value of the return factor is 0.6"], [1.1, "The value of the return factor is 1.1"], ], label="Which message do you want to send to the two other participants?", widget=widgets.RadioSelect, ) nl_message_sent_multiplier_low = models.LongStringField( blank=True, label="Please type below the text that the two other participants will see when making their contribution decision.", ) struct_message_sent_multiplier_high = models.FloatField( choices=[ [0.6, "The value of the return factor is 0.6"], [1.1, "The value of the return factor is 1.1"], ], label="Which message do you want to send to the two other participants?", widget=widgets.RadioSelect, ) nl_message_sent_multiplier_high = models.LongStringField( blank=True, label="Please type below the text that the two other participants will see when making their contribution decision.", ) #FUNCTIONS def assign_order(player: Player): if player.field_maybe_none('show_low_first') is None: player.show_low_first = player.id_in_group > 2 #PAGES class ChooseMessage_statistic(Page): form_model = 'player' form_fields = ['struct_message_sent_multiplier_low', 'struct_message_sent_multiplier_high'] @staticmethod def is_displayed(player: Player): return player.participant.treatment_group == 'structured_com' @staticmethod def vars_for_template(player: Player): assign_order(player) player.treatment_group = player.participant.treatment_group if player.field_maybe_none('start_time_communication') is None: player.start_time_communication = time.time() total_pages = settings.TOTAL_PAGES_treatment_structured_com_NL current_index = player.participant._index_in_pages progress_percent = int(current_index / total_pages * 100) return { 'progress_percent': progress_percent, 'total_pages': total_pages, 'current_index': current_index, 'show_low_first': player.show_low_first, } # @staticmethod def before_next_page(player: Player, timeout_happened=False): player.time_spent_communication = time.time() - player.start_time_communication class ChooseMessage_statistic_NL(Page): form_model = 'player' form_fields = ['struct_message_sent_multiplier_low', 'struct_message_sent_multiplier_high', 'nl_message_sent_multiplier_low', 'nl_message_sent_multiplier_high'] # @staticmethod def is_displayed(player: Player): return player.participant.treatment_group == 'structured_com_NL' # @staticmethod def vars_for_template(player: Player): assign_order(player) player.treatment_group = player.participant.treatment_group if player.field_maybe_none('start_time_communication') is None: player.start_time_communication = time.time() total_pages = settings.TOTAL_PAGES_treatment_structured_com_NL current_index = player.participant._index_in_pages - 1 progress_percent = int(current_index / total_pages * 100) return { 'progress_percent': progress_percent, 'total_pages': total_pages, 'current_index': current_index, 'show_low_first': player.show_low_first, } # def error_message(self, values): if len(values['nl_message_sent_multiplier_high']) <= 5 or len(values['nl_message_sent_multiplier_low']) <= 5: return 'You must write a longer message.' # @staticmethod def before_next_page(player: Player, timeout_happened=False): player.time_spent_communication = time.time() - player.start_time_communication page_sequence = [ChooseMessage_statistic, ChooseMessage_statistic_NL]