from otree.api import * import csv import random author = 'Alexia Gaudeul' def read_csv(): import csv f = open(__name__ + '/sums.csv', encoding='utf-8-sig') rows = list(csv.DictReader(f)) # random.shuffle(rows) return rows class C(BaseConstants): NAME_IN_URL = 'transfer' PLAYERS_PER_GROUP = None # with open('transfer/sums.csv') as questions_file: # questions = list(csv.DictReader(questions_file)) QUESTIONS = read_csv() NUM_ROUNDS = len(QUESTIONS) PARTICIPATION_FEE = 1 class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): question_data = C.QUESTIONS[subsession.round_number - 1] for p in subsession.get_players(): p.question_id = int(question_data['id']) p.nr1 = int(question_data['nr1']) p.nr2 = int(question_data['nr2']) p.nr3 = int(question_data['nr3']) p.nr4 = int(question_data['nr4']) p.nr5 = int(question_data['nr5']) p.correct5 = int(question_data['correct5']) p.correct3 = int(question_data['correct3']) # time limit randomly assigned, either 3 or 5 # hardness either 3 or 5 sums p.time_limit = 3 + ((p.id_in_group) % 2 == 1)*2 p.hardness = ((p.id_in_group % 4 == 1) or (p.id_in_group % 4 == 2))*1 class Group(BaseGroup): pass class Player(BasePlayer): question_id = models.IntegerField() nr1 = models.IntegerField() nr2 = models.IntegerField() nr3 = models.IntegerField() nr4 = models.IntegerField() nr5 = models.IntegerField() correct3 = models.IntegerField() correct5 = models.IntegerField() time_left = models.FloatField() submitted_answer = models.IntegerField() is_answered = models.IntegerField(initial=0) correct = models.IntegerField() is_correct = models.IntegerField(initial=0) sum_answered = models.IntegerField(initial = 0) hardness = models.IntegerField(initial = 0) time_limit = models.IntegerField(initial = 0) sum_correct = models.IntegerField(initial = 0) #timeout = models.FloatField() finish = models.IntegerField() length = models.FloatField() gender = models.IntegerField(choices=[(0, 'Male'), (1, 'Female'), (2, 'Other')], label='What is your gender?', widget=widgets.RadioSelectHorizontal) nationality = models.IntegerField(choices=[(0, 'German'), (1, 'Italian'), (2, 'Other')], label='What is your nationality?', widget=widgets.RadioSelectHorizontal) belief_correct = models.IntegerField() difficulty = models.IntegerField(choices=[(4, 'Very difficult'), (3, 'Quite difficult'), (2, 'Quite easy'), (1, 'Easy')], label='How difficult was it for you to do the sums?', widget=widgets.RadioSelectHorizontal) problems = models.IntegerField(choices=[(0, 'No'), (1, 'Yes')], label='Did you face any problems when completing this study?', widget=widgets.RadioSelectHorizontal) explain = models.CharField( label="If so, what kind of problem did you face?", max_length=100, blank=True) # In your opinion, what is the likelihood of a new wave of Covid-19 before the end of 2022 in your country of residence? # 1. Very unlikely # 2. Rather unlikely # 3. Neither likely nor unlikely # 4. Rather likely # 5. Very likely # 6. Don’t know # 7. Prefer not to say # # # Please tell us how much you disagree or agree with the following statements about getting yourself vaccinated # (coded as 1 = strongly disagree, 2 = rather disagree, 3 = neutral, 4 = rather agree, 5 = strongly agree,8=don’t know 9= Prefer not to say). # # I am completely confident that vaccines are safe. # Vaccination is unnecessary because vaccine-preventable diseases are not common anymore. # Everyday stress prevents me from being vaccinated. # When I think about being vaccinated, I weigh the benefits and risks to make the best decision possible. # When everyone else is vaccinated, I don’t have to be vaccinated, too. vax_0 = models.IntegerField(widget=widgets.RadioSelect, label='In your opinion, what is the likelihood of a new wave of Covid-19 before the end of 2022 in your country of residence?', choices=[(1, '1. Very unlikely'), (2, '2. Rather unlikely'), (3, '3. Neither likely nor unlikely'), (4, '4. Rather likely'), (5, '5. Very likely'), (8, '8. Do not know'), (9, '9. Prefer not to say') ]) vax_1 = models.IntegerField(widget=widgets.RadioSelect, label='1. I am completely confident that vaccines are safe.', choices=[(1, '1. Strongly disagree'), (2, '2. Rather disagree'), (3, '3. Neutral'), (4, '4. Rather agree'), (5, '5. Strongly agree'), (8, '8. Do not know'), (9, '9. Prefer not to say') ]) vax_2 = models.IntegerField(widget=widgets.RadioSelect, label='2. Vaccination is unnecessary because vaccine-preventable diseases are not common anymore.', choices=[(1, '1. Strongly disagree'), (2, '2. Rather disagree'), (3, '3. Neutral'), (4, '4. Rather agree'), (5, '5. Strongly agree'), (8, '8. Do not know'), (9, '9. Prefer not to say') ]) vax_3 = models.IntegerField(widget=widgets.RadioSelect, label='3. Everyday stress prevents me from being vaccinated.', choices=[(1, '1. Strongly disagree'), (2, '2. Rather disagree'), (3, '3. Neutral'), (4, '4. Rather agree'), (5, '5. Strongly agree'), (8, '8. Do not know'), (9, '9. Prefer not to say') ]) vax_4 = models.IntegerField(widget=widgets.RadioSelect, label='4. When I think about being vaccinated, I weigh the benefits and risks to make the best decision possible.', choices=[(1, '1. Strongly disagree'), (2, '2. Rather disagree'), (3, '3. Neutral'), (4, '4. Rather agree'), (5, '5. Strongly agree'), (8, '8. Do not know'), (9, '9. Prefer not to say') ]) vax_5 = models.IntegerField(widget=widgets.RadioSelect, label='5. When everyone else is vaccinated, I don’t have to be vaccinated, too.', choices=[(1, '1. Strongly disagree'), (2, '2. Rather disagree'), (3, '3. Neutral'), (4, '4. Rather agree'), (5, '5. Strongly agree'), (8, '8. Do not know'), (9, '9. Prefer not to say') ]) # FUNCTIONS def current_question(self): return self.session.vars['questions'][self.round_number - 1] # PAGES class gender_nat(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['gender','nationality'] class Instructions0(Page): #timeout_seconds = 20 def is_displayed(self): return self.round_number == 1 class Instructions1(Page): #timeout_seconds = 20 def is_displayed(self): return self.round_number == 1 @staticmethod def before_next_page(player, timeout_happened): participant = player.participant import time # remember to add 'expiry' to PARTICIPANT_FIELDS. participant.expiry = time.time() + player.time_limit*60 def get_timeout_seconds(player): participant = player.participant import time return participant.expiry - time.time() class Sums(Page): timer_text = 'Time left:' get_timeout_seconds = get_timeout_seconds # record time of each answer @staticmethod def is_displayed(player): return get_timeout_seconds(player) > 1 form_model = 'player' form_fields = ['submitted_answer'] @staticmethod def before_next_page(player, timeout_happened): if player.submitted_answer != 0: player.is_answered = 1 player.time_left = get_timeout_seconds(player) if player.hardness==1: player.correct=player.correct5 else: player.correct=player.correct3 if player.submitted_answer == player.correct: player.is_correct = 1 class End_Sums(Page): timeout_seconds = 2 def is_displayed(self): return self.round_number == C.NUM_ROUNDS @staticmethod def before_next_page(player, timeout_happened): player.sum_answered = sum([p.is_answered for p in player.in_all_rounds()]) class Results0(Page): def is_displayed(self): return self.round_number == C.NUM_ROUNDS form_model = 'player' form_fields = ['belief_correct'] @staticmethod def before_next_page(player, timeout_happened): player.sum_correct = sum([p.is_correct for p in player.in_all_rounds()]) class Results1(Page): def is_displayed(self): return self.round_number == C.NUM_ROUNDS class Questions_Vax(Page): def is_displayed(self): return self.round_number == C.NUM_ROUNDS form_model = 'player' form_fields = ['vax_1', 'vax_2', 'vax_3', 'vax_4', 'vax_5'] class Questions(Page): def is_displayed(self): return self.round_number == C.NUM_ROUNDS form_model = 'player' form_fields = ['vax_0', 'difficulty', 'problems', 'explain'] @staticmethod def before_next_page(player, timeout_happened): participant = player.participant participant.finished = True class Finished(Page): def is_displayed(self): return self.round_number == C.NUM_ROUNDS page_sequence = [ gender_nat, Instructions0, Instructions1, Sums, End_Sums, Results0, Results1, Questions_Vax, Questions, Finished ]