from otree.api import * doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'ht_pilot_2' players_per_group = None num_rounds = 12 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): num_correct = models.IntegerField(initial=0) num_incorrect = models.IntegerField(initial=0) attempted = models.IntegerField(initial=0) difficult = models.BooleanField() condition = models.StringField() payment = models.StringField() def make_field1(label): return models.IntegerField( choices=[ [1, "1 (Very Low Effort)"], [2, "2"], [3, "3"], [4, "4 (Moderate Effort)"], [5, "5"], [6, "6"], [7, "7 (Very High Effort)"] ], label=label, widget=widgets.RadioSelectHorizontal, ) peq1 = make_field1('1. How much effort did you devote to performing well in the Type 1 ' '(subtracting two-digit from two-digit numbers in Round 1) math task?') peq2 = make_field1('2. How much effort did you devote to performing well in the Type 2 ' '(subtracting two-digit from three-digit numbers in Round 2) math task?') peq3 = make_field1('3. How much effort did you devote to performing well in the Type 3 ' '(subtracting two-digit from three-digit numbers with the slider in Rounds 3-12) math task?') peq2a = make_field1('2. How much effort did you devote to performing well in the Type 2 ' '(subtracting three-digit from three-digit numbers in Round 2) math task?') peq3a = make_field1('3. How much effort did you devote to performing well in the Type 3 ' '(subtracting three-digit from three-digit numbers with the slider in Rounds 3-12) math task?') def make_field2(label): return models.IntegerField( choices=[ [1, "1 (Not at all interesting)"], [2, "2"], [3, "3"], [4, "4 (Moderately interesting)"], [5, "5"], [6, "6"], [7, "7 (Very interesting)"] ], label=label, widget=widgets.RadioSelectHorizontal, ) peq4 = make_field2('How interesting did you find the Type 1 ' '(subtracting two-digit from two-digit numbers in Round 1) math task? ') peq5 = make_field2('How interesting did you find the Type 2 ' '(subtracting two-digit from three-digit numbers in Round 2) math task? ') peq6 = make_field2('How interesting did you find the Type 3 ' '(subtracting two-digit from three-digit numbers with the slider in Rounds 3-12) math task? ') peq5a = make_field2('How interesting did you find the Type 2 ' '(subtracting three-digit from three-digit numbers in Round 2) math task? ') peq6a = make_field2('How interesting did you find the Type 3 ' '(subtracting three-digit from three-digit numbers with the slider in Rounds 3-12) math task? ') total_strategy = models.LongStringField( label='Please describe your strategy (if any) during Rounds 3-12.' ) strategy_change = models.LongStringField( label='Did your strategy change during Rounds 3-12? If so, please describe how.' ) gender = models.IntegerField( label='Gender Identification:', choices=[ [1, 'Male'], [2, 'Female'], [3, 'Other'], [4, 'Prefer not to answer'] ], widget=widgets.RadioSelect) age = models.IntegerField( min=18, label='Age (in years):') grade_status = models.IntegerField( label='Current grade status', choices=[ [1, 'Freshman'], [2, 'Sophomore'], [3, 'Junior'], [4, 'Senior'], [5, 'Graduate'] ], widget=widgets.RadioSelect) major = models.StringField( label='What is your academic major? (answer "none" or "undecided" if applicable):' ) gpa = models.FloatField( label='What is your GSU GPA?' ) math = models.IntegerField( label='How many college-level math classes have you taken? (answer with a number)' ) # FUNCTIONS def creating_session(subsession): import itertools if subsession.round_number == 1: difficult = itertools.cycle([True, False]) for player in subsession.get_players(): participant = player.participant participant.vars['difficult'] = next(difficult) print('treatment', participant.vars['difficult']) if participant.vars['difficult']: player.condition = "2x3" else: player.condition = "3x3" # PAGES class Page1_General(Page): def is_displayed(player): return player.round_number == 1 class TaskInformation(Page): def is_displayed(player): return player.round_number == 1 def vars_for_template(player: Player): if player.participant.vars['difficult']: difficult = 1 else: difficult = 0 return dict( difficult=difficult, ) class Feedback_Earnings(Page): def is_displayed(player): return player.round_number == 1 def vars_for_template(player: Player): if player.participant.vars['difficult']: difficult = 1 else: difficult = 0 return dict( difficult=difficult, ) class Procedures(Page): def is_displayed(player): return player.round_number == 1 class Testrun(Page): def is_displayed(player): return player.round_number == 1 class Task1(Page): timeout_seconds = 240 def is_displayed(player): return player.round_number == 1 def live_method(player, data): print(data) if data == 0: player.num_correct += 1 else: player.num_incorrect += 1 player.attempted = player.num_correct + player.num_incorrect print('number_correct:', player.num_correct) print('number_incorrect:', player.num_incorrect) print('number_attempted:', player.attempted) @staticmethod def before_next_page(player, timeout_happened): player.participant.vars['payoff'] = player.num_correct * 2 print('payoff:', player.participant.vars['payoff']) class Task2(Page): timeout_seconds = 240 def is_displayed(player): return player.round_number == 2 def live_method(player, data): print(data) if data == 0: player.num_correct += 1 else: player.num_incorrect += 1 player.attempted = player.num_correct + player.num_incorrect print('number_correct:', player.num_correct) print('number_incorrect:', player.num_incorrect) print('number_attempted:', player.attempted) @staticmethod def js_vars(player: Player): if player.participant.vars['difficult']: lower1 = 300 lower2 = 101 upper1 = 500 upper2 = 299 else: lower1 = 101 lower2 = 11 upper1 = 500 upper2 = 99 return dict( lower1=lower1, upper1=upper1, lower2=lower2, upper2=upper2, ) @staticmethod def before_next_page(player, timeout_happened): if player.participant.vars['difficult']: player.participant.vars['payoff'] += player.num_correct * 4 else: player.participant.vars['payoff'] += player.num_correct * 3 print('payoff:', player.participant.vars['payoff']) class Slider(Page): timeout_seconds = 120 def is_displayed(player): return player.round_number >= 3 def live_method(player, data): print(data) if data == 0: player.num_correct += 1 else: player.num_incorrect += 1 player.attempted = player.num_correct + player.num_incorrect print('number_correct:', player.num_correct) print('number_incorrect:', player.num_incorrect) print('number_attempted:', player.attempted) def js_vars(player: Player): if player.participant.vars['difficult']: lower1 = 300 lower2 = 101 upper1 = 500 upper2 = 299 else: lower1 = 101 lower2 = 11 upper1 = 500 upper2 = 99 return dict( lower1=lower1, upper1=upper1, lower2=lower2, upper2=upper2, ) @staticmethod def before_next_page(player, timeout_happened): if player.participant.vars['difficult']: player.participant.vars['payoff'] += player.num_correct * 6 else: player.participant.vars['payoff'] += player.num_correct * 5 print('payoff:', player.participant.vars['payoff']) class Results(Page): pass class PEQ1(Page): def is_displayed(player: Player): return player.round_number == Constants.num_rounds and player.participant.vars['difficult'] == 0 form_model = 'player' form_fields = ['peq1', 'peq2', 'peq3', 'peq4', 'peq5', 'peq6', ] class PEQ1a(Page): def is_displayed(player: Player): return player.round_number == Constants.num_rounds and player.participant.vars['difficult'] form_model = 'player' form_fields = ['peq1', 'peq2a', 'peq3a', 'peq4', 'peq5a', 'peq6a', ] class PEQ2(Page): def is_displayed(player: Player): return player.round_number == Constants.num_rounds form_model = 'player' form_fields = ['total_strategy', 'strategy_change', ] class PEQ3(Page): def is_displayed(player: Player): return player.round_number == Constants.num_rounds form_model = 'player' form_fields = ['gender', 'age', 'grade_status', 'major', 'gpa', 'math', ] class Payout(Page): def is_displayed(player: Player): return player.round_number == Constants.num_rounds @staticmethod def vars_for_template(player): lira = player.participant.vars['payoff'] x = lira/30 y = round(x*4)/4 conversion = '{:.2f}'.format(round(y, 2)) total = y + 5 payout = '{:.2f}'.format(total) player.payment = payout return dict( lira=lira, payout=payout, conversion=conversion, ) page_sequence = [Page1_General, TaskInformation, Feedback_Earnings, Procedures, Task1, Task2, Slider, Results, PEQ1, PEQ1a, PEQ2, PEQ3, Payout]