from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import csv class Constants(BaseConstants): name_in_url = 'business' players_per_group = 3 num_rounds = 3 instructions_template = 'nk_model/Instructions.html' with open('nk_model/payoffs.csv', encoding='utf-8') as payoff_file: payoffs = list(csv.DictReader(payoff_file)) class Subsession(BaseSubsession): pass class Group(BaseGroup): max_payoff = models.IntegerField() def set_payoffs(self): players = self.get_players() for p in players: p.choice1str = str(p.choice1) p.choice2str = str(p.choice2) p.choice3str = str(p.choice3) p.choices = p.choice1str + p.choice2str + p.choice3str for x in range(0, len(Constants.payoffs)): if Constants.payoffs[x]['choicestring'] == p.choices: p.choicespayoff = Constants.payoffs[x]['payoff'] p.choicespayoffint = int(p.choicespayoff) break payoffs = [p.choicespayoffint for p in players] max_payoff = max(payoffs) self.max_payoff = max_payoff class Player(BasePlayer): choice1 = models.IntegerField(label='Choice 1', choices=[[1, 'Yes'], [2, 'No']], widget=widgets.RadioSelectHorizontal) choice2 = models.IntegerField(label='Choice 2', choices=[[1, 'Yes'], [2, 'No']], widget=widgets.RadioSelectHorizontal) choice3 = models.IntegerField(label='Choice 3', choices=[[1, 'Yes'], [2, 'No']], widget=widgets.RadioSelectHorizontal) choice1str = models.StringField() choice2str = models.StringField() choice3str = models.StringField() choices = models.StringField() choicespayoff = models.StringField() choicespayoffint = models.IntegerField()