from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random from experience_no_choice.models import mark_slot_taken_for_participant, touch_reservation, reservation_active class FinalDecision(Page): def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False tg = self.participant.vars.get('tg') # or whatever key you used return tg in {2, 3, 4} def error_message(self, values): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return "Your session has expired due to inactivity" def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return touch_reservation(self.session, self.participant) class ChoicePage(Page): form_model = 'player' form_fields = ['option_choice'] def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False tg = self.participant.vars.get('tg') # or whatever key you used return tg in {2, 3, 4} def error_message(self, values): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return "Your session has expired due to inactivity" def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return touch_reservation(self.session, self.participant) class Question_1(Page): form_model='player' form_fields=['probability'] def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False tg = self.participant.vars.get('tg') # or whatever key you used return tg in {2, 3, 4} def error_message(self, values): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return "Your session has expired due to inactivity" def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return touch_reservation(self.session, self.participant) class Results(Page): def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False tg = self.participant.vars.get('tg') # or whatever key you used return tg in {2, 3, 4} def vars_for_template(self): p = self.player lottery2 = [0, -4, -4, -4, -4] if p.option_choice == 2: p.lottery_outcome = -3 else: p.lottery_outcome = random.choice(lottery2) return dict( z=p.lottery_outcome, l=-p.lottery_outcome*2, ) def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return self.player.payoff = self.player.lottery_outcome*2 touch_reservation(self.session, self.participant) class AttentionCheckResponse(Page): form_model = 'player' form_fields = ['color_choice'] def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False tg = self.participant.vars.get('tg') # or whatever key you used return tg in {2, 3, 4} def error_message(self, values): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return "Your session has expired due to inactivity" def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return touch_reservation(self.session, self.participant) class Question_2(Page): form_model='player' form_fields=['X'] def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False return True def error_message(self, values): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return "Your session has expired due to inactivity" def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return touch_reservation(self.session, self.participant) class Question_3(Page): form_model = 'player' form_fields = ['ball_cost'] def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False return True def error_message(self, values): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return "Your session has expired due to inactivity" def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return touch_reservation(self.session, self.participant) class Question_4(Page): form_model = 'player' form_fields = ['length_minutes'] def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False return True def error_message(self, values): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return "Your session has expired due to inactivity" def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return touch_reservation(self.session, self.participant) class Question_5(Page): form_model = 'player' form_fields = ['duration_days'] def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False return True def error_message(self, values): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return "Your session has expired due to inactivity" def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return touch_reservation(self.session, self.participant) class Question_6(Page): form_model = 'player' form_fields = ['played_lottery'] def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False return True def error_message(self, values): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return "Your session has expired due to inactivity" def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return touch_reservation(self.session, self.participant) class Question_7(Page): form_model = 'player' form_fields = ['won_lottery'] def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False return True def error_message(self, values): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return "Your session has expired due to inactivity" def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return touch_reservation(self.session, self.participant) class AfterR(Page): def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False return True def vars_for_template(self): return dict( w=self.participant.payoff, h= 19.00 - self.participant.payoff, ) def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return touch_reservation(self.session, self.participant) class TheEnd(Page): def is_displayed(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return False return True def before_next_page(self): if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return # Finalize the slot exactly once, at the very end of the study if not self.participant.vars.get('slot_marked'): mark_slot_taken_for_participant(self.session, self.participant) self.participant.vars['slot_marked'] = True class Expired(Page): # Show if we’ve already marked them expired, or if the reservation is no longer active. def is_displayed(self): if self.participant.vars.get('expired'): return True if not reservation_active(self.session, self.participant): self.participant.vars['expired'] = True return True return False page_sequence = [FinalDecision, ChoicePage, Question_1, Results, AttentionCheckResponse, Question_2, Question_3, Question_4, Question_5, Question_6, Question_7, AfterR, TheEnd, Expired,]