from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = '' doc = """ """ class Constants(BaseConstants): name_in_url = 'G3' players_per_group = 3 num_rounds = 1 answers_Motiv_a = ['b', 'c', 'b', 'a'] answers_NoMotiv = ['b', 'c', 'b', 'b'] pre_pilot = False outcome_part1 = 50 outcome_norm_pun = 50 outcome_norm_nopun = 50 class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: for p in self.get_players(): # p.random_role = random.randint(1, 3) p.random_part = random.randint(1, 2) p.random_order = random.randint(1, 2) p.computer_n = random.randint(0, 100) p.lottery_draw = random.randint(0, 100) p.lottery_outcome_draw = random.randint(0, 100) for group in self.get_groups(): group.random_number = random.randint(1, 5) if group.random_number == 1: group.random_game = 1 else: group.random_game = 2 # group.random_game = 1 # manually set game 1 or 2 # new_structure_a = [[1, 13, 14], [2, 15, 16], [3, 17, 18], [4, 19, 20], # [5, 21, 22], [6, 23, 24], [7, 25, 26], [8, 27, 28], # [9, 29, 30], [10, 31, 32], [11, 33, 34], [12, 35, 36]] # new_structure_b = [[13, 1, 14], [15, 2, 16], [17, 3, 18], [19, 4, 20], # [21, 5, 22], [23, 6, 24], [25, 7, 26], [27, 8, 28], # [29, 9, 30], [31, 10, 32], [33, 11, 34], [35, 12, 36]] # new_structure_c = [[14, 13, 1], [16, 15, 2], [18, 17, 3], [20, 19, 4], # [22, 21, 5], [24, 23, 6], [26, 25, 7], [28, 27, 8], # [30, 29, 9], [32, 31, 10], [34, 33, 11], [36, 35, 12]] # self.set_group_matrix(new_structure_a) # self.set_group_matrix(new_structure_b) # self.set_group_matrix(new_structure_c) class Group(BaseGroup): random_game = models.IntegerField() random_number = models.IntegerField() class Player(BasePlayer): accept = models.BooleanField() ProlificID = models.StringField() paid = models.BooleanField() # selected 1 in 20 to be paid # random_role = models.IntegerField() # player a, b or c random_part = models.IntegerField() # either part 1 or part 2 for payment random_order = models.IntegerField() # karni mechanism computer_n = models.IntegerField() # computer draws number (N) lottery_played = models.BooleanField() # whether simple lottery is played or outcome lottery lottery_played_norm_pun = models.BooleanField() lottery_played_norm_nopun = models.BooleanField() # if N>=guess, play simple lottery lottery_draw = models.IntegerField() # draw a number to determine lottery outcome lottery_win = models.BooleanField() lottery_win_norm_pun = models.BooleanField() # if lottery_draw <= computer_n, win, else, lose lottery_win_norm_nopun = models.BooleanField() # if Nk', '£20,000 - £39,000'], ['<60>k', '£40,000 - £59,000'], ['<80>k', '£60,000 - £79,000'], ['<100k', '£80,000 - £99,000'], ['>100k', 'More than £100,000'], ['not-say', 'Prefer not to say'] ]) political = models.StringField(label='What is your political orientation?', choices=['Left', 'Centre-Left', 'Centre-Right', 'Right', 'Other', 'Prefer not to say']) open_ended = models.LongStringField(label='') open_ended_B = models.LongStringField(label='') feedback = models.LongStringField(label='Any general comments or feedback ' '(e.g. anything we can improve in the instructions)?', blank=True)