from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants #class Introduction(Page): #timeout_seconds = 100 class Intro(WaitPage): wait_for_all_groups = True # class IntroMatch(Page): # def is_displayed(self): # return self.round_number in [1] class DecisionGuess(Page): def is_displayed(self): return self.round_number in [1] form_model = 'player' form_fields = ['decision_guess'] def before_next_page(self): if self.round_number == 1: self.participant.vars['decision_guess_task2_m1_r1'] = self.player.decision_guess self.player.decision_guess_task2_m1_r1 = str(self.participant.vars['decision_guess_task2_m1_r1']) else: pass class Decision(Page): form_model = 'player' form_fields = ['decision'] def is_displayed(self): if self.round_number <= self.subsession.num_last_round: return True else: return False def before_next_page(self): if self.round_number == 1: if self.player.decision == 1: self.participant.vars['decision_task2_m1_r1'] = int(1) self.participant.vars['decision_task2_type_m1_r1'] = str("X") else: self.participant.vars['decision_task2_m1_r1'] = int(0) self.participant.vars['decision_task2_type_m1_r1'] = str("Y") self.participant.vars['group_id_task2_m1_r1'] = self.group.id_in_subsession self.player.decision_task2_m1_r1 = int(self.participant.vars['decision_task2_m1_r1']) self.player.decision_type = str(self.participant.vars['decision_task2_type_m1_r1']) print(self.participant.vars) elif self.round_number == 2: if self.player.decision == 1: self.participant.vars['decision_task2_m1_r2'] = int(1) self.participant.vars['decision_task2_type_m1_r2'] = str("X") else: self.participant.vars['decision_task2_m1_r2'] = int(0) self.participant.vars['decision_task2_type_m1_r2'] = str("Y") self.player.decision_task2_m1_r2 = int(self.participant.vars['decision_task2_m1_r2']) self.player.decision_type = str(self.participant.vars['decision_task2_type_m1_r2']) elif self.round_number == 3: if self.player.decision == 1: self.participant.vars['decision_task2_m1_r3'] = int(1) self.participant.vars['decision_task2_type_m1_r3'] = str("X") else: self.participant.vars['decision_task2_m1_r3'] = int(0) self.participant.vars['decision_task2_type_m1_r3'] = str("Y") self.player.decision_task2_m1_r3 = int(self.participant.vars['decision_task2_m1_r3']) self.player.decision_type = str(self.participant.vars['decision_task2_type_m1_r3']) elif self.round_number == 4: if self.player.decision == 1: self.participant.vars['decision_task2_m1_r4'] = int(1) self.participant.vars['decision_task2_type_m1_r4'] = str("X") else: self.participant.vars['decision_task2_m1_r4'] = int(0) self.participant.vars['decision_task2_type_m1_r4'] = str("Y") self.player.decision_task2_m1_r4 = int(self.participant.vars['decision_task2_m1_r4']) self.player.decision_type = str(self.participant.vars['decision_task2_type_m1_r4']) elif self.round_number == 5: if self.player.decision == 1: self.participant.vars['decision_task2_m1_r5'] = int(1) self.participant.vars['decision_task2_type_m1_r5'] = str("X") else: self.participant.vars['decision_task2_m1_r5'] = int(0) self.participant.vars['decision_task2_type_m1_r5'] = str("Y") self.player.decision_task2_m1_r5 = int(self.participant.vars['decision_task2_m1_r5']) self.player.decision_type = str(self.participant.vars['decision_task2_type_m1_r5']) else: if self.player.decision == 1: self.participant.vars['decision_task2_m1_r6'] = int(1) self.participant.vars['decision_task2_type_m1_r6'] = str("X") else: self.participant.vars['decision_task2_m1_r6'] = int(0) self.participant.vars['decision_task2_type_m1_r6'] = str("Y") self.player.decision_task2_m1_r6 = int(self.participant.vars['decision_task2_m1_r6']) self.player.decision_type = str(self.participant.vars['decision_task2_type_m1_r6']) # class ResultsWaitPage2(WaitPage): # after_all_players_arrive = 'set_cooprates' class ResultsWaitPage1(WaitPage): wait_for_all_groups = True def is_displayed(self): if self.round_number <= self.subsession.num_last_round: return True else: return False class ResultsWaitPage2(WaitPage): after_all_players_arrive = 'set_payoffs' def is_displayed(self): if self.round_number <= self.subsession.num_last_round: return True else: return False class Results(Page): timeout_seconds = 10 def is_displayed(self): if self.round_number <= self.subsession.num_last_round: return True else: return False def vars_for_template(self): self.player.round_number = self.round_number me = self.player opponent = me.other_player() return dict( my_decision=me.decision_type, opponent_decision=opponent.decision_type, same_choice=me.decision_type == opponent.decision_type, round_number=me.round_number, cont_value_r1=me.cont_value_r1, cont_value_r2=me.cont_value_r2, cont_value_r3=me.cont_value_r3, cont_value_r4=me.cont_value_r4, cont_value_r5=me.cont_value_r5, cont_value_r6=me.cont_value_r6, ) def before_next_page(self): if self.round_number == 1: self.player.participant.vars['payoff_task2_int_m1_r1'] = int(self.player.payoff_int) self.player.total_coop_s1_task2_m1_r1 = sum([p.decision for p in self.subsession.get_players() if p.role() == '1']) self.player.total_coop_s2_task2_m1_r1 = sum([p.decision for p in self.subsession.get_players() if p.role() == '2']) self.player.total_coop_s3_task2_m1_r1 = sum([p.decision for p in self.subsession.get_players() if p.role() == '3']) self.player.total_coop_s4_task2_m1_r1 = sum([p.decision for p in self.subsession.get_players() if p.role() == '4']) # self.player.coop_rate_s1_task2_m1_r1 = int(self.player.total_coop_s1_task2_m1_r1 / # Constants.players_per_supergroup*100) # self.player.coop_rate_s2_task2_m1_r1 = int(self.player.total_coop_s2_task2_m1_r1 / # Constants.players_per_supergroup*100) # self.player.coop_rate_s3_task2_m1_r1 = int(self.player.total_coop_s3_task2_m1_r1 / # Constants.players_per_supergroup*100) # self.player.coop_rate_s4_task2_m1_r1 = int(self.player.total_coop_s4_task2_m1_r1 / # Constants.players_per_supergroup*100) if self.player.supergroup_task2 == '1': self.participant.vars['total_coop_task2_m1_r1'] = self.player.total_coop_s1_task2_m1_r1 #self.player.participant.vars['cooprate_task2_m1_r1'] = self.player.coop_rate_s1_task2_m1_r1 elif self.player.supergroup_task2 == '2': self.player.participant.vars['total_coop_task2_m1_r1'] = self.player.total_coop_s2_task2_m1_r1 #self.participant.vars['cooprate_task2_m1_r1'] = self.player.coop_rate_s2_task2_m1_r1 elif self.player.supergroup_task2 == '3': self.player.participant.vars['total_coop_task2_m1_r1'] = self.player.total_coop_s3_task2_m1_r1 #self.participant.vars['cooprate_task2_m1_r1'] = self.player.coop_rate_s3_task2_m1_r1 else: self.player.participant.vars['total_coop_task2_m1_r1'] = self.player.total_coop_s4_task2_m1_r1 #self.participant.vars['cooprate_task2_m1_r1'] = self.player.coop_rate_s4_task2_m1_r1 self.player.total_coop_task2_m1_r1 = self.player.participant.vars['total_coop_task2_m1_r1'] #self.player.cooprate_task2_m1_r1 = self.player.participant.vars['cooprate_task2_m1_r1'] print(self.participant.vars) elif self.round_number == 2: self.player.participant.vars['payoff_task2_int_m1_r2'] = int(self.player.payoff_int) elif self.round_number == 3: self.player.participant.vars['payoff_task2_int_m1_r3'] = int(self.player.payoff_int) elif self.round_number == 4: self.player.participant.vars['payoff_task2_int_m1_r4'] = int(self.player.payoff_int) elif self.round_number == 5: self.player.participant.vars['payoff_task2_int_m1_r5'] = int(self.player.payoff_int) else: self.player.participant.vars['payoff_task2_int_m1_r6'] = int(self.player.payoff_int) print(self.participant.vars) class FinalResults(Page): timeout_seconds = 10 def is_displayed(self): if self.round_number == self.subsession.num_last_round: return True else: return False def vars_for_template(self): self.player.cum_payoff = sum([p.payoff for p in self.player.in_rounds(1, self.subsession.num_last_round)]) self.player.cum_payoff_int = sum([p.payoff_int for p in self.player.in_rounds(1, self.subsession.num_last_round)]) self.player.participant.vars['cum_payoff_task2_m1'] = self.player.cum_payoff self.player.participant.vars['cum_payoff_task2_int_m1'] = int(self.player.cum_payoff_int) self.player.participant.vars['task2_m1_length'] = int(self.subsession.num_last_round) return {'last_round': self.player.last_round, 'cum_payoff_int': self.player.cum_payoff_int } page_sequence = [ Intro, #IntroMatch, DecisionGuess, Decision, ResultsWaitPage1, ResultsWaitPage2, Results, FinalResults ]