import random import requests import json from otree.api import * from . import models author = 'Razvan' doc = """ Attention check """ class C(BaseConstants): NAME_IN_URL = 'Instructions' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 HINT_1 = 'The "Introduction" section of the instructions will help you answer this question. Please try answering the question again' HINT_2 = 'The "Introduction" section of the instructions will help you answer this question. Please try answering the question again' HINT_3 = 'The "Introduction" section of the instructions will help you answer this question. Please try answering the question again' HINT_4 = 'The "Employee decides how many winning balls to buy" section of the instructions will help you answer this question. Please try answering the question again' HINT_5 = 'The "Employee decides how many winning balls to buy" section of the instructions will help you answer this question. Please try answering the question again' HINT_6 = 'The "Employee decides how many winning balls to buy" section of the instructions will help you answer this question. Please try answering the question again' HINT_7 = 'The "Employee decides how many winning balls to buy" section of the instructions will help you answer this question. Please try answering the question again' HINT_8 = 'The "Supervisor decides the bonus for the employee" section of the instructions will help you answer this question. Please try answering the question again' HINT_9 = 'The "Supervisor decides the bonus for the employee" section of the instructions will help you answer this question. Please try answering the question again' HINT_10 = 'The instructions will help you answer this question. Please try answering the question again' HINT_11 = 'The "Payoff summary" section of the instructions will help you answer this question. Please try answering the question again' HINT_12 = 'The "Payoff summary" section of the instructions will help you answer this question. Please try answering the question again' TEMPLATE_INSTRUCTIONS = 'attention/instructions_template.html' NUMBER_QUESTIONS = 12 ATTEMPTS = 4 CORRECT_1 = 2 CORRECT_2 = 1 CORRECT_3 = 1 CORRECT_4 = 2 CORRECT_5 = 60 CORRECT_6 = 5 CORRECT_7 = 40 CORRECT_8 = 1 CORRECT_9 = 2 CORRECT_10 = 1 CORRECT_11 = 590 CORRECT_12 = 400 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): payment_task = models.PositiveIntegerField() ip = models.StringField(blank=True) ip_string = models.StringField(blank=True) quiz_passed = models.BooleanField() usesMobile = models.BooleanField(blank=True) usesIE = models.BooleanField(blank=True) checkVPN = models.PositiveIntegerField() understanding_questions_wrong_attempts = models.PositiveIntegerField(initial=0) correct_answers = models.PositiveIntegerField(initial=0) question_1 = models.IntegerField( label="At the end of the session, a participant has earned 300 points. How many USD will he receive as a payoff (fixed pay plus bonus)?", choices=[1,2,3,4], widget=widgets.RadioSelectHorizontal, ) question_2 = models.IntegerField( label="How will your total payoff be determined?", choices=[ [1, 'One period is randomly chosen as a payoff period'], [2, 'The payoffs from all the 8 periods are totaled'], [3, 'My compensation in this study is fixed'], ], widget=widgets.RadioSelect, ) question_3 = models.IntegerField( label="Will you interact with the same person (employee/supervisor) for all the periods of the study?", choices=[ [1, 'Yes'], [2, 'No'], ], widget=widgets.RadioSelectHorizontal, ) question_4 = models.IntegerField( label="If the employee does not buy any winning balls, how many winning balls will there be in the bag?", choices=[0,2,4,8], widget=widgets.RadioSelectHorizontal, ) question_5 = models.IntegerField( label="How much does it cost the employee to buy 3 winning balls?", choices=[0, 30, 60, 90], widget=widgets.RadioSelectHorizontal, ) question_6 = models.IntegerField( label="What is the maximum number of additional winning balls that an employee can buy?", choices=[2, 5, 8, 10], widget=widgets.RadioSelectHorizontal, ) question_7 = models.IntegerField( label="What is the probability of a HIGH profit if the employee buys 2 winning balls?", choices=[ [20, '20%'], [30, '30%'], [40, '40%'], [80, '80%'], ], widget=widgets.RadioSelectHorizontal, ) question_8 = models.IntegerField( choices=[ [1, 'True'], [2, 'False'], ], widget=widgets.RadioSelectHorizontal, ) question_9 = models.IntegerField( label="By how much would a supervisor’s payoff decrease in a period where the supervisor awarded the employee a bonus of 150 points instead of a bonus of 100 points?", choices=[ [1, 'The supervisor’s payoff would decrease by 50 points because supervisors pay the bonus out of their own pocket'], [2, 'The supervisor’s payoff would not decrease at all because supervisors do not pay the bonus out of their own pocket'], ], widget=widgets.RadioSelect, ) question_10 = models.IntegerField( choices=[ [1, 'True'], [2, 'False'], ], widget=widgets.RadioSelectHorizontal, ) question_11 = models.IntegerField( label="What is a supervisor’s payoff in a period in which profit is HIGH? (Don’t forget that supervisors also receive a salary in each period)", choices=[280, 380, 440, 590], widget=widgets.RadioSelectHorizontal, ) question_12 = models.IntegerField( label="What is an employee’s payoff in a period in which the employee has bought 3 winning balls and the bonus has been 100? (Don’t forget that employees also receive a salary in each period)", choices=[280, 400, 440, 540], widget=widgets.RadioSelectHorizontal, ) question_1_incorrect_answers = models.PositiveIntegerField(initial=0) question_2_incorrect_answers = models.PositiveIntegerField(initial=0) question_3_incorrect_answers = models.PositiveIntegerField(initial=0) question_4_incorrect_answers = models.PositiveIntegerField(initial=0) question_5_incorrect_answers = models.PositiveIntegerField(initial=0) question_6_incorrect_answers = models.PositiveIntegerField(initial=0) question_7_incorrect_answers = models.PositiveIntegerField(initial=0) question_8_incorrect_answers = models.PositiveIntegerField(initial=0) question_9_incorrect_answers = models.PositiveIntegerField(initial=0) question_10_incorrect_answers = models.PositiveIntegerField(initial=0) question_11_incorrect_answers = models.PositiveIntegerField(initial=0) question_12_incorrect_answers = models.PositiveIntegerField(initial=0) # def question_1_error_message(player, value): # print('value is', value) # if value != C.CORRECT_1 and player.understanding_questions_wrong_attempts<4: # player.understanding_questions_wrong_attempts=player.understanding_questions_wrong_attempts+1 # return 'Cannot offer more than your remaining budget' # def question_2_error_message(player, value): # print('value is', value) # if value != C.CORRECT_2 and player.understanding_questions_wrong_attempts<4: # player.understanding_questions_wrong_attempts=player.understanding_questions_wrong_attempts+1 # return 'Cannot offer more than your remaining budget' # FUNCTIONS def creating_session(subsession: Subsession): if subsession.round_number == 1: for p in subsession.get_players(): if 'treatment_confrontation' in subsession.session.config: p.participant.vars['treatment_confrontation'] = subsession.session.config[ 'treatment_confrontation' ] else: p.participant.vars['treatment_confrontation'] = random.choice([0, 1]) if 'treatment_info' in subsession.session.config: p.participant.vars['treatment_info'] = subsession.session.config['treatment_info'] else: p.participant.vars['treatment_info'] = random.choice([0, 1, 2]) # 0=outcome only # 1=outcome+effort # 2=effort only p.participant.vars['treatment_g_output'] = subsession.session.config['g_output'] p.participant.vars['treatment_g_input'] = subsession.session.config['g_input'] if p.participant.vars['treatment_g_output']==0 and p.participant.vars['treatment_g_input']==0: p.participant.vars['treatment_noG']=1 else: p.participant.vars['treatment_noG']=0 # PAGES class Quiz(Page): template_name = 'attention/test.html' form_model = 'player' form_fields = ['question_1', 'question_2','question_3', 'question_4','question_5', 'question_6','question_7', 'question_8','question_9', 'question_10','question_11', 'question_12'] @staticmethod def error_message(player, values): solutions = dict( question_1=C.CORRECT_1, question_2=C.CORRECT_2, question_3=C.CORRECT_3, question_4=C.CORRECT_4, question_5=C.CORRECT_5, question_6=C.CORRECT_6, question_7=C.CORRECT_7, question_8=C.CORRECT_8, question_9=C.CORRECT_9, question_10=C.CORRECT_10, question_11=C.CORRECT_11, question_12=C.CORRECT_12, ) hints = dict( question_1=C.HINT_1, question_2=C.HINT_2, question_3=C.HINT_3, question_4=C.HINT_4, question_5=C.HINT_5, question_6=C.HINT_6, question_7=C.HINT_7, question_8=C.HINT_8, question_9=C.HINT_9, question_10=C.HINT_10, question_11=C.HINT_11, question_12=C.HINT_12, ) question_names = dict( question_1='question_1_incorrect_answers', question_2='question_2_incorrect_answers', question_3='question_3_incorrect_answers', question_4='question_4_incorrect_answers', question_5='question_5_incorrect_answers', question_6='question_6_incorrect_answers', question_7='question_7_incorrect_answers', question_8='question_8_incorrect_answers', question_9='question_9_incorrect_answers', question_10='question_10_incorrect_answers', question_11='question_11_incorrect_answers', question_12='question_12_incorrect_answers', ) error_messages = dict() for field_name in solutions: if values[field_name] != solutions[field_name] and player.understanding_questions_wrong_attempts C.ATTEMPTS: player.participant.vars["quiz_fail"] = True return "kicked_out" class Instructions_text(Page): @staticmethod def vars_for_template(player: Player): return dict( treatment_info=player.participant.vars['treatment_info'], ) class WarningVPN(Page): pass class CheckIPandMobile(Page): form_model = 'player' form_fields=['ip','usesMobile','usesIE'] @staticmethod def before_next_page(player: Player,timeout_happened): ip_ugly=player.ip if ip_ugly == "": player.checkVPN=100 else: ip=ip_ugly[12:-4] my_key = 'MTc3ODU6a0NERjVTbVdMMTI4RmVSVG93enN4SU5qcm04cWZqY04=' headers = {'X-Key': my_key} response = requests.get('http://v2.api.iphub.info/ip/' + ip, headers=headers) results = json.loads(response.text) try: player.checkVPN=results["block"] except Exception as err: player.checkVPN=200 print("Erro {}".format(err)) @staticmethod def app_after_this_page(player: Player, upcoming_apps): if player.checkVPN==1 or player.usesMobile==1 or player.usesIE==1: player.participant.vars["kicked_for_VPN"] = True return "kicked_out" page_sequence = [ WarningVPN, CheckIPandMobile, Instructions_text, Quiz, ]