from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from django.views.decorators.csrf import csrf_exempt from django.utils.decorators import method_decorator import numpy as np import time def vars_for_all_templates(self): return { 'participation_fee': c(self.session.config['participation_fee']), 'round': self.round_number, 'trial': self.round_number in self.participant.vars['trial_round'], } @method_decorator(csrf_exempt, name='dispatch') class GroupWaitPage(WaitPage): def is_displayed(self): return self.round_number not in self.participant.vars['instruction_round'] and not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] and not self.participant.vars['skip'] group_by_arrival_time = True title_text = "Please Wait" body_text = "It may take a few seconds to wait for other people in your group before you can start the auction. " \ "The maximum waiting time is 5 minutes. Please refresh the page if you stay in this page too long." class MainInstructions(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['attention_got_wrong'] class AuctionInstructions(Page): def is_displayed(self): return self.round_number in self.participant.vars['instruction_round'] and not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] and not self.participant.vars['skip'] class BeginStudy(Page): def is_displayed(self): return self.round_number in self.participant.vars['instruction_round'] and not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] and not self.participant.vars['skip'] def before_next_page(self): self.participant.vars['wait_page_arrival'] = time.time() class Auction(Page): live_method = 'live_aa' def is_displayed(self): return self.round_number not in self.participant.vars['instruction_round'] and not self.participant.vars['attention_got_wrong'] and self.player.group_size != 1 and not self.participant.vars['failed_comprehension'] and not self.participant.vars['skip'] form_model = 'player' form_fields = ['bid', 'stop_help'] def js_vars(self): return { 'id': self.player.id_in_group, 'current': self.player.current_play, 'max': Constants.bid_max, 'step': Constants.signal_interval } def get_timeout_seconds(self): if self.player.current_play == "aa" or self.player.current_play == "da": return None else: return 180 def before_next_page(self): self.player.group.current_play = self.player.current_play class ResultWaitPage(WaitPage): def is_displayed(self): return self.round_number not in self.participant.vars['instruction_round'] and not self.participant.vars['attention_got_wrong'] and self.player.group_size != 1 and not self.participant.vars['failed_comprehension'] and not self.participant.vars['skip'] after_all_players_arrive = 'set_payoffs' title_text = "Please Wait" body_text = "It may take a few seconds to wait for other people in your group to submit their bids. " \ "The maximum waiting time is 2 minutes. Please refresh the page if you stay in this page too long." class Result(Page): def is_displayed(self): return self.round_number not in self.participant.vars['instruction_round'] and not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] and not self.participant.vars['skip'] def vars_for_template(self): if self.player.round_payoff > 0: abs_payoff = self.player.round_payoff positive = 1 elif self.player.round_payoff < 0: abs_payoff = -1 * self.player.round_payoff positive = -1 else: abs_payoff = 0 positive = 0 total_payoff = self.player.round_payoff + Constants.budget return { 'abs_payoff': c(abs_payoff), 'total_payoff': c(total_payoff), 'positive': positive } def before_next_page(self): self.participant.vars['wait_page_arrival'] = time.time() timeout_seconds = 45 timer_text = 'Time Remaining on this Page:' class FinishedTasks(Page): def is_displayed(self): return self.round_number == Constants.num_rounds and not self.participant.vars['attention_got_wrong'] and not self.participant.vars['failed_comprehension'] def before_next_page(self): if not self.participant.vars['skip']: self.participant.vars['correct_payment'] = c(self.participant.vars['correct_num']*0.2) self.participant.vars['total_payment'] += self.participant.vars['correct_payment'] self.player.total_payment = self.participant.vars['total_payment'] class PayoffandGoodbye(Page): def is_displayed(self): return self.round_number == Constants.num_rounds and not self.participant.vars['attention_got_wrong'] def before_next_page(self): self.player.skip = self.participant.vars['skip'] self.player.total_payment = self.participant.vars['total_payment'] class ToProlific(Page): def is_displayed(self): return self.round_number == Constants.num_rounds page_sequence = [ GroupWaitPage, AuctionInstructions, BeginStudy, Auction, ResultWaitPage, Result, FinishedTasks, PayoffandGoodbye, # ToProlific ]