from otree.api import * import random class C(BaseConstants): NAME_IN_URL = 'final' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 SHOWUP_FEE = 5.00 POINTS_TO_EUROS = 0.01 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # ── SWB III fields ──────────────────────────────────────────────────────── swb_end_happy = models.IntegerField( choices=[0, 1, 2, 3, 4, 5, 6], label='', widget=widgets.RadioSelectHorizontal, ) swb_end_friendly = models.IntegerField( choices=[0, 1, 2, 3, 4, 5, 6], label='', widget=widgets.RadioSelectHorizontal, ) swb_end_relaxed = models.IntegerField( choices=[0, 1, 2, 3, 4, 5, 6], label='', widget=widgets.RadioSelectHorizontal, ) swb_end_stressed = models.IntegerField( choices=[0, 1, 2, 3, 4, 5, 6], label='', widget=widgets.RadioSelectHorizontal, ) swb_end_sad = models.IntegerField( choices=[0, 1, 2, 3, 4, 5, 6], label='', widget=widgets.RadioSelectHorizontal, ) swb_end_angry = models.IntegerField( choices=[0, 1, 2, 3, 4, 5, 6], label='', widget=widgets.RadioSelectHorizontal, ) swb_end_frustrated = models.IntegerField( choices=[0, 1, 2, 3, 4, 5, 6], label='', widget=widgets.RadioSelectHorizontal, ) feeling_order_end = models.StringField() study_guess = models.LongStringField(label='') class SWBIII(Page): form_model = 'player' form_fields = [ 'swb_end_happy', 'swb_end_friendly', 'swb_end_relaxed', 'swb_end_stressed', 'swb_end_sad', 'swb_end_angry', 'swb_end_frustrated', ] @staticmethod def vars_for_template(player: Player): feelings = ['happy', 'friendly', 'relaxed', 'stressed', 'sad', 'angry', 'frustrated'] random.shuffle(feelings) player.feeling_order_end = ','.join(feelings) return dict(feeling_order=feelings) class Debriefing(Page): form_model = 'player' form_fields = ['study_guess'] class LastPage(Page): @staticmethod def vars_for_template(player: Player): p = player.participant.vars points_p1 = int(p.get('points_p1') or 0) points_p2 = int(p.get('points_p2') or 0) points_p3 = int(p.get('points_p3') or 0) p4_A = p.get('points_p4_A') p4_B = p.get('points_p4_B') if p4_A is not None: points_p4 = int(p4_A or 0) option_taken = 'A' else: points_p4 = int(p4_B or 0) option_taken = 'B' total_points = points_p1 + points_p2 + points_p3 + points_p4 total_euros = round(total_points * C.POINTS_TO_EUROS + C.SHOWUP_FEE, 2) return dict( points_p1=points_p1, points_p2=points_p2, points_p3=points_p3, points_p4=points_p4, option_taken=option_taken, total_points=total_points, showup_fee=C.SHOWUP_FEE, points_to_euros=C.POINTS_TO_EUROS, total_euros=total_euros, ) page_sequence = [ SWBIII, #Debriefing, LastPage ]