from otree.api import *
import random
class C(BaseConstants):
NAME_IN_URL = 'control_survey'
PLAYERS_PER_GROUP = None
NUM_ROUNDS = 1
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
pass
class Player(BasePlayer):
control_q1 = models.StringField(
choices=[['188', '188 points'],
['191','191 points'],
['143', '143 points'],
['176', '176 points']
],
label='Question on the 1st guessing task: Suppose that 37% of the participants answered the '
'quiz question correctly and you guessed that 62% of the participants would answer correctly. '
'What would your payoff then be?',
widget=widgets.RadioSelect,
)
control_q2 = models.StringField(
choices=[['143', '143 points'],
['96', '96 points'],
['188', '188 points'],
['218', '218 points']
],
label='Question on the 2nd guessing task: Suppose that the randomly chosen participant in this session '
'has guessed that 15% of the participants answered the quiz question correctly and you guessed '
'that this participant would guess that 85% of the participants guessed correctly. What would your '
'payoff then be?',
widget=widgets.RadioSelect,
)
# control_q3 = models.StringField(
# choices=[['37', '37 points'],
# ['25','25 points'],
# ['62', '62 points'],
# ['70', '70 points']
# ],
# label='3. Imagine that in one of the quiz questions 37% of the participants answered correctly, '
# 'and you guessed that 62% of the participants '
# 'answered correctly. In this scenario, what would your payoff be? ',
# widget=widgets.RadioSelect,
# )
# control_q4 = models.StringField(
# choices=[['50', '50 points'],
# ['0','0 points'],
# ['100', '100 points'],
# ['75', '75 points']
# ],
# label='4. Suppose now that a participant in this room, chosen randomly and not including '
# 'yourself, has guessed that 100% of participants answered correctly. Your '
# 'task is to accurately guess this person guess. If you guess 50% instead, what '
# 'would your payoff be in this situation?',
# widget=widgets.RadioSelect,
# )
# control_q5 = models.StringField(
# choices=[['60', '60 points'],
# ['85', '85 points'],
# ['38', '38 points'],
# ['12', '12 points']
# ],
# label='5. Suppose now that a participant in this room, chosen randomly and not including '
# 'yourself, has guessed that 15% of participants answered correctly. Your '
# 'task is to accurately guess this person guess. If you guess 85% instead, what '
# 'would your payoff be in this situation?',
# widget=widgets.RadioSelect,
# )
trial_q = models.StringField(
choices=[['The Hague', 'The Hague'],
['Tilburg', 'Tilburg'],
['Amsterdam', 'Amsterdam'],
['Rotterdam', 'Rotterdam']
],
label='Suppose the quiz question is "What is the capital of the Netherlands?" and suppose there are '
'4 possible options:',
widget=widgets.RadioSelect,
)
trial_guess1 = models.IntegerField(
label='Question on the 1st guessing task: Suppose that 37% of the participants answered the quiz '
'question correctly and you guessed that 62% of the participants would answer correctly. '
'What would your payoff then be?',
min=0,
max=100
)
trial_guess2 = models.IntegerField(
label='Guess 2: Think of a random participant in this experiment. What answer do you think '
'they gave to the previous guessing task?',
min=0,
max=100
)
# payoff_q = models.FloatField()
# payoff_guess1 = models.FloatField()
# payoff_guess2 = models.FloatField()
# total_payoff = models.FloatField()
# percentage_correct = models.FloatField()
# partner_id = models.IntegerField()
# partner_trial_guess1 = models.IntegerField()
## old version
## def compute_payoffs(self):
## all_players = []
## for subsession in self.session.get_subsessions():
## all_players.extend(subsession.get_players())
## other_players = [player for player in all_players if player.id != self.id]
## #all_players = self.session.get_participants()
## #other_players = [p for p in all_players if p.id != self.id]
## num_correct = sum([p.trial_q == 'Amsterdam' for p in other_players])
## percentage_correct = (num_correct / len(other_players))
## self.payoff_guess1 = round((1 - percentage_correct*(1-self.trial_guess1/100)**2 - (1-percentage_correct)*(self.trial_guess1/100)**2) * 100)
## partner = random.choice(other_players)
## self.partner_id = partner.id_in_group
## self.partner_trial_guess1 = partner.trial_guess1
## self.payoff_guess2 = round((1 - (partner.trial_guess1/100)*(1-self.trial_guess1/100)**2 - (1-(partner.trial_guess1/100))*(self.trial_guess1/100)**2) * 100)
## self.percentage_correct = round(percentage_correct * 100)
## if self.trial_q == 'Amsterdam':
## self.payoff_q = 100
## else:
## self.payoff_q = 0
## self.total_payoff = self.payoff_q + self.payoff_guess1 + self.payoff_guess2
# we decided to remove an example question
# def compute_payoffs(self):
# all_players = self.subsession.get_players()
# other_players = [player for player in all_players if player.participant.id != self.participant.id]
# num_correct = sum([p.trial_q == 'Amsterdam' for p in other_players])
# percentage_correct = (num_correct / len(other_players))
# self.payoff_guess1 = round((2 - percentage_correct * (1 - self.trial_guess1 / 100) ** 2 - (
# 1 - percentage_correct) * (self.trial_guess1 / 100) ** 2) * 100)
# partner = random.choice(other_players)
# self.partner_id = partner.id_in_group
# self.partner_trial_guess1 = partner.trial_guess1
# self.payoff_guess2 = round((2 - (partner.trial_guess1 / 100) * (1 - self.trial_guess1 / 100) ** 2 - (
# 1 - (partner.trial_guess1 / 100)) * (self.trial_guess1 / 100) ** 2) * 100)
# self.percentage_correct = round(percentage_correct * 100)
# if self.trial_q == 'Amsterdam':
# self.payoff_q = 100
# else:
# self.payoff_q = 0
# self.total_payoff = self.payoff_q + self.payoff_guess1 + self.payoff_guess2
# FUNCTIONS
# PAGES
class Welcome(Page):
pass
#class InstructionsPartOne(Page):
# pass
class ControlQuestions(Page):
form_model = 'player'
form_fields = ['trial_q','control_q1','control_q2']#, 'control_q3','control_q4','control_q5']
class Feedback(Page):
@staticmethod
def vars_for_template(player: Player):
player_answers = [
player.control_q1,
player.control_q2,
#player.control_q3,
#player.control_q4,
#player.control_q5,
]
correct_answers = [
'176',
'96',
]
feedback = []
for player_answer, correct_answer in zip(player_answers, correct_answers):
if player_answer == correct_answer:
feedback.append((player_answer, "Correct"))
else:
feedback.append((player_answer, f"Incorrect (Correct answer: {correct_answer})"))
return {'feedback': feedback}
form_model = 'player'
# class TrialQuestion(Page):
# form_model = 'player'
# form_fields = ['trial_q', 'trial_guess1', 'trial_guess2','control_q1','control_q2']
#
#
# class SessionResultsWaitPage(WaitPage):
# wait_for_all_groups = True
#
# @staticmethod
# def after_all_players_arrive(subsession: Subsession):
# for player in subsession.get_players():
# player.compute_payoffs()
#
#
# class TrialResults(Page):
# def vars_for_template(player: Player):
# return {
# 'trial_q_correct': 100 if player.trial_q == 'Amsterdam' else 0,
# 'trial_guess1': player.trial_guess1,
# 'trial_guess2': player.trial_guess2,
# 'payoff_guess1': player.payoff_guess1,
# 'payoff_guess2': player.payoff_guess2,
# 'percentage_correct': player.percentage_correct,
# 'partner_id': player.partner_id,
# 'partner_trial_guess1': player.partner_trial_guess1,
# 'total_payoff': player.total_payoff
# }
page_sequence = [Welcome,
#InstructionsPartOne,
ControlQuestions,
Feedback,
]
#TrialQuestion,
#SessionResultsWaitPage,
#TrialResults
#page_sequence = [TrialQuestion, ResultsWaitPage, TrialResults]#, TrialResults]