import random import csv import itertools from django import forms from django.conf import settings from django import forms from captcha.fields import ReCaptchaField from captcha.widgets import ReCaptchaV2Checkbox from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from django_countries.fields import CountryField author = 'Julian Hackinger' doc = """ This experiment is designed to test whether subjects are equally prone to exhibit the house money effect, i.e. violate the assumption of fungibility. It therefore comprises of three parts. In part one, participants need to earn their endowment in a real effort task. In part two, participants make decisions on how to allocate their endowment. In part three, participants complete intelligence tests. There are four treatments with respect to part one. In the Random High Effort treatment (RHE) and the Random Low Effort treatment (RLE) participants are told that they would either need to work little or much in order to earn their endowment. They are then assigned correspondingly to work either little or much. In the High Effort treatment (HE) and the Low Effort treatment (LE) participants are told that they would need to work little in the Low Effort treatment or much in the High Effort treatment. They are then assigned correspondingly. """ class Constants(BaseConstants): name_in_url = 'po_ca_eb_1' players_per_group = None participation_fee_in_points = 500 # For testing: participation_numbers with open('po_ca_eb_1/participation_numbers.csv') as participation_numbers_file: participation_numbers = participation_numbers_file.read().split('\n') # Load questions with open('po_ca_eb_1/crt.csv') as crt_questions_file: crt_questions = list(csv.DictReader(crt_questions_file)) with open('po_ca_eb_1/raven.csv') as raven_questions_file: raven_questions = list(csv.DictReader(raven_questions_file)) pre_crt_rounds = 1 num_crt_rounds = 6 pre_raven_rounds = num_crt_rounds num_raven_6_rounds = 6 num_raven_8_rounds = 18 total_num_raven_rounds = num_raven_6_rounds + num_raven_8_rounds num_rounds = num_crt_rounds + num_raven_6_rounds + num_raven_8_rounds class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: # For testing: participation_numbers self.session.vars['participation_numbers'] = Constants.participation_numbers.copy() # Questions self.session.vars['crt_questions'] = Constants.crt_questions.copy() self.session.vars['raven_questions'] = Constants.raven_questions.copy() # For testing: participation_numbers participation_numbers = iter(self.session.vars['participation_numbers']) # List must be larger than number of participants for p in self.get_players(): p.participation_number = next(participation_numbers) for p in self.get_players(): crt_question_data = p.crt_current_question() p.crt_question_id = int(crt_question_data['id']) p.crt_question = crt_question_data['question'] p.crt_solution = int(crt_question_data['solution']) p.crt_unit = crt_question_data['unit'] raven_6_question_data = p.raven_6_current_question() p.raven_6_question_id = str(raven_6_question_data['id']) p.raven_6_solution = str(raven_6_question_data['solution']) raven_8_question_data = p.raven_8_current_question() p.raven_8_question_id = str(raven_8_question_data['id']) p.raven_8_solution = str(raven_8_question_data['solution']) # def creating_session(self): # # randomize slider points # for player in self.get_players(): # player.participant.vars['starting_points'] = [] # for slider in range(1, Constants.num_sliders + 1): # player.participant.vars['starting_points'].append(random.randint(*random.choice([(0, 40), (60, 100)]))) # print('set participant.starting_point to', player.participant.vars['starting_points']) class Group(BaseGroup): pass class Player(BasePlayer): # Participation_numbers participation_number = models.StringField() # Comprehension check comprehension = models.StringField() # Captcha captcha = ReCaptchaField(widget=ReCaptchaV2Checkbox) # https://groups.google.com/forum/#!topic/otree/69qEkthJYL8 # https://blog.bitlabstudio.com/using-recaptcha-with-django-1b7aea786ad6 # https://github.com/praekelt/django-recaptcha # Confirmation Instructions confirmation = models.BooleanField( widget=widgets.CheckboxInput(), label='''I confirm that I have carefully read the instructions.''' ) # CRT questions crt_question_id = models.IntegerField() crt_question = models.StringField() crt_solution = models.IntegerField() crt_unit = models.StringField() crt_submitted_answer = models.IntegerField() crt_is_correct = models.BooleanField() def crt_current_question(self): return self.session.vars['crt_questions'][self.round_number - 1] def crt_current_unit(self): return self.session.vars['crt_units'][self.round_number - 1] def crt_check_correct(self): self.crt_is_correct = (self.crt_submitted_answer == self.crt_solution) crt_familiarity_bat = models.BooleanField( label=''' A bat and a ball cost 22 dollars in total. The bat costs 20 dollars more than the ball. How many dollars does the ball cost?''', widget = widgets.CheckboxInput() ) crt_familiarity_widget = models.BooleanField( label=''' If it takes 5 machines 5 minutes to make 5 widgets, how many minutes would it take 100 machines to make 100 widgets?''', widget=widgets.CheckboxInput() ) crt_familiarity_lake = models.BooleanField( label=''' In a lake, there is a patch of lily pads. Every day, the patch doubles in size. If it takes 48 days for the patch to cover the entire lake, how many days would it take for the patch to cover half of the lake?''', widget=widgets.CheckboxInput() ) crt_familiarity_elves = models.BooleanField( label=''' If three elves can wrap three toys in one hour, how many elves are needed to wrap six toys in two hours?''', widget=widgets.CheckboxInput() ) crt_familiarity_marks = models.BooleanField( label=''' Jerry received both the 15th highest and the 15th lowest mark in the class. How many students are there in the class?''', widget=widgets.CheckboxInput() ) crt_familiarity_medals = models.BooleanField( label=''' In an athletics team, tall members won three times more medals than short members. The team won 60 medals in total. How many of these were won by short athletes?''', widget=widgets.CheckboxInput() ) # Raven's Test raven_6_question_id = models.StringField() raven_6_solution = models.StringField() raven_8_question_id = models.StringField() raven_8_solution = models.StringField() raven_6_submitted_answer = models.StringField( choices=['1', '2', '3', '4', '5', '6'], label='Select one!', widget=widgets.RadioSelectHorizontal ) raven_8_submitted_answer = models.StringField( choices=['1', '2', '3', '4', '5', '6', '7', '8'], label='Select one!', widget=widgets.RadioSelectHorizontal ) raven_is_correct = models.BooleanField() def raven_6_current_question(self): return self.session.vars['raven_questions'][2*(self.round_number - Constants.num_crt_rounds) + 10 + 1] def raven_6_check_correct(self): self.raven_is_correct = (self.raven_6_submitted_answer == self.raven_6_solution) def raven_8_current_question(self): return self.session.vars['raven_questions'][2*self.round_number - 1] # return self.session.vars['raven_questions'][self.round_number - Constants.num_crt_rounds - Constants.num_raven_6_rounds + 60 - Constants.num_raven_8_rounds - 1] def raven_8_check_correct(self): self.raven_is_correct = (self.raven_8_submitted_answer == self.raven_8_solution) # Confirmation Instructions information_results = models.BooleanField( widget=widgets.CheckboxInput(), label='''I would like to receive an e-mail with my results in the two tests.''' )