from . import models from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants #from threading import Timer class Introduction(Page): """Description of the game: How to play and returns expected""" def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return { # 'experiment_name': self.session.vars['experimentName'] 'experiment_name': "PGG 2" } class Demographics(Page): form_model = 'player' form_fields = ['age', 'gender'] def is_displayed(self): return self.round_number == 1 class Contribute(Page): """Player: Choose how much to contribute""" form_model = 'player' form_fields = ['contribution'] + ['punish_{}'.format(i) for i in range(1, 5)] + \ ['reward_{}'.format(i) for i in range(1, 5)] timeout_submission = {'contribution': c(Constants.endowment / 2)} def error_message(self, values): for i in range(1, 5): if (values['punish_{}'.format(i)]) and (values['reward_{}'.format(i)]): return 'You can either punish or reward a player' def vars_for_template(self): return { 'round_num': self.round_number, # 'experiment_name': self.session.vars['experimentName'], 'experiment_name': "PGG 2", 'length': "xxxxxxxxxxxx" } class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() body_text = "Waiting for other participants to contribute." class GroupingWaitPage(WaitPage): group_by_arrival_time = True def is_displayed(self): return self.round_number == 1 # def get_players_for_group(self, waiting_players): # m_players = [p for p in waiting_players if p.participant.vars['gender'] == 'Male'] # f_players = [p for p in waiting_players if p.participant.vars['gender'] == 'Female'] # # #print(waiting_players) # for debugging # #print(m_players) # for debugging # #print(f_players) # for debugging # # if len(m_players) >= 2 and len(f_players) >= 2: # assortment = self.session.vars.get('assortment') # # if assortment == 0: # self.session.vars['assortment'] = 1 # return [m_players[0], m_players[1], f_players[0], f_players[1]] # elif assortment == 1: # self.session.vars['assortment'] = 0 # return [f_players[0], f_players[1], m_players[0], m_players[1]] # else: # print("there is a problem with the assortment") body_text = "Waiting for other participants to arrive." class Results(Page): """Players payoff: How much each has earned""" def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): return { 'total_earnings': self.group.total_contribution * Constants.multiplier, 'round_num': self.round_number, 'experiment_name': self.session.vars['experimentName'] } class Payoff(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): return { 'experiment_name': self.session.vars['experimentName'] } page_sequence = [ # Demographics, GroupingWaitPage, Introduction, Contribute, ResultsWaitPage, Results, Payoff ]