from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Introduction(Page): form_model = 'player' form_fields = ['test_1', 'test_2', 'test_3'] def is_displayed(self): return self.round_number == 1 def error_message(self, value): bb = value['test_1'] + value['test_2'] + value['test_3'] if bb != 3: self.participant.vars['test_tries'] = self.participant.vars['test_tries'] + 1 self.player.test_tries = self.participant.vars['test_tries'] self.participant.vars['test_1'] = value['test_1'] self.participant.vars['test_2'] = value['test_2'] self.participant.vars['test_3'] = value['test_3'] return "您给出的答案至少有一个不正确。请您认真阅读下方提示并确定理解任务。" def vars_for_template(self): pp = (35, 25, 40) oo_1 = (20, 40, 70) oo_2 = (30, 70, 50) fields_from, fields_to = Constants.fields(pp)[0], Constants.fields(pp)[1] pp_2 = (15, 80, 5) oo_1_2 = (20, 30, 150) oo_2_2 = (70, 40, 50) fields_from_2, fields_to_2 = Constants.fields(pp_2)[0], Constants.fields(pp_2)[1] error = 0 if self.participant.vars['test_tries'] > 0: error = 1 return dict( pp=pp, oo_1=oo_1, oo_2=oo_2, fields=zip(fields_from, fields_to, pp), explain=zip(fields_from, fields_to, pp, oo_1, oo_2), pp_2=pp_2, oo_1_2=oo_1_2, oo_2_2=oo_2_2, fields_2=zip(fields_from_2, fields_to_2, pp_2), error=error, test_1=self.participant.vars['test_1'], test_2=self.participant.vars['test_2'], test_3=self.participant.vars['test_3'], ) class passed(Page): def is_displayed(self): return self.round_number == 1 class Feedback(Page): def is_displayed(self): return self.participant.vars['features'][self.round_number][0] == 'Feedback' def vars_for_template(self): game = self.participant.vars['games'][self.round_number] A_skewed = self.participant.vars['choice_dict'][self.round_number]['A_skewed'] pos = self.participant.vars['choice_dict'][self.round_number]['pos'] pp, ppp, oo_1, oo_2 = list(), list(), list(), list() sum_fields = 0 for i in range(len(game)): sum_fields = sum_fields + game[i][0] for i in range(len(game)): pp.append(round((game[i][0]/sum_fields)*100, 1)) ppp.append(game[i][0]) oo_1.append(game[i][pos[0]]) oo_2.append(game[i][pos[1]]) fields_from, fields_to = Constants.fields(ppp)[0], Constants.fields(ppp)[1] skewed = self.participant.vars['choice_dict'][self.round_number]['skewed'] payoff_A, payoff_B = 0, 0 if skewed == 1: n_skewed = 0 else: n_skewed = 1 if A_skewed == skewed: chosen_option = 'A' checked_A = 'checked' checked_B = '' payoff_A = self.participant.vars['possible_payoffs_dict'][self.round_number][skewed] payoff_B = self.participant.vars['possible_payoffs_dict'][self.round_number][n_skewed] else: chosen_option = 'B' checked_B = 'checked' checked_A = '' payoff_B = self.participant.vars['possible_payoffs_dict'][self.round_number][skewed] payoff_A = self.participant.vars['possible_payoffs_dict'][self.round_number][n_skewed] return dict( pp=pp, oo_1=zip(oo_1, fields_from, fields_to), oo_2=zip(oo_2, fields_from, fields_to), treatment=self.participant.vars['treatment'], fields=zip(fields_from, fields_to, pp), fields_from=fields_from, fields_to=fields_to, payoff=self.participant.vars['possible_payoffs_dict'][self.round_number][self.participant.vars['choice_dict'][self.round_number]['skewed']], skewed=skewed, chosen_option=chosen_option, realized_field=self.participant.vars['realized_field_dict'][self.round_number], checked_A=checked_A, checked_B=checked_B, payoff_A=payoff_A, payoff_B=payoff_B, ) class help(Page): def vars_for_template(self): games = self.participant.vars['games'] ABC = self.participant.vars['ABC'] h2 = self.participant.vars['h2'] a2 = self.participant.vars['a2'] features = self.participant.vars['features'] return dict( games=games, ABC=ABC, h2=h2, a2=a2, features=features ) class MyPage(Page): form_model = 'player' form_fields = ['skewed'] def vars_for_template(self): games = self.participant.vars['games'] game = self.participant.vars['games'][self.round_number] self.participant.vars['choice_dict'][self.round_number] = dict() self.participant.vars['choice_dict'][self.round_number]['game'] = game pp, ppp, oo_1, oo_2, state_order = list(), list(), list(), list(), list() import random # randomizes whether skewed option is bottom or top. pos[0]=2 means skewed is top pos = [1, 2] random.shuffle(pos) self.participant.vars['choice_dict'][self.round_number]['pos'] = pos if pos[0] == 2: option_a = 1 option_b = 0 self.participant.vars['choice_dict'][self.round_number]['A_skewed'] = 1 elif pos[0] == 1: option_a = 0 option_b = 1 self.participant.vars['choice_dict'][self.round_number]['A_skewed'] = 0 sum_fields = 0 for i in range(len(game)): sum_fields = sum_fields + game[i][0] for i in range(len(game)): pp.append(round((game[i][0]/sum_fields)*100, 1)) ppp.append(game[i][0]) oo_1.append(game[i][pos[0]]) oo_2.append(game[i][pos[1]]) state_order.append([oo_1[i], oo_2[i]]) self.player.state_order = str(state_order) fields_from, fields_to = Constants.fields(ppp)[0], Constants.fields(ppp)[1] ff = self.participant.vars['features'][self.round_number] if self.participant.vars['treatment'] == 'clean': tt = 'CEO' elif self.participant.vars['treatment'] == 'confound': tt = 'CEESE' tr_1 = self.participant.vars['features'][self.round_number][0] return dict( pp=pp, oo_1=oo_1, oo_2=oo_2, treatment=self.participant.vars['treatment'], fields=zip(fields_from, fields_to, pp), fields_from=fields_from, fields_to=fields_to, option_a=option_a, option_b=option_b, ff=ff, tt=tt, tr_1=tr_1, correlation = self.participant.vars['features'][self.round_number][2], part=self.participant.vars['features'][self.round_number][0], skewed_A=self.participant.vars['choice_dict'][self.round_number]['A_skewed'] ) def before_next_page(self): self.participant.vars['choice_dict'][self.round_number]['skewed'] = self.player.skewed ff = self.participant.vars['features'][self.round_number] self.player.part = self.participant.vars['features'][self.round_number][0] self.player.lottery_nr = self.participant.vars['features'][self.round_number][1] self.player.correlation = self.participant.vars['features'][self.round_number][2] self.player.z = self.participant.vars['features'][self.round_number][3] self.player.A_skewed = self.participant.vars['choice_dict'][self.round_number]['A_skewed'] if self.round_number == Constants.num_rounds: possible_payoff = self.participant.vars['possible_payoff'] payoff_relevant = self.participant.vars['payoff_relevant'] skewed = self.participant.vars['choice_dict'][payoff_relevant]['skewed'] payoff = possible_payoff[skewed] self.player.payoff = payoff self.participant.vars['payoff'] = payoff self.player.choice_dict = str(self.participant.vars['choice_dict']) class FeedbackStart(Page): def is_displayed(self): return self.round_number == Constants.num_rounds_nf + 1 class Survey(Page): def is_displayed(self): return self.round_number == Constants.num_rounds form_model = 'player' form_fields = ['Columns', 'Rows', 'Probas', 'EV', 'open_end'] def vars_for_template(self): pp = (35, 25, 40) oo_1 = (20, 40, 70) oo_2 = (30, 70, 50) fields_from, fields_to = Constants.fields(pp)[0], Constants.fields(pp)[1] pp_2 = (15, 80, 5) oo_1_2 = (20, 30, 150) oo_2_2 = (70, 40, 50) fields_from_2, fields_to_2 = Constants.fields(pp_2)[0], Constants.fields(pp_2)[1] return dict( pp=pp, oo_1=oo_1, oo_2=oo_2, fields=zip(fields_from, fields_to, pp), explain=zip(fields_from, fields_to, pp, oo_1, oo_2), pp_2=pp_2, oo_1_2=oo_1_2, oo_2_2=oo_2_2, fields_2=zip(fields_from_2, fields_to_2, pp_2), test_1=self.participant.vars['test_1'], test_2=self.participant.vars['test_2'], test_3=self.participant.vars['test_3'], ) page_sequence = [Introduction, passed, FeedbackStart, MyPage, Feedback, Survey]