from otree.api import * import math import pandas as pd import itertools import numpy as np import random class C(BaseConstants): NAME_IN_URL = 'task1' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 SVO_TEMPLATE = 'svo/templates/svo_.html' RULES_TEMPLATE = 'svo/templates/rules.html' A = 23 B = 0.25 SVO_VALUES = pd.read_csv("svo/svo_values.csv") class Subsession(BaseSubsession): pass def shuffle_list(co_players): randomized_list = co_players[:] while True: random.shuffle(randomized_list) for a, b in zip(co_players, randomized_list): if a == b: break else: return randomized_list def creating_session(subsession): roles_svo = itertools.cycle(["B", "A"]) players = subsession.get_players() for player in players: player.role_svo = next(roles_svo) player.internal_id = player.participant_id player.payoff_task1 = 0 player.participant.payoff_task1 = 0 player.participant.role_svo = player.role_svo player.participant.self_option_task_1 = 0 player.participant.other_option_task_1 = 0 player.participant.self_payoff_task_1 = 0 player.participant.other_payoff_task_1 = 0 class Group(BaseGroup): pass class Player(BasePlayer): you1 = models.IntegerField() you2 = models.IntegerField() you3 = models.IntegerField() you4 = models.IntegerField() you5 = models.IntegerField() you6 = models.IntegerField() other1 = models.IntegerField() other2 = models.IntegerField() other3 = models.IntegerField() other4 = models.IntegerField() other5 = models.IntegerField() other6 = models.IntegerField() svo_idx = models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8], widget=widgets.RadioSelect) role_svo = models.StringField() co_player_svo = models.IntegerField() internal_id = models.IntegerField() payoff_task1 = models.FloatField(initial = 0) def pickOptions(self): random_pick = np.random.randint(0, 6) self_picks = [self.you1, self.you2, self.you3, self.you4, self.you5, self.you6] other_picks = [self.other1, self.other2, self.other3, self.other4, self.other5, self.other6] self.participant.self_option_task_1 = random_pick + 1 self.participant.other_option_task_1 = random_pick + 1 self.participant.self_payoff_task_1 = self_picks[random_pick] self.participant.other_payoff_task_1 = other_picks[random_pick] # def setPayoffs(self): # random_pick = np.random.randint(0, 6) # if self.role_svo == "A": # self_picks = [self.you1, self.you2, self.you3, self.you4, self.you5, self.you6] # self.payoff_task1 += self_picks[random_pick] # self.participant.payoff_task1 = np.round(self.payoff_task1, 2) # self.participant.self_option_task_1 = random_pick + 1 # self.participant.self_payoff_task_1 = self_picks[random_pick] # else: # other_players = self.get_others_in_subsession() # for p in other_players: # if p.role_svo == "A" and p.field_maybe_none("you1") is not None: # other_picks = [p.other1, p.other2, p.other3, p.other4, p.other5, p.other6] # self.payoff_task1 += other_picks[random_pick] # p.participant.payoff_task1 = np.round(p.payoff_task1, 2) # p.participant.self_option_task_1 = random_pick + 1 # if self.payoff_task1 == 0: # self_picks = [self.you1, self.you2, self.you3, self.you4, self.you5, self.you6] # self.payoff_task1 += self_picks[random_pick] # self.participant.payoff_task1 = np.round(self.payoff_task1, 2) # self.participant.self_option_task_1 = random_pick + 1 # self.participant.self_payoff_task_1 = self_picks[random_pick] # def setPayoffs(self): # co_player = self.get_others_in_subsession()[0] # random_pick = np.random.randint(0, 6) # self_picks = [self.you1, self.you2, self.you3, self.you4, self.you5, self.you6] # other_picks = [self.other1, self.other2, self.other3, self.other4, self.other5, self.other6] # if self.role_svo == "active": # self.payoff_task1 += self_picks[random_pick] # co_player.payoff_task1 += other_picks[random_pick] # self.participant.payoff_task1 = np.round(self.payoff_task1, 2) # co_player.participant.payoff_task1 = np.round(co_player.payoff_task1, 2) # # self.participant.self_option_task_1 = random_pick + 1 # co_player.participant.received_option_task_1 = random_pick + 1 # self.participant.self_payoff_task_1 = self_picks[random_pick] # co_player.participant.received_payoff_task_1 = other_picks[random_pick] def make_question_html(values): html = "" for v in values: html += f"