from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import math import time import json from random import (randrange, choice, shuffle) class Landing(Page): def is_displayed(self) -> bool: return self.round_number == 1 def vars_for_template(self) -> dict: return { } class PreLanding(Page): def is_displayed(self) -> bool: return self.round_number == 1 form_model = 'player' form_fields = ['prolific_id'] class InstructionTP(Page): def is_displayed(self) -> bool: return self.round_number == 1 def vars_for_template(self) -> dict: return { "treatment": self.participant.vars["treatment"], } class InstructionFP(Page): def is_displayed(self) -> bool: return self.round_number == 1 def vars_for_template(self) -> dict: return { "treatment": self.participant.vars["treatment"], } class InstructionFN(Page): def is_displayed(self) -> bool: return self.round_number == 1 def vars_for_template(self) -> dict: return { "treatment": self.participant.vars["treatment"], } def before_next_page(self): self.participant.vars["start_time"] = time.time() # set timing after instruction self.player.set_start() # set start of application class Tutorial1(Page): form_model = 'player' form_fields = ['tut_box_1', 'tut_box_2', 'tut_box_3', 'tut_box_4', 'tut_box_5'] def is_displayed(self) -> bool: return self.round_number == 1 def vars_for_template(self) -> dict: self.player.tutorial_points = 0 return { "treatment": self.participant.vars["treatment"], "tutorial_points": self.participant.vars["tutorial_points"], "box_1": self.player.tut_box_1, } def before_next_page(self): if self.player.tut_box_1: self.player.tutorial_points += 1 class Tutorial2(Page): form_model = 'player' form_fields = ['tut_box_1', 'tut_box_2', 'tut_box_3', 'tut_box_4', 'tut_box_5'] def is_displayed(self) -> bool: return self.round_number == 1 def vars_for_template(self) -> dict: return { "treatment": self.participant.vars["treatment"], "tutorial_points": self.participant.vars["tutorial_points"], "box_2": self.player.tut_box_2, "box_3": self.player.tut_box_3, "box_4": self.player.tut_box_4, } def before_next_page(self): if self.player.tut_box_2: self.player.tutorial_points += 1 if self.player.tut_box_3: self.player.tutorial_points += 1 if self.player.tut_box_4: self.player.tutorial_points += 1 class Tutorial3(Page): form_model = 'player' form_fields = ['tut_box_1', 'tut_box_2', 'tut_box_3', 'tut_box_4', 'tut_box_5'] def is_displayed(self) -> bool: return self.round_number == 1 def vars_for_template(self) -> dict: return { "treatment": self.participant.vars["treatment"], "tutorial_points": self.participant.vars["tutorial_points"], "box_5": self.player.tut_box_5, } def before_next_page(self): if self.player.tut_box_5: self.player.tutorial_points += 1 class Feedback(Page): def is_displayed(self) -> bool: return self.round_number == 1 def vars_for_template(self) -> dict: return { "treatment": self.participant.vars["treatment"], "tutorial_points": self.participant.vars["tutorial_points"], } class Tasks(Page): timeout_seconds = 210 form_model = 'player' form_fields = ['box_1', 'box_2', 'box_3', 'box_4', 'box_5', 'box_6', 'box_7', 'box_8', 'box_9', 'box_10', 'box_11', 'box_12', 'box_13', 'box_14', 'box_15', 'box_16', 'box_17', 'box_18', 'box_19', 'box_20', 'box_21', 'box_22', 'box_23', 'box_24', 'box_25'] timeout_submission = {'your_answer': ""} def before_next_page(self): now = time.time() self.player.check_correct() self.player.task_duration = math.ceil(now - self.participant.vars["start_time"]) self.participant.vars["start_time"] = now # reset timer def vars_for_template(self) -> dict: context = self.player.vars_for_template() return context class FPEstimation(Page): form_model = 'player' form_fields = ['estimation'] def before_next_page(self): self.player.check_estimation() def is_displayed(self) -> bool: return self.round_number == Constants.num_rounds class Questionaire(Page): form_model = 'player' form_fields = ['q1', 'q2', 'q3', 'q4', 'q4_other'] def is_displayed(self) -> bool: return self.round_number == Constants.num_rounds class Questionaire2(Page): form_model = 'player' form_fields = ['q5', 'q6', 'q7', 'q8', 'q9', 'q10', 'q11', 'q12', 'q13'] def is_displayed(self) -> bool: return self.round_number == Constants.num_rounds class Results(Page): def is_displayed(self) -> bool: return self.round_number == Constants.num_rounds def vars_for_template(self) -> dict: return { 'total_earning': self.participant.payoff } page_sequence = [ PreLanding, Landing, InstructionTP, InstructionFP, InstructionFN, Tutorial1, Tutorial2, Tutorial3, Feedback, Tasks, FPEstimation, Questionaire, Questionaire2, Results ]