from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from random import randint class WTP(Page): def is_displayed(self): return self.player.id_in_group == 2 form_model = "player" form_fields = [ 'active1', 'active2', 'active3', 'active4', 'active5', ] def before_next_page(self): for p in self.subsession.get_players(): if p.id_in_group == 2: random_num = randint(1, 100) # randint是均匀分布吗?一直抽中4 if random_num <= 20: p.activeness = p.active1 p.activeness_chosen = 1 if random_num >=21 & random_num <=40: p.activeness = p.active2 p.activeness_chosen = 2 if random_num >= 41 & random_num <=60: p.activeness = p.active3 p.activeness_chosen = 3 if random_num >=61 & random_num <= 80: p.activeness = p.active4 p.activeness_chosen = 4 if random_num >= 81: p.activeness = p.active5 p.activeness_chosen = 5 class precision_choice(Page): def is_displayed(self): return self.player.id_in_group == 1 form_model = "player" form_fields = ['precision_choice'] def precision_choice_error_message(self, value): if value == None and self.player.id_in_group == 1: return 'Please make a choice' def before_next_page(self): #这里需要loop吗?对每个人都loop一次?? for p in self.subsession.get_players(): if p.id_in_group == 1: num_problem = randint(1, 100) if num_problem <= 50: self.player.problem = 0 else: self.player.problem = 1 #import pdb; pdb.set_trace() class diagnosis_wait_page(WaitPage): def after_all_players_arrive(self): for p in self.subsession.get_players(): if p.id_in_group == 1: p.diagnostic_result = p.problem random_result = randint(1, 100) if p.precision_choice == 0.5: if random_result <= 50: p.diagnostic_result = p.problem else: p.diagnostic_result = abs(p.problem - 1) if p.precision_choice == 0.6: if random_result <= 60: p.diagnostic_result = p.problem else: p.diagnostic_result = abs(p.problem - 1) if p.precision_choice == 0.7: if random_result <= 70: p.diagnostic_result = p.problem else: p.diagnostic_result = abs(p.problem - 1) if p.precision_choice == 0.8: if random_result <= 80: p.diagnostic_result = p.problem else: p.diagnostic_result = abs(p.problem - 1) if p.precision_choice == 0.9: if random_result <= 90: p.diagnostic_result = p.problem else: p.diagnostic_result = abs(p.problem - 1) if p.precision_choice == 1: p.diagnostic_result = p.problem player1 = self.group.get_player_by_role('player1') player2 = self.group.get_player_by_role('player2') player2.problem = player1.problem player2.precision_choice = player1.precision_choice player2.diagnostic_result = player1.diagnostic_result for p in self.subsession.get_players(): if p.id_in_group == 2: random_result = randint(1, 100) if random_result <= 60: p.private_signal = p.problem else: p.private_signal = abs(p.problem-1) class diagnostic_result(Page): def vars_for_template(self): return { 'precision': self.player.precision_choice, 'diagnostic_result': self.player.diagnostic_result, 'private_signal': self.player.private_signal } form_model = "player" form_fields = ['treatment_choice'] def treatment_choice_error_message(self, value): if value == None and self.player.id_in_group == 2: return 'Please make a choice' class payoff_wait_page(WaitPage): after_all_players_arrive = 'set_payoffs' class payoff(Page): def vars_for_template(self): return { 'payment': self.player.payment } page_sequence = [WTP, precision_choice, diagnosis_wait_page, diagnostic_result, payoff_wait_page, payoff]