from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'svo' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): al1 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9']], widget=widgets.RadioSelect) al2 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9']], widget=widgets.RadioSelect) al3 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9']], widget=widgets.RadioSelect) al4 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9']], widget=widgets.RadioSelect) al5 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9']], widget=widgets.RadioSelect) al6 = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9']], widget=widgets.RadioSelect) score = models.FloatField() orientation = models.StringField() def svoscore(player: Player): alloc = [[85,85,85,15,50,100,50,100,100,50,100,50], [85,76,87,19,54,98,54,89,94,56,98,54], [85,68,89,24,59,96,59,79,88,63,96,59], [85,59,91,28,63,94,63,68,81,69,94,63], [85,50,93,33,68,93,68,58,75,75,93,68], [85,41,94,37,72,91,72,47,69,81,91,72], [85,33,96,41,76,89,76,36,63,88,89,76], [85,24,98,46,81,87,81,26,56,94,87,81], [85,15,100,50,85,85,85,15,50,100,85,85]] jtable = [player.al1,player.al2,player.al3,player.al4,player.al5,player.al6] sum1 = 0 sum2 = 0 for i in range(0, 6): sum1 = sum1 + alloc[jtable[i] - 1][2 * (i)] sum2 = sum2 + alloc[jtable[i] - 1][2 * (i) + 1] mean1 = sum1 / 6 - 50 mean2 = sum2 / 6 - 50 import math return math.atan(mean2 / mean1) * 180 / math.pi class Svo(Page): form_model = 'player' form_fields = ['al1', 'al2', 'al3', 'al4', 'al5', 'al6'] @staticmethod def js_vars(player: Player): # these are from the test.csv file alloc = [[85,85,85,76,85,68,85,59,85,50,85,41,85,33,85,24,85,15], [85,15,87,19,89,24,91,28,93,33,94,37,96,41,98,46,100,50], [50,100,54,98,59,96,63,94,68,93,72,91,76,89,81,87,85,85], [50,100,54,89,59,79,63,68,68,58,72,47,76,36,81,26,85,15], [100,50,94,56,88,63,81,69,75,75,69,81,63,88,56,94,50,100], [100,50,98,54,96,59,94,63,93,68,91,72,89,76,87,81,85,85]] return dict( alloc = alloc ) @staticmethod def before_next_page(player: Player, timeout_happened): player.score = svoscore(player) class Results(Page): form_model = 'player' @staticmethod def vars_for_template(player: Player): if player.score >= 57.15: player.orientation = 'altruistic' if player.score >= 22.45 and player.score < 57.15: player.orientation = 'prosocial' if player.score >= -12.04 and player.score < 22.45: player.orientation = 'individualistic' if player.score < -12.04: player.orientation = 'competitive' return dict( orientation = player.orientation ) page_sequence = [Svo, Results]