from otree.api import Currency as c, currency_range from . import models from ._builtin import Page, WaitPage from .models import Constants import random from random import shuffle import itertools from decimal import * def vars_for_all_templates(self): return { 'condition': self.participant.vars['condition'], } class IC(Page): form_model = models.Player form_fields = ['informed_consent'] def before_next_page(self): # See if that worker ID already appears in players, in which case they at least started the experiment mturk_check = models.Player.objects.filter( worker_id=self.participant.label) if not mturk_check: self.player.mturk_dupe = 0 else: self.player.mturk_dupe = 1 # Bring worker ID into player table/model for accessibility, which will be captured via the participant # label in the URL. Updating for this participant so that if they try again, they'll fail the dupe check. # Worker_Id has a default of 'e,' so for testing outside of MTurk just need to keep it at 'e' if there is no # participant label coming from the URL if not self.participant.label: self.player.worker_id = 'e' else: self.player.worker_id = self.participant.label # Also store condition in the player table just for ease of data analysis self.player.condition = self.participant.vars["condition"] class IC_Decline(Page): def is_displayed(self): return self.player.informed_consent == "No" class DuplicateWorker(Page): def is_displayed(self): return self.player.mturk_dupe == 1 class GenInstructions(Page): pass class TaskInstructions(Page): pass class KnowledgeCheck(Page): form_model = models.Player def get_form_fields(self): if self.player.condition == 1 or self.player.condition == 2: return ['kc1', 'kc2', 'kc3', 'kc4'] elif self.player.condition == 3 or self.player.condition == 4: return ['kc1', 'kc2', 'kc3', 'kc4', 'kc5', 'kc6'] def before_next_page(self): # Might as well pick a pay period on the way in pay_choice = (1, 2, 3, 4) self.participant.vars['pay_period'] = random.choice(pay_choice) class PreDecoding(Page): def vars_for_template(self): return { 'decode_strings': models.DecodeStrings.objects.filter(id__range=[1, 5]) } form_model = models.Player form_fields = ['practice_time'] page_sequence = [ IC, IC_Decline, DuplicateWorker, GenInstructions, TaskInstructions, KnowledgeCheck, PreDecoding ]