from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class CustomWait(WaitPage): def is_displayed(self): return self.subsession.first_period class NewMatch(Page): def is_displayed(self): return self.subsession.first_period def vars_for_template(self): return { 'round': self.round_number, 'push': self.session.config['debug'], 'time': self.session.config['time'], 'cc': self.subsession.cc, 'dd': self.subsession.dd, 'cd': self.subsession.cd, 'dc': self.subsession.dc, 'delta': self.subsession.cutoff, } class Decision(Page): form_model = 'player' form_fields = ['action'] def vars_for_template(self): match_number = self.subsession.match_number match_list = [] for i in range(1, match_number + 1): match_list.append(str(i)) if self.round_number == 1: self.participant.vars['match_history'] = {} self.participant.vars['pd_points'] = 0 self.participant.vars['pd_dollars'] = 0 if self.subsession.period_number == 1: self.participant.vars['match_history'][match_number] = {} self.session.vars['match_to_game'][str(self.subsession.match_number)] = { 'payoffs': [self.subsession.cc, self.subsession.dd, self.subsession.cd, self.subsession.dc], 'cutoff': self.subsession.cutoff} return { 'match_to_game': self.session.vars['match_to_game'], 'deltas': self.session.vars['delta_dic'], 'games': self.session.vars['game_dic'], 'game': self.subsession.game, 'history': self.participant.vars['match_history'], 'current_match': str(match_number), 'match_number': match_number, 'match_list': match_list, 'period_number': self.subsession.period_number, 'cc': self.subsession.cc, 'dd': self.subsession.dd, 'cd': self.subsession.cd, 'dc': self.subsession.dc, 'delta': self.subsession.cutoff, 'round': self.round_number, 'push': self.session.config['debug'], 'time': self.session.config['time'], 'current_match_int': match_number, 'period_number_string': str(self.subsession.period_number), } class Wait(WaitPage): template_name = 'prisoners_dilemma/Wait.html' def vars_for_template(self): match_number = self.subsession.match_number match_list = [] for i in range(1, match_number + 1): match_list.append(str(i)) return { 'match_to_game': self.session.vars['match_to_game'], 'row': -1 * self.player.action+ 2, 'history': self.participant.vars['match_history'], 'current_match': str(match_number), 'match_number': match_number, 'match_list': match_list, 'period_number': self.subsession.period_number, 'cc': self.subsession.cc, 'dd': self.subsession.dd, 'cd': self.subsession.cd, 'dc': self.subsession.dc, 'delta': self.subsession.cutoff, 'round': self.round_number, 'push': self.session.config['debug'], 'time': self.session.config['time'], 'current_match_int': match_number, 'period_number_string': str(self.subsession.period_number), } class Wait1(WaitPage): template_name = 'prisoners_dilemma/Wait.html' wait_for_all_groups = True def vars_for_template(self): match_number = self.subsession.match_number match_list = [] for i in range(1, match_number + 1): match_list.append(str(i)) return { 'match_to_game': self.session.vars['match_to_game'], 'row': -1 * self.player.action + 2, 'history': self.participant.vars['match_history'], 'current_match': str(match_number), 'match_number': match_number, 'match_list': match_list, 'period_number': self.subsession.period_number, 'cc': self.subsession.cc, 'dd': self.subsession.dd, 'cd': self.subsession.cd, 'dc': self.subsession.dc, 'delta': self.subsession.cutoff, 'round': self.round_number, 'push': self.session.config['debug'], 'time': self.session.config['time'], 'current_match_int': match_number, 'period_number_string': str(self.subsession.period_number), } class WaitGroup(WaitPage): template_name = 'prisoners_dilemma/WaitGroup.html' wait_for_all_groups = True def vars_for_template(self): match_number = self.subsession.match_number match_list = [] for i in range(1, match_number + 1): match_list.append(str(i)) other = self.player.get_others_in_group() others_choice = other[0].action choice = self.player.action return { 'choice': choice, 'others_choice': others_choice, 'match_to_game': self.session.vars['match_to_game'], 'history': self.participant.vars['match_history'], 'current_match': str(match_number), 'match_number': match_number, 'match_list': match_list, 'period_number': self.subsession.period_number, 'cc': self.subsession.cc, 'dd': self.subsession.dd, 'cd': self.subsession.cd, 'dc': self.subsession.dc, 'delta': self.subsession.cutoff, 'round': self.round_number, 'push': self.session.config['debug'], 'time': self.session.config['time'], 'current_match_int': match_number, 'period_number_string': str(self.subsession.period_number), } class ResultsPage(Page): timeout_seconds = 5 def vars_for_template(self): self.player.set_points() players = self.group.get_players() match_number = self.subsession.match_number period_number = str(self.subsession.period_number) for p in players: j = p.get_others_in_group()[0] p.participant.vars['match_history'][match_number]['P' + period_number] = { 'match': match_number, 'period': period_number, 'action': -1 * p.action + 2, 'others_action': -1 * j.action + 2 } match_list = [] for i in range(1, match_number + 1): match_list.append(str(i)) other = self.player.get_others_in_group() others_choice = other[0].action choice = self.player.action dice_roll = self.subsession.dice_roll delta = self.subsession.cutoff if dice_roll > delta: gl = 'greater' terminate = "end" if self.subsession.match_number == self.session.config['num_blocks'] * self.session.config[ 'num_supergames']: click_to = 'Session Over: Click for Payoffs' else: click_to = 'Click to Start New Match' else: gl = 'not greater' terminate = "continue" click_to = 'Click to Start Next Round' return { 'match_to_game': self.session.vars['match_to_game'], 'current_match': str(match_number), 'match_number': match_number, 'match_list': match_list, 'period_number': self.subsession.period_number, 'history': self.participant.vars['match_history'], 'choice': choice, 'others_choice': others_choice, 'dice_roll': dice_roll, 'click_to': click_to, 'gl': gl, 'terminate': terminate, 'cc': self.subsession.cc, 'dd': self.subsession.dd, 'cd': self.subsession.cd, 'dc': self.subsession.dc, 'delta': delta, 'round': self.round_number, 'push': self.session.config['debug'], 'time': self.session.config['time'], 'current_match_int': match_number, 'period_number_string': str(self.subsession.period_number), } class Finished(Page): def is_displayed(self): return self.subsession.stop_session def vars_for_template(self): self.player.set_dollars() return { 'sh_game_ee': self.participant.vars['payment_stag_game'][0], 'sh_game_es': self.participant.vars['payment_stag_game'][1], 'sh_game_se': self.participant.vars['payment_stag_game'][2], 'sh_game_ss': self.participant.vars['payment_stag_game'][3], 'sh_points': self.participant.vars['sh_points'], 'sh_dollars': round(self.participant.vars['sh_points'] * self.session.config['sh_conversion'], 2), 'sh_action': self.participant.vars['payment_action'], 'sh_action_other': self.participant.vars['payment_action_other'], 'payment': self.participant.payoff_plus_participation_fee(), 'pd_points': self.participant.vars['pd_points'], 'pd_dollars': self.player.payoff, 'participation_fee': self.session.config['participation_fee'] } page_sequence = [ Finished, NewMatch, Decision, Wait1, ResultsPage, ]