from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants as Constants import random import time class Full(Page): def is_displayed(self): displayed = False if self.player.test_existance_of_session_vars() == True: if self.session.vars['num_participants_finished'] >= 5000: displayed = True return (displayed and self.round_number == 1) class ErklaerungConsent(Page): form_model = 'player' form_fields = ["prolificID"] def is_displayed(self): return self.round_number == 1 def vars_for_template(self): self.player.START_time_epoch = time.time() rand = random.random() if rand < 0.5: self.player.treatment = True else: self.player.treatment = False return{ 'powerCostsHigh': Constants.powerCostHigh, 'taskPayment': round(Constants.taskPayment, 1), 'totalPayment': Constants.num_rounds* round(Constants.taskPayment, 1), 'showContainer': self.player.in_round(1).treatment, 'num_tasks': Constants.num_rounds, 'penalty': Constants.penalty_mistake } def before_next_page(self): self.player.set_initial_num_participants() class realEffortTaskSeconds(Page): form_model = 'player' form_fields = ["elapsed_time", "realEffortTask_answer", "mistakes_made"] def vars_for_template(self): midRound = int(Constants.num_rounds/2) self.player.start_task = time.time() if self.round_number == 1: currentTime = 0 rightAnswers = 0 else: currentTime = self.player.in_round(self.round_number-1).elapsed_time rightAnswers = self.player.in_round(self.round_number-1).rightAnswers if self.player.in_round(midRound).field_maybe_none('investChoice')==1: costSecond = Constants.powerCostLow midpointBalance = self.player.in_round(midRound).elapsed_time_midpoint*(Constants.powerCostHigh-Constants.powerCostLow) else: costSecond = Constants.powerCostHigh midpointBalance = 0 return { 'currentTime': currentTime, 'rightAnswers': rightAnswers, 'roundNumber': self.round_number, 'numberA': Constants.correctAnswers[self.round_number-1], 'seed': Constants.randomSeeds[self.round_number-1], 'showContainer': self.player.in_round(1).treatment, 'costSecond': costSecond, 'gridSize': Constants.gridSize, 'midpointBalance': midpointBalance, 'penalty_time': Constants.penalty_mistake, } def before_next_page(self): self.player.end_task = time.time() if self.round_number == 1: if self.player.elapsed_time > 0: self.player.light_activated = 1 if (self.player.elapsed_time == Constants.penalty_mistake*self.player.mistakes_made): self.player.light_activated = 0 else: if (self.player.elapsed_time - self.player.in_round(self.round_number-1).elapsed_time)>0: self.player.light_activated=1 if ((self.player.elapsed_time - self.player.in_round(self.round_number - 1).elapsed_time) == Constants.penalty_mistake*self.player.mistakes_made): self.player.light_activated=0 if self.player.realEffortTask_answer == Constants.correctAnswers[self.round_number-1]: if self.round_number == 1: self.player.in_round(self.round_number).rightAnswers = 1 else: self.player.in_round(self.round_number).rightAnswers = self.player.in_round(self.round_number-1).rightAnswers + 1 else: if self.round_number == 1: self.player.in_round(self.round_number).rightAnswers = 0 else: self.player.in_round(self.round_number).rightAnswers = self.player.in_round(self.round_number-1).rightAnswers class realEffortTaskSeconds_example(Page): form_model = 'player' form_fields = ["elapsed_time_example", "realEffortTask_answer_example", "mistakes_made_example"] def is_displayed(self): return self.round_number == 1 def vars_for_template(self): currentTime = 0 rightAnswers = 0 midpointBalance = 0 return { 'currentTime': currentTime, 'rightAnswers': rightAnswers, 'roundNumber': self.round_number, 'numberA': Constants.correctAnswers_example, 'seed': Constants.randomSeeds_example, 'showContainer': self.player.in_round(1).treatment, 'costSecond': Constants.powerCostHigh, 'gridSize': Constants.gridSize, 'midpointBalance': midpointBalance, 'penalty_time': Constants.penalty_mistake, } class ErklaerungRegulierung(Page): form_model = 'player' form_fields = ["investChoice"] def is_displayed(self): return self.round_number == int(Constants.num_rounds/2) def vars_for_template(self): rightAnswers = self.player.in_round(self.round_number).rightAnswers currentTime = self.player.in_round(self.round_number).elapsed_time totalPayment = Constants.taskPayment*Constants.num_rounds/2 self.player.efficiencyInvest = max(min(currentTime * (Constants.powerCostHigh-Constants.powerCostLow), 90), 3) return { "rightAnswers":round(rightAnswers,0), 'currentTime': currentTime, 'costs': round(currentTime*Constants.powerCostHigh, 1), 'bonus': max(round(Constants.num_rounds/2*Constants.taskPayment-currentTime*Constants.powerCostHigh, 1),0), 'powerCostsHigh': Constants.powerCostHigh, 'powerCostsLow': Constants.powerCostLow, 'totalPayment': round(totalPayment,0), 'taskPayment': Constants.taskPayment, 'efficiencyInvest': round(self.player.efficiencyInvest, 1), 'number_round': round(Constants.num_rounds, 0) } def before_next_page(self): self.player.elapsed_time_midpoint = self.player.in_round(self.round_number).elapsed_time class explanation_exampleRound(Page): form_model = 'player' def is_displayed(self): return self.round_number == 1 def vars_for_template(self): rightAnswers = 1 currentTime = self.player.in_round(self.round_number).elapsed_time_example return { "rightAnswers":rightAnswers, 'currentTime': currentTime, 'costs': currentTime*Constants.powerCostHigh, 'bonus': max(round(Constants.taskPayment-currentTime*Constants.powerCostHigh, 1),0), 'taskPayment': round(Constants.taskPayment, 1), 'penalty': Constants.penalty_mistake, } class ENDE(Page): form_model = 'player' def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): midRound = int(Constants.num_rounds/2) self.player.ENDE_time_epoch = time.time() rightAnswers = self.player.in_round(self.round_number).rightAnswers currentTime = self.player.in_round(self.round_number).elapsed_time if self.player.in_round(midRound).investChoice==2: payout = max(Constants.num_rounds* round(Constants.taskPayment, 2)-currentTime*Constants.powerCostHigh, 0) cost10= self.player.in_round(midRound).elapsed_time_midpoint*Constants.powerCostHigh cost20= (currentTime-self.player.in_round(midRound).elapsed_time_midpoint)*Constants.powerCostHigh else: payout = max(Constants.num_rounds* round(Constants.taskPayment, 2) -self.player.in_round(midRound).elapsed_time_midpoint*Constants.powerCostHigh - (currentTime-self.player.in_round(midRound).elapsed_time_midpoint)*Constants.powerCostLow-self.player.in_round(midRound).efficiencyInvest, 0) cost10 = self.player.in_round(midRound).elapsed_time_midpoint*Constants.powerCostHigh cost20 = (currentTime - self.player.in_round(midRound).elapsed_time_midpoint)*Constants.powerCostLow if self.player.in_round(midRound).investChoice==1: invest = self.player.in_round(midRound).efficiencyInvest else: invest = 0 self.player.payout = payout return { "rightAnswers":round(rightAnswers,0), 'currentTime': currentTime, 'timeRound10': self.player.in_round(midRound).elapsed_time_midpoint, 'timeRound20': (currentTime-self.player.in_round(midRound).elapsed_time_midpoint), 'payout': round(payout, 1), 'payoutGBP': round(payout/100, 2), 'cost10': round(cost10, 1), 'cost20': round(cost20, 1), 'invest': round(invest,1), 'half_round': int(Constants.num_rounds/2), } class controlQuestions(Page): form_model = 'player' def is_displayed(self): return self.round_number == Constants.num_rounds form_fields = ["investKnow", "patience", "altruism", "risk", "awareness", "attention", "impulsive", "efficiency", "savings"] class Metadaten2(Page): form_model = 'player' def is_displayed(self): return self.round_number == Constants.num_rounds form_fields = ["Geschlecht", "Alter", "Hoechste_berufliche_Qualifikation", "Erwerbsstatus", "Einkommen", "FinalFeedback", "screenshots"] class AttentionCheckFailed(Page): def is_displayed(self): return self.player.field_maybe_none('attention') != 1 page_sequence = [ErklaerungConsent, realEffortTaskSeconds_example, explanation_exampleRound, realEffortTaskSeconds, ErklaerungRegulierung, controlQuestions, Metadaten2, ENDE] #page_sequence = [ErklaerungConsent, realEffortTask, ENDE] #page_sequence = [Full, ErklaerungConsent, objectives, behavioralControl, expertise, effectiveness, trust, AttentionCheckFailed, userSatisfaction, ErklaerungRegulierung, trust2, Metadaten2, ENDE]