from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) #from django.utils import translation #from django import http #from django.conf import settings import random from math import atan, degrees, sqrt, tan, pi from .utils import compute_line, intersection_point, distance, max_tuple import itertools import csv author = 'Luuk' doc = """ Your app description """ def read_csv(): with open('svo/SVO.csv', encoding='utf-8-sig') as f: return [ dict( round_number_svo=int(row['round_number_svo']), to_self=int(row['to_self']), to_other=int(row['to_other']), ) for row in csv.DictReader(f) ] def group_rows(): from collections import defaultdict d = defaultdict(list) for row in read_csv(): round_number_svo = row['round_number_svo'] d[round_number_svo].append(row) return d class Constants(BaseConstants): name_in_url = 'Questionnaires' players_per_group = None tasks = ["SVO", "SDO", "RuleFollowing", "CoinToss"] num_rounds = 34 CHART_TEMPLATE = 'svo/chart.html' ROWS = group_rows() NUM_ROUNDS_SVO = 15 # num_rounds = int(len(tasks) + 1) class Player(BasePlayer): to_self = models.IntegerField() to_other = models.IntegerField() to_self_primary = models.IntegerField() to_other_primary = models.IntegerField() to_self_secondary = models.IntegerField() to_other_secondary = models.IntegerField() to_self_total = models.IntegerField() to_other_total = models.IntegerField() to_self_total_earn = models.FloatField() to_other_total_earn = models.FloatField() choice = models.IntegerField(choices=list(range(9))) svo_angle = models.FloatField() svo_category = models.StringField() round_number_svo = models.IntegerField() personal_ID = models.StringField() IC1 = models.StringField(choices=[["I consent to participating in this study","I consent to participating in this study"]]) Credits = models.StringField(choices=[["Credits","Credits"],["Money","Money"]]) Student_number = models.StringField(blank=True) Bank = models.StringField() Bank_account_name = models.StringField() Street = models.StringField() House_number = models.StringField() Postal_code = models.StringField() City = models.StringField() CountryBank = models.StringField() IBAN = models.StringField() emailadress = models.StringField() # BSN = models.StringField() # date_of_birth = models.StringField() earnings_rulefollowing = models.FloatField() num_HEADS = models.IntegerField() earnings_cointoss = models.FloatField() SDO_1 = models.IntegerField(choices=[ [1, '1 Strongly oppose'], [2, '2 '], [3, '3 '], [4, '4 Neutral'], [5, '5 '], [6, '6 '], [7, '7 Strongly favour'], ], label="An ideal society requires some groups to be on top and others to be on the bottom.", widget=widgets.RadioSelectHorizontal) SDO_2 = models.IntegerField(choices=[ [1, '1 Strongly oppose'], [2, '2 '], [3, '3 '], [4, '4 Neutral'], [5, '5 '], [6, '6 '], [7, '7 Strongly favour'], ], label="Some groups of people are simply inferior to other groups.", widget=widgets.RadioSelectHorizontal) SDO_3 = models.IntegerField(choices=[ [1, '1 Strongly oppose'], [2, '2 '], [3, '3 '], [4, '4 Neutral'], [5, '5 '], [6, '6 '], [7, '7 Strongly favour'], ], label="No one group should dominate in society.", widget=widgets.RadioSelectHorizontal) SDO_4 = models.IntegerField(choices=[ [1, '1 Strongly oppose'], [2, '2 '], [3, '3 '], [4, '4 Neutral'], [5, '5 '], [6, '6 '], [7, '7 Strongly favour'], ], label="Groups at the bottom are just as deserving as groups at the top.", widget=widgets.RadioSelectHorizontal) SDO_5 = models.IntegerField(choices=[ [1, '1 Strongly oppose'], [2, '2 '], [3, '3 '], [4, '4 Neutral'], [5, '5 '], [6, '6 '], [7, '7 Strongly favour'], ], label="Group equality should not be our primary goal.", widget=widgets.RadioSelectHorizontal) SDO_6 = models.IntegerField(choices=[ [1, '1 Strongly oppose'], [2, '2 '], [3, '3 '], [4, '4 Neutral'], [5, '5 '], [6, '6 '], [7, '7 Strongly favour'], ], label="It is unjust to try to make groups equal.", widget=widgets.RadioSelectHorizontal) SDO_7 = models.IntegerField(choices=[ [1, '1 Strongly oppose'], [2, '2 '], [3, '3 '], [4, '4 Neutral'], [5, '5 '], [6, '6 '], [7, '7 Strongly favour'], ], label="We should do what we can to equalize conditions for different groups.", widget=widgets.RadioSelectHorizontal) SDO_8 = models.IntegerField(choices=[ [1, '1 Strongly oppose'], [2, '2 '], [3, '3 '], [4, '4 Neutral'], [5, '5 '], [6, '6 '], [7, '7 Strongly favour'], ], label="We should work to give all groups an equal chance to succeed.", widget=widgets.RadioSelectHorizontal) bucket_blue_balls = models.IntegerField() bucket_yellow_balls = models.IntegerField() gender = models.StringField(choices=[["Male","Male"],["Female","Female"],["Other","Other"],["I prefer not to say","I prefer not to say"]]) age = models.IntegerField() political_orientation = models.IntegerField(choices=[ [1, '1 very left'], [2, '2 '], [3, '3 '], [4, '4 center'], [5, '5 '], [6, '6 '], [7, '7 very right'], ], label="On the following scale, how would you describe your political orientation?", widget=widgets.RadioSelectHorizontal) social_ideology = models.IntegerField(choices=[ [1, '1 progressive'], [2, '2 '], [3, '3 '], [4, '4 neither progressive nor conservative'], [5, '5 '], [6, '6 '], [7, '7 conservative'], ], label="On the following scale, how progressive or conservative are your views on social issues?", widget=widgets.RadioSelectHorizontal) economic_ideology = models.IntegerField(choices=[ [1, '1 social'], [2, '2 '], [3, '3 '], [4, '4 neither social nor liberal'], [5, '5 '], [6, '6 '], [7, '7 liberal'], ], label="On the following scale, how social or liberal are your economic views?", widget=widgets.RadioSelectHorizontal) coint_toss = models.IntegerField(choices=[ [1, 'My prediction was correct'], [2, 'My prediction was not correct'], ], label="Please indicate whether your prediction was correct. For each correct prediction, you earn €0.10.", widget=widgets.RadioSelect) random_coinflip = models.StringField() class Group(BaseGroup): pass class Subsession(BaseSubsession): def creating_session(self): import random for p in self.get_players(): # print(Constants.tasks.copy()) task = Constants.tasks.copy() random.shuffle(task) # print(task) p.participant.vars['task_order'] = task # print(p.participant.vars['task_order']) # print(p.participant.vars['task_order'][0]) # print(p.participant.vars['task_order'][1]) # print(p.participant.vars['task_order'][2]) # print(p.participant.vars['task_order'][3]) if p.participant.vars['task_order'][0] == "SDO": p.participant.vars['SDO_order'] = 1 if p.participant.vars['task_order'][1] == "SDO": p.participant.vars['SDO_order'] = 2 if p.participant.vars['task_order'][2] == "SDO": p.participant.vars['SDO_order'] = 3 if p.participant.vars['task_order'][3] == "SDO": p.participant.vars['SDO_order'] = 4 if p.participant.vars['task_order'][0] == "RuleFollowing": p.participant.vars['RuleFollowing_order'] = 1 if p.participant.vars['task_order'][1] == "RuleFollowing": p.participant.vars['RuleFollowing_order'] = 2 if p.participant.vars['task_order'][2] == "RuleFollowing": p.participant.vars['RuleFollowing_order'] = 3 if p.participant.vars['task_order'][3] == "RuleFollowing": p.participant.vars['RuleFollowing_order'] = 4 # if p.participant.vars['task_order'][0] == "SVO": # p.participant.vars['SVO_round'] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] # if p.participant.vars['task_order'][1] == "SVO": # p.participant.vars['SVO_round'] = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] # if p.participant.vars['task_order'][2] == "SVO": # p.participant.vars['SVO_round'] = [3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] # if p.participant.vars['task_order'][3] == "SVO": # p.participant.vars['SVO_round'] = [4,5,6,7,8,9,10,11,12,13,14,15,16,17,18] # if p.participant.vars['task_order'][0] == "CoinToss": # p.participant.vars['CoinToss_round'] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] # if p.participant.vars['task_order'][1] == "CoinToss": # p.participant.vars['CoinToss_round'] = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] # if p.participant.vars['task_order'][2] == "CoinToss": # p.participant.vars['CoinToss_round'] = [3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] # if p.participant.vars['task_order'][3] == "CoinToss": # p.participant.vars['CoinToss_round'] = [4,5,6,7,8,9,10,11,12,13,14,15,16,17,18] # print(p.participant.vars['SDO_round']) # print(p.participant.vars['SVO_round']) # print(p.participant.vars['RuleFollowing_round']) # print(p.participant.vars['CoinToss_round']) # print(p.participant.vars['CoinToss_round'][0]) if p.participant.vars['task_order'][0] == "SVO": p.participant.vars['SVO_order'] = 1 if p.participant.vars['task_order'][1] == "SVO": p.participant.vars['SVO_order'] = 2 if p.participant.vars['task_order'][2] == "SVO": p.participant.vars['SVO_order'] = 3 if p.participant.vars['task_order'][3] == "SVO": p.participant.vars['SVO_order'] = 4 if p.participant.vars['task_order'][0] == "CoinToss": p.participant.vars['CoinToss_order'] = 1 if p.participant.vars['task_order'][1] == "CoinToss": p.participant.vars['CoinToss_order'] = 2 if p.participant.vars['task_order'][2] == "CoinToss": p.participant.vars['CoinToss_order'] = 3 if p.participant.vars['task_order'][3] == "CoinToss": p.participant.vars['CoinToss_order'] = 4 print("SDO") print(p.participant.vars['SDO_order']) print("RuleFollowing_order") print(p.participant.vars['RuleFollowing_order']) print("SVO") print(p.participant.vars['SVO_order']) print("Coin") print(p.participant.vars['CoinToss_order']) p.participant.vars['SDO_round'] = p.participant.vars['SDO_order'] p.participant.vars['RuleFollowing_round'] = p.participant.vars['RuleFollowing_order'] if p.participant.vars['SDO_order'] > p.participant.vars['SVO_order']: p.participant.vars['SDO_round'] = p.participant.vars['SDO_round'] + 14 if p.participant.vars['RuleFollowing_order'] > p.participant.vars['SVO_order']: p.participant.vars['RuleFollowing_round'] = p.participant.vars['RuleFollowing_round'] + 14 if p.participant.vars['SDO_order'] > p.participant.vars['CoinToss_order']: p.participant.vars['SDO_round'] = p.participant.vars['SDO_round'] + 14 if p.participant.vars['RuleFollowing_order'] > p.participant.vars['CoinToss_order']: p.participant.vars['RuleFollowing_round'] = p.participant.vars['RuleFollowing_round'] + 14 if p.participant.vars['CoinToss_order'] == 1: p.participant.vars['CoinToss_round'] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] if p.participant.vars['CoinToss_order'] == 2: p.participant.vars['CoinToss_round'] = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] if p.participant.vars['CoinToss_order'] == 3: p.participant.vars['CoinToss_round'] = [3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] if p.participant.vars['CoinToss_order'] == 4: p.participant.vars['CoinToss_round'] = [4,5,6,7,8,9,10,11,12,13,14,15,16,17,18] if p.participant.vars['SVO_order'] == 1: p.participant.vars['SVO_round'] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] if p.participant.vars['SVO_order'] == 2: p.participant.vars['SVO_round'] = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] if p.participant.vars['SVO_order'] == 3: p.participant.vars['SVO_round'] = [3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] if p.participant.vars['SVO_order'] == 4: p.participant.vars['SVO_round'] = [4,5,6,7,8,9,10,11,12,13,14,15,16,17,18] if p.participant.vars['SVO_order'] < p.participant.vars['CoinToss_order']: if p.participant.vars['CoinToss_order'] == 2: p.participant.vars['CoinToss_round'] = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30] if p.participant.vars['CoinToss_order'] == 3: p.participant.vars['CoinToss_round'] = [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31] if p.participant.vars['CoinToss_order'] == 4: p.participant.vars['CoinToss_round'] = [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32] if p.participant.vars['CoinToss_order'] < p.participant.vars['SVO_order']: if p.participant.vars['SVO_order'] == 2: p.participant.vars['SVO_round'] = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30] if p.participant.vars['SVO_order'] == 3: p.participant.vars['SVO_round'] = [17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31] if p.participant.vars['SVO_order'] == 4: p.participant.vars['SVO_round'] = [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32] # if p.participant.vars['SDO_round'] > p.participant.vars['SVO_round'][0]: # p.participant.vars['SDO_round'] = p.participant.vars['SDO_round'] + 14 # if p.participant.vars['RuleFollowing_round'] > p.participant.vars['SVO_round'][0]: # p.participant.vars['RuleFollowing_round'] = p.participant.vars['RuleFollowing_round'] + 14 # if p.participant.vars['SDO_round'] > p.participant.vars['CoinToss_round'][0]: # p.participant.vars['SDO_round'] = p.participant.vars['SDO_round'] + 14 # if p.participant.vars['RuleFollowing_round'] > p.participant.vars['CoinToss_round'][0]: # p.participant.vars['RuleFollowing_round'] = p.participant.vars['RuleFollowing_round'] + 14 # if p.participant.vars['SVO_round'][0] > p.participant.vars['CoinToss_round'][0]: # p.participant.vars['CoinToss_round'] = [i + 15 for i in p.participant.vars['CoinToss_round']] # if p.participant.vars['CoinToss_round'][0] > p.participant.vars['SVO_round'][0]: # p.participant.vars['SVO_round'] = [i + 15 for i in p.participant.vars['SVO_round']] # print("SDO round") # print(p.participant.vars['SDO_round']) # print("RuleFollowing_round") # print(p.participant.vars['RuleFollowing_round']) # print("SVO round") # print(p.participant.vars['SVO_round']) # print("Coin round") # print(p.participant.vars['CoinToss_round'])