from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import json author = 'Miriam Kachelmann' doc = """ Intro to OmEx Card Lottery Game including Mock Game """ class Constants(BaseConstants): name_in_url = 'Introduction' players_per_group = None num_rounds = 1 max_errors = 4 max_errors_captcha = 2 class Subsession(BaseSubsession): def creating_session(self): import itertools # using itertools makes equally sized groups as p1 gets t1 and p2 t2 p3 t3 p4 t1 and so on treatments = itertools.cycle(['ExpDef', 'ExpAlt', 'ExpNone', 'ExpNone', 'ExpAlt', 'ExpDef']) # place this outside the for loop! otherwise the same for all participants if self.round_number == 1: for player in self.get_players(): #### ---- Set condition to assign between groups ---------### # Conditional to determine which HTML Templates should be used for Tutorial and Real Lottery # and store them to participant variables so they will persist throughout the session player.participant.vars['treatment'] = next(treatments) # next() retrieves next item from the iterator if player.participant.vars['treatment'] == 'ExpDef': player.participant.vars['template'] = 'OmEx_Lottery/Lottery_Cond_ExpDef.html' player.participant.vars['tut_template'] = 'Intro_OmEx/Lottery_tut_Cond_ExpDef.html' elif player.participant.vars['treatment'] == 'ExpAlt': player.participant.vars['template'] = 'OmEx_Lottery/Lottery_Cond_ExpAlt.html' player.participant.vars['tut_template'] = 'Intro_OmEx/Lottery_tut_Cond_ExpAlt.html' else: player.participant.vars['template'] = 'OmEx_Lottery/Lottery_Cond_ExpNone.html' player.participant.vars['tut_template'] = 'Intro_OmEx/Lottery_tut_Cond_ExpNone.html' player.tut_lottery_template = player.participant.vars['tut_template'] # store participant variable in player class trial_1 = [[['0.5', '50'], ['0.5', '50']], [['0.5', '48'], ['0.5', '52']]] trial_2 = [[['0.5', '48'], ['0.5', '52']], [['0.5', '50'], ['0.5', '50']]] new_tut_trial = random.choice([trial_1, trial_2]) player.new_tut_trial = json.dumps(new_tut_trial) ## ----------- Create order variable for sides of default risk-panel in Runde 1 --------------------- #### from numpy.random import choice possible_sides = ['L', 'R'] numpy_side = choice(possible_sides, 1, p=[0.5, 0.5]) # L = left R = right mit numpy side = numpy_side.tolist() # der numpy array mus noch konvertiert werden in normale python liste player.participant.vars['order'] = side player.order = str(player.participant.vars['order']) ## Create Array to shuffle Probability and Points Display within description table and set to participant variable table_array = ["prob_first", "points_first"] numpy_table_order = choice(table_array, 1, p=[0.5, 0.5]) table_order = numpy_table_order.tolist() # der numpy array mus noch konvertiert werden in normale python liste player.participant.vars['table_order'] = table_order player.table_order = str(player.participant.vars['table_order']) print(player.table_order) print('The tutorial trial is:', player.new_tut_trial) class Group(BaseGroup): pass class Player(BasePlayer): order = models.LongStringField() tut_lottery_template = models.LongStringField() table_order = models.StringField() error_count = models.IntegerField(initial=0) error_count_captcha = models.IntegerField(initial=0) new_tut_trial = models.LongStringField() tut_exp_deck = models.LongStringField() tut_exp_deck_seen_hidden = models.LongStringField(blank=True) tut_length_exp_deck_seen_hidden = models.IntegerField(blank=True) tut_page_time_hidden = models.LongStringField(blank=True) choice = models.StringField(choices=[1, 'default', 2, 'alternative', 3, 'no-default-1', 4, 'no-default-2']) def live_data(self, data): self.error_count = data['error_count'] print('The error count is', data['error_count']) def live_captcha(self, data): self.error_count_captcha = data['error_count_captcha'] print('The captcha error count is', data['error_count_captcha']) test_1 = models.IntegerField(label='How many card decks can you choose from?', choices=[ [1, '4'], [2, '3'], [3, '2'], [4, 'none'], [5, 'do not know / not displayed'] ], widget=widgets.RadioSelect()) test_2 = models.IntegerField(label='What is the range of the possible points/outcomes?', choices=[ [1, '-1000 to 1000'], [2, '0 to 100'], [3, '-100 to 100'], [4, 'range varies every round'], [5, 'do not know / not displayed'] ], widget=widgets.RadioSelect()) test_3 = models.IntegerField(label='How often can you draw test cards from the card deck that does not come with a description?', choices=[ [1, 'Never'], [2, 'Once'], [3, 'As often as you want WITHOUT cost'], [4, 'There is no card deck that you can draw cards from.'], [5, 'do not know / not displayed'] ], widget=widgets.RadioSelect()) test_4 = models.IntegerField(label='What does an outcome probability of 100% mean?', choices=[ [1, 'The outcome is 100% sure to occur.'], [2, 'The outcome is 100% sure to NOT occur.'], [3, 'The outcome is likely but not sure to occur.'], [4, 'The outcome is likely but not sure to NOT occur.'], [5, 'do not know / not displayed'] ], widget=widgets.RadioSelect()) test_5 = models.IntegerField(label='When you made your decision and you played the real lottery...', choices=[ [1, '...you will receive immediate feedback on the drawn outcome.'], [2, '...you will receive no feedback, but the won outcome will be counted towards ' 'your overall bonus payment.'], [3, 'do not know / not displayed'] ], widget=widgets.RadioSelect()) test_6 = models.IntegerField(label='The last mock round of the main task (card lottery) was...', choices=[ [1, '...counted towards your sum bonus payment.'], [2, '...NOT counted towards your sum bonus payment'], [3, 'do not know / not displayed'] ], widget=widgets.RadioSelect()) captcha_1 = models.BooleanField(blank=True, label='', widget=widgets.CheckboxInput) captcha_2 = models.BooleanField(blank=True, label='', widget=widgets.CheckboxInput) captcha_3 = models.BooleanField(blank=True, label='', widget=widgets.CheckboxInput) captcha_4 = models.BooleanField(blank=True, label='', widget=widgets.CheckboxInput) captcha_5 = models.BooleanField(blank=True, label='', widget=widgets.CheckboxInput) captcha_6 = models.BooleanField(blank=True, label='', widget=widgets.CheckboxInput)