## I think that to fix this I need to have the different investment options onthe screen, but not ## as fields within a Integer field. In other words, I think that it's not liking having to change ## the integer field options every time, and that's why it's glitching. I think that ## I can just have the options be a character field as option 1 and option 2, and then display the ## actual contents of the option on the screen in the same way that I did it with the N-back task. from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random import pandas as pd import itertools import numpy as np from sklearn.utils import shuffle doc = """ This is my rendition of the ultimatum game, hopefully it works """ # This is the function I use to determine if offer was accepted or not def response(p): return True if random.random() < p else False all_combos1 = np.array(list(itertools.combinations(range(0, 21, 2), 2))) all_combos2 = np.array(list(itertools.combinations(range(1, 21, 2), 2))) all_combos = (np.concatenate((all_combos1, all_combos2), axis=0)) # random.shuffle(all_combos) all_combos = shuffle(all_combos) for ss in range(0, len(all_combos)): if random.random() > 0.5: all_combos[ss] = all_combos[ss, np.random.permutation(all_combos.shape[1])] class Constants(BaseConstants): name_in_url = 'my_dictator' players_per_group = None # num_rounds must be divisible by the number of opponents num_rounds = 96 instructions_template = 'my_dictator/Instructions.html' endowment = c(20) payoff_if_rejected = c(0) offer_increment = c(1) offer_choices = currency_range(0, endowment, offer_increment) # all_combos1 = np.array(list(itertools.combinations(range(0, 21, 2), 2))) # all_combos2 = np.array(list(itertools.combinations(range(1, 21, 2), 2))) # # all_combos = (np.concatenate((all_combos1, all_combos2), axis=0)) # random.shuffle(all_combos) # # all_combos = list(all_combos) offer_choices_count = len(offer_choices) keep_give_amounts = [] for offer in offer_choices: keep_give_amounts.append((offer, endowment - offer)) opponent = "triangle", "circle", "square" opponentb1 = list(opponent*(int((num_rounds/len(opponent))/2 ))) opponentb2 = list(opponent * (int((num_rounds / len(opponent)) / 2))) random.shuffle((opponentb1)) random.shuffle((opponentb2)) opponent = opponentb1+opponentb2 # these probabilities are directly from behavioral data of responders opponent_dict = dict(triangle = [0.0707, 0.1032, 0.1482, 0.2083, 0.2846, 0.3757, 0.4764, 0.5791, 0.6754, 0.7589, 0.8264, 0.8780, 0.9159, 0.9427, 0.9614, 0.9741, 0.9827, 0.9885, 0.9924, 0.9949, 0.9967], circle = [0.2844, 0.3839, 0.4942, 0.6051, 0.7061, 0.7902, 0.8552, 0.9026, 0.9356, 0.9579, 0.9728, 0.9825, 0.9887, 0.9928, 0.9954, 0.9971, 0.9981, 0.9988, 0.9992, 0.9995, 0.9997], square = [0.8268, 0.8855, 0.9261, 0.9530, 0.9705, 0.9816, 0.9885, 0.9929, 0.9956, 0.9973, 0.9983, 0.9990, 0.9994, 0.9996, 0.9998, 0.9998, 0.9999, 0.9999, 1.0000, 1.0000, 1.0000]) class Subsession(BaseSubsession): pass class Group(BaseGroup): option1 = models.IntegerField() option2 = models.IntegerField() amount_offered = models.IntegerField() option_chosen = models.CharField(widget=widgets.RadioSelectHorizontal(), choices=("Option 1", "Option 2")) current_opponent = models.CharField() payout = models.IntegerField() soc_or_no = models.CharField() # amount_offered= models.IntegerField() def set_responder_identity(self): self.current_opponent = Constants.opponent[self.round_number-1] self.round_number = self.round_number self.option1 = all_combos[self.round_number - 1][0] self.option2 = all_combos[self.round_number - 1][1] offer_accepted = models.BooleanField() def set_payoffs(self): # self.option1 = Constants.all_combos[self.round_number-1][0] # self.option2 = Constants.all_combos[self.round_number-1][1] if self.option_chosen == "Option 1": self.amount_offered = self.option1 elif self.option_chosen == "Option 2": self.amount_offered = self.option2 Player.payoff = Constants.endowment - self.amount_offered self.payout = Constants.endowment - self.amount_offered # self.offer_accepted = response(Constants.opponent_dict[self.current_opponent][int(self.amount_offered)]) # # if self.offer_accepted: # Player.payoff = Constants.endowment - self.amount_offered # self.payout = Constants.endowment - self.amount_offered # else: # Player.payoff = Constants.payoff_if_rejected # self.payout = Constants.payoff_if_rejected class Player(BasePlayer): trial_to_pay = models.IntegerField() amount_earned_on_dictator = models.IntegerField() def round_to_pay(self): self.round_list = range(1, self.round_number + 1) self.payout_chosen_trial = shuffle(self.round_list) # self.participant.vars['payout_chosen_trial'] = self.payout_chosen_trial[0] self.participant.vars['payout_chosen_trial'] = random.choice(range(1, self.round_number + 1)) self.trial_to_pay = self.participant.vars['payout_chosen_trial'] self.participant.vars['payout_dictator'] = self.group.in_round(self.trial_to_pay).payout self.amount_earned_on_dictator = self.participant.vars['payout_dictator'] test_question_1 = models.CharField( choices=('TRUE', 'FALSE'), widget=widgets.RadioSelect() ) test_question_2 = models.CharField( choices=('TRUE', 'FALSE'), widget=widgets.RadioSelect() ) test_question_3 = models.CharField( choices=('TRUE', 'FALSE'), widget=widgets.RadioSelect() ) test_question_4 = models.CharField( choices=('TRUE', 'FALSE'), widget=widgets.RadioSelect() )