from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import uuid class Survey(Page): form_model = 'player' form_fields = ['problems', 'problems_text', 'strategy', 'satisfaction_with_strat', 'understanding', 'understanding_text'] timeout_seconds = Constants.timer def before_next_page(self): self.player.survey_earnings = Constants.survey_payoff self.player.game_earnings = self.participant.vars['game_earnings'] self.player.quiz_earnings = self.participant.vars['quiz_earnings'] self.player.instruction_earnings = self.participant.vars['instruction_earnings'] if self.timeout_happened is True: self.participant.payoff = 0 self.player.survey_earnings = c(0) else: self.player.total_earnings = self.player.game_earnings + self.player.quiz_earnings + self.player.instruction_earnings + self.player.survey_earnings self.player.total_earnings_dollar = str(self.player.total_earnings.to_real_world_currency(self.session)) task_earnings = self.player.game_earnings + self.player.quiz_earnings self.participant.payoff += task_earnings if self.timeout_happened: self.player.survey_timeout += 1 def is_displayed(self): if self.participant.vars['is_mobile'] is False and self.participant.vars['timed_out'] == False: return True else: return False class FinalTaskResults(Page): def vars_for_template(self): money = self.participant.payoff.to_real_world_currency(self.session) quiz = self.player.quiz_earnings.to_real_world_currency(self.session) instruction = self.player.instruction_earnings.to_real_world_currency(self.session) game = self.player.game_earnings.to_real_world_currency(self.session) survey = self.player.survey_earnings.to_real_world_currency(self.session) questions = self.participant.vars['quiz_questions_correct'] vars = {'money':money, 'quiz':quiz, 'instruction':instruction, 'game':game, 'survey': survey, 'questions':questions} return vars def is_displayed(self): if self.participant.vars['is_mobile'] is False and self.participant.vars['timed_out'] == False and self.player.survey_timeout == 0 : return True else: return False class SurveyInformation(Page): def is_displayed(self): if self.participant.vars['is_mobile'] is False and self.player.survey_timeout == 0: return True else: return False class Results(Page): def is_displayed(self): if self.participant.vars['is_mobile'] is False and self.participant.vars['timed_out'] == False: return True else: return False class Timed_Out(Page): timeout_seconds = Constants.timer def is_displayed(self): if self.participant.vars['is_mobile'] is False and self.participant.vars['timed_out'] == False and self.player.survey_timeout > 0: return True else: return False page_sequence = [ SurveyInformation, Survey, FinalTaskResults, Timed_Out, ]