from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import itertools import numpy as np from django import forms from django.forms import widgets as django_widgets import math author = 'Jindi Huang' doc = """ Dots Estimation """ class Constants(BaseConstants): #### Task Setting #### dots_time = 10 # How many seconds the dots pattern shows on the screen. est_time = 10 # How many seconds you have to do the comparison or estimation. cu_time = 20 # How many seconds you have to select your CU. dots_num = 430 # The true number of dots correct_incentive = 0.5 # Bonus if correctly answer the question ###################### name_in_url = 'dots_estimation' players_per_group = None num_rounds = 1 list1 = np.arange(1 * 20, - 1, -1) list2 = [] list2.append(0) for x in range(20): list2.append((x+1)*5) class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: for p in self.get_players(): p.participant.vars['anchor'] = 0 p.participant.vars['guess_correct'] = False p.participant.vars['correct_bonus'] = 0 p.participant.vars['failed_answer'] = False p.participant.vars['bonus_amount'] = 0 p.participant.vars['consent'] = True p.participant.vars['failed_comprehension_dots'] = False class Group(BaseGroup): pass class Player(BasePlayer): prolific_id = models.StringField(label="", max_length=24) def prolific_id_error_message(self, str): if len(str)<24: return 'Your Prolific ID should have 24 alphanumeric characters.' anchor = models.IntegerField(label="") dots_estimation = models.IntegerField(min=0, label="") failed_answer = models.BooleanField(initial=False) failed_comprehension = models.BooleanField(initial=False) confidence_noanchor = models.FloatField() confidence_anchor = models.FloatField() # question_failed = models.IntegerField(initial=0) # qn_procedure_got_wrong = models.BooleanField(initial=False) # qn_confidence_got_wrong = models.BooleanField(initial=False) answer_failed = models.IntegerField(initial=0) consent = models.BooleanField(initial=True) dots_anchor = models.IntegerField( initial=0, widget=widgets.RadioSelect, blank=False, label="" ) def dots_anchor_choices(self): choices=[ [1, 'More than {}'.format(self.participant.vars['anchor'])], [2, 'Less than {}'.format(self.participant.vars['anchor'])], ] return choices # # qn_procedure = models.IntegerField( # choices=[ # [1, 'The dots will only be shown for {} seconds.'.format(Constants.dots_time)], # [0, 'I can still see the dots on the following decision screens.'], # [0, 'There will be no time limit to answer the questions on the following decision screens.'] # ], # widget=widgets.RadioSelect, # blank=False, # label="" # ) # # qn_confidence = models.FloatField( # blank=False, # label="" # ) def set_payoff(self): if not self.failed_comprehension and not self.participant.vars['failed_answer']: self.participant.vars['guess_correct'] = abs(self.dots_estimation - Constants.dots_num) <= 5 if self.participant.vars['guess_correct']: self.participant.vars['correct_bonus'] = Constants.correct_incentive self.payoff = Constants.correct_incentive else: self.payoff = 0