from otree.api import * import random doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'effort_task' PLAYERS_PER_GROUP = None NUM_ROUNDS = 10 NRO_SECCION = 1 payment_per_correct_answer = (1) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): Su_respuesta = models.IntegerField() sum_of_numbers = models.IntegerField() # PAGES class O001_instr(Page): @staticmethod def vars_for_template(player): return dict( nombre_seccion=C.NRO_SECCION, points_4_cash=int(player.session.config["real_world_currency_per_point"]) ) class O002_task(Page): form_model = "player" form_fields = ["Su_respuesta"] @staticmethod def vars_for_template(player: Player): num1 = random.randint(1, 100) num2 = random.randint(1, 100) num3 = random.randint(1, 100) num4 = random.randint(1, 100) num5 = random.randint(1, 100) num6 = random.randint(1, 100) player.sum_of_numbers = num1 + num2 + num3 + num4 + num5 + num6 return { "num1": num1, "num2": num2, "num3": num3, "num4": num4, "num5": num5, "num6": num6, } @staticmethod def before_next_page(player: Player, timeout_happened): if player.sum_of_numbers == player.Su_respuesta: player.payoff += C.payment_per_correct_answer ''' @staticmethod def vars_for_template(player : Player): return dict( nombre_seccion=C.NRO_SECCION ) ''' class O003_results(Page): @staticmethod def vars_for_template(player: Player): return dict( nombre_seccion=C.NRO_SECCION ) @staticmethod def is_displayed(player: Player): return player.round_number == C.NUM_ROUNDS @staticmethod def vars_for_template(player: Player): all_players = player.in_all_rounds() combined_payoff = 0 for temp_player in all_players: combined_payoff += temp_player.payoff return { "combined_payoff": combined_payoff } page_sequence = [O002_task, O003_results]