from . import models from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants import math import settings import time class EndWaitPage(WaitPage): group_by_arrival_time = True template_name = 'payment/EndWaitPage.html' def vars_for_template(self): participation_fee = self.session.config['participation_fee'] mturk = self.session.config.get('mturk',False) game_payoff = self.participant.vars['game_payoff'] # tickets = self.participant.vars.get('tickets',0) final_payment = self.participant.payoff_plus_participation_fee() payoff_info = [ ('Allocation Task', 'To be determined.'), # ('Raffle Tickets Earned', tickets), # ('Raffle Ticket Winner?', 'To be determined'), ('Interactive Task', str(c(game_payoff))), ('Logical questions', str(c(self.participant.vars.get('crt_payoff',0)))), ('Solving puzzles', str(c(self.participant.vars.get('ravens_payoff',0)))), ] return { 'participation_fee': participation_fee, 'mturk': mturk, 'payoff_in_points': self.participant.payoff, 'payment': self.participant.payoff.to_real_world_currency(self.session), 'final_payment': final_payment, # 'tickets': tickets, 'dropout': self.player.dropout, 'payoff_info': payoff_info, 'real_currency': getattr(settings, 'REAL_WORLD_CURRENCY_CODE', '$'), } def is_displayed(self): print(self.player,'now it is at display function') self.player.experiment_duration = round((self.participant.vars.get('experiment_ending_time',time.time()) - self.participant.vars.get('experiment_starting_time',time.time())) * 10) / 10 self.player.workerid = self.participant.vars.get('workerid','') self.player.dropout = self.participant.vars.get('dropout',0) # set the playser variable "dropout" self.player.matched = self.participant.vars.get('matched',False) self.player.qualified = self.participant.vars.get('qualified',False) return not self.participant.vars.get('finished',0) class EndInfo(Page): def vars_for_template(self): mturk = self.session.config.get('mturk',False) exchange_rate = self.session.config.get('real_world_currency_per_point', 1) participation_fee = self.session.config['participation_fee'] # quiz_payment = self.session.config.get('quiz_payment', 2) self.player.final_payment = float(self.participant.payoff_plus_participation_fee()) if self.player.qualified and (not self.player.matched): # qualified but unmatched participants receive quiz_payment self.player.final_payment = float(participation_fee) # self.player.payoff -= round((participation_fee - quiz_payment)/exchange_rate) self.player.bonus = round((self.player.final_payment - float(participation_fee))*100)/100 if self.player.dropout or (not self.player.qualified): # dropouts and unqualified participants receive 0 self.player.final_payment = 0 self.player.bonus = 0 # self.player.payoff -= round(participation_fee/exchange_rate) game_payoff = self.participant.vars.get('game_payoff',0) payoff_info = [ ('Allocation Task', str(c(self.participant.vars.get('eet_payoff',0)))), ('Interactive Task', str(c(game_payoff))), # ('Raffle Ticket Payment', str(c(raffle_payoff))), ('Logical questions', str(c(self.participant.vars.get('crt_payoff',0)))), ('Solving puzzles', str(c(self.participant.vars.get('ravens_payoff',0)))), ] return { 'participation_fee': participation_fee, 'mturk': mturk, 'payoff_in_points': self.participant.payoff, 'final_payment': self.player.final_payment, 'bonus_payment': self.player.final_payment - participation_fee, 'matched': self.player.matched, 'qualified': self.player.qualified, 'dropout': self.player.dropout, 'payoff_info': payoff_info, 'real_currency': getattr(settings, 'REAL_WORLD_CURRENCY_CODE', '$'), } page_sequence = [ EndWaitPage, EndInfo, ]