from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random class Wait(WaitPage): group_by_arrival_time = True players_per_group = 3 def after_all_players_arrive(self): # if self.group.treatment == 'None': # Retrieve the condition assignments from each participant so far conditions_so_far = [] for g in self.subsession.get_groups(): conditions_so_far.append(g.treatment) # Count how often each condition has been run conditions_n = {} for c in Constants.conditions: conditions_n[c] = conditions_so_far.count(c) # Create a new array containing the conditions that have been run the least amount of times conditions = [] for c, n in conditions_n.items(): if n == min(conditions_n.values()): conditions.append(c) # Randomly assign the participant to one of these conditions temp = random.choice(conditions) self.group.treatment = temp # if temp == 'Treatment D': # for p in self.group.get_players(): # p.is_4 = 1 # else: # for p in self.group.get_players(): # p.is_4 = 0 # else: # pass class Main(Page): form_model = 'player' form_fields = ['click'] def vars_for_template(self): if self.group.treatment == "A": link = "https://nativeadsyt3.s3.us-east-2.amazonaws.com/finished+2.mp4" # elif self.group.treatment == "AB": # link = "http://s3.amazonaws.com/wpll/short-video.mp4" # elif self.group.treatment == "BA": # link = "http://s3.amazonaws.com/wpll/short-video.mp4" else: link = "https://nativeadsyt3.s3.us-east-2.amazonaws.com/condition_B2.mp4" return {'link': link} class Results(Page): pass class Q1(Page): pass class Q2(Page): form_model = 'player' form_fields = ['diff_num', 'diff'] class VideoQ(Page): form_model = 'player' form_fields = ['game_live', 'game_freq', 'ads_notice', 'ads_recall', 'ads_intention', 'ads_wtp', 'ads_eval', 'interest_game'] class Demog(Page): form_model = 'player' form_fields = ['age', 'gender', 'race', 'income', 'feedback'] page_sequence = [ Wait, Main, Q1, Q2, VideoQ, Demog, Results ]