from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import json from numpy.random import choice class GeneralInstructions(Page): pass class CaptchaFailed(Page): def is_displayed(self): return self.player.error_count_captcha >= (Constants.max_errors_captcha) class Lottery_tut(Page): form_model = 'player' form_fields = ['choice', 'tut_exp_deck_seen_hidden', 'tut_length_exp_deck_seen_hidden', 'tut_page_time_hidden', ] def vars_for_template(self): new_tut_trial = json.loads(self.player.new_tut_trial) a1_prob = float(new_tut_trial[0][0][0]) a1_outcome = int(new_tut_trial[0][0][1]) a2_prob = float(new_tut_trial[0][1][0]) a2_outcome = int(new_tut_trial[0][1][1]) b1_prob = float(new_tut_trial[1][0][0]) b1_outcome = int(new_tut_trial[1][0][1]) b2_prob = float(new_tut_trial[1][1][0]) b2_outcome = int(new_tut_trial[1][1][1]) class MakeDeck: """Creating the card decks/lotteries that Players will see (experience deck)... """ """...and play (real lotteries)""" def __init__(self, p_gamble1, outcome_gamble1, p_gamble2, outcome_gamble2, k_draws): """Initialize probability and number of draws attributes""" self.outcomes = [outcome_gamble1, outcome_gamble2] self.p_gamble1 = p_gamble1 # our low prob weights to be passed to each instance self.p_gamble2 = p_gamble2 # our high prob weights to be passed to each instance self.k_draws = k_draws # number of chosen outcomes (bzw outcomes fuer die Liste) that we pass to each instance of CardDeck # draw k number of outcomes with weighted probs to build CardDeck self.make_session_array = choice(self.outcomes, k_draws, p=[p_gamble1, p_gamble2]) self.deck_array = self.make_session_array.tolist() # convert numpy array to a list # Make single choice for real lottery gamble self.lottery = (choice(self.outcomes, k_draws, p=[p_gamble1, p_gamble2])) exp_deck = MakeDeck(a1_prob, a1_outcome, a2_prob, a2_outcome, 450) # Create instances of class CardDeck with special probabilities that we pass # Debug Variables printed to terminal: print('The tutorial exp_deck is', exp_deck.deck_array) print('The tutorial trial is', new_tut_trial) self.player.tut_exp_deck = json.dumps(exp_deck.deck_array) return dict( order=self.player.participant.vars['order'], table_order=self.player.participant.vars['table_order'], participant_treatment=self.player.participant.vars['treatment'], tut_exp_deck=self.player.tut_exp_deck, new_tut_trial=new_tut_trial, a1_prob=int(a1_prob * 100), a1_outcome=a1_outcome, a2_prob=int(a2_prob * 100), a2_outcome=a2_outcome, b1_prob=int(b1_prob * 100), b1_outcome=b1_outcome, b2_prob=int(b2_prob * 100), b2_outcome=b2_outcome, ) def js_vars(self): return dict( order=self.player.participant.vars['order'], table_order=self.player.participant.vars['table_order'], tut_exp_deck=json.loads(self.player.tut_exp_deck), ) class ComprehensionTest(Page): form_model = 'player' form_fields = ['test_1', 'test_2', 'test_3', 'test_4', 'test_5', 'test_6', 'captcha_1' ] live_method = 'live_data' def vars_for_template(self): return dict( n_errors=self.player.error_count, participant_treatment=self.player.participant.vars['treatment'], order=self.player.participant.vars['order'], table_order=self.player.participant.vars['table_order'], ) def js_vars(self): return dict( n_errors=self.player.error_count, ) class ComprehensionFailed(Page): def is_displayed(self): return self.player.error_count >= (Constants.max_errors) class ComprehensionPassed(Page): pass class Captcha(Page): form_model = 'player' form_fields = ['captcha_1', 'captcha_2', 'captcha_3', 'captcha_4', 'captcha_5', 'captcha_6',] live_method = 'live_captcha' def vars_for_template(self): return dict( n_errors_captcha=self.player.error_count_captcha, ) def js_vars(self): return dict( n_errors_captcha=self.player.error_count_captcha, ) page_sequence = [Captcha, CaptchaFailed, GeneralInstructions, Lottery_tut, ComprehensionTest, ComprehensionFailed, ComprehensionPassed,]