from otree.api import *
import pandas as pd
import time
doc = """
Participants move on to Qualtrics.
"""
def read_csv():
import csv
f = open(__name__ + '/example-2.csv', encoding='utf-8-sig')
rows = list(csv.DictReader(f))
return rows
class C(BaseConstants):
NAME_IN_URL = 'final_questions'
PLAYERS_PER_GROUP = None
INTRO = (6, 4, 1, 5, 3, 2, 2, 3)
QUESTIONS = read_csv()
NUM_ROUNDS = 1
class Group(BaseGroup):
pass
class Player(BasePlayer):
question = models.StringField()
choice = models.IntegerField()
my_Username = models.StringField(label='Please enter your Prolific ID.')
my_Gender = models.IntegerField(
label='What gender do you identify as?',
choices=[
[1, 'Male'],
[2, 'Non-binary or gender non-conforming'],
[3, 'Female'],
[4, 'Other']
],
widget=widgets.RadioSelect
)
my_Strategy = models.LongStringField(label='Please describe how you made your decisions. Did you have a strategy for how to answer?')
my_Study = models.StringField(label='What is your area of study?')
my_Courses = models.LongStringField(label='What courses have you taken in (or related to) game theory?')
my_Agreement1 = models.IntegerField(label='Please describe your agreement with the following statements to the best of your ability.
1- I am familiar with game theory [number between 0 and 100].')
my_Agreement2 = models.IntegerField(label='2- I have been educated in school or university on game theory [number between 0 and 100].')
my_Agreement3 = models.IntegerField(label='3- I believe that efficiency is more important than fairness [number between 0 and 100].')
my_Agreement4 = models.IntegerField(label='4- I believe I am self-interested [number between 0 and 100].')
my_Agreement5 = models.IntegerField(label='5- I believe I make logical choices [number between 0 and 100].')
my_Agreement6 = models.IntegerField(label='6- I believe others are self-interested [number between 0 and 100].')
my_Agreement7 = models.IntegerField(label='7- I believe others make logical choices [number between 0 and 100].')
my_Agreement8 = models.IntegerField(label='8- I believe that the participants in this experiment are self-interested [number between 0 and 100].')
my_Agreement9 = models.IntegerField(label='9- I believe that the participants in this experiment make logical choices [number between 0 and 100].')
my_Agreement10 = models.IntegerField(label='10- I believe that the participants in this experiment believe that the other participants are self-interested [number between 0 and 100].')
my_Agreement11 = models.IntegerField(label='11- I believe that the participants in this experiment believe that the other participants make logical choices [number between 0 and 100].')
Time_spent = models.FloatField()
decision_time = models.FloatField()
def record_decision_time(self):
self.decision_time = time.time() - self.participant.vars['start_time']
self.participant.vars['start_time'] = time.time()
class Subsession(BaseSubsession):
pass
def creating_session(subsession: Subsession):
current_question = C.QUESTIONS[subsession.round_number - 1]
playersList = subsession.get_players()
for p in playersList:
df = pd.DataFrame(C.QUESTIONS)
numgames = df.shape[1]
id = numgames*(p.id_in_group/numgames % 1)
if id == 0:
id = numgames
id = round(id,0)
id = int(id)
p.question = current_question[f'SEQ{id}']
#
# if p.id_in_group == 1:
# p.question = current_question['SEQ1']
#
# elif p.id_in_group == 2:
# p.question = current_question['SEQ2']
#
# elif p.id_in_group == 3:
# p.question = current_question['SEQ3']
#
# elif p.id_in_group == 4:
# p.question = current_question['SEQ4']
#
# elif p.id_in_group == 5:
# p.question = current_question['SEQ5']
#
# elif p.id_in_group == 6:
# p.question = current_question['SEQ6']
#
# elif p.id_in_group == 7:
# p.question = current_question['SEQ7']
#
# elif p.id_in_group == 8:
# p.question = current_question['SEQ8']
#
# elif p.id_in_group == 9:
# p.question = current_question['SEQ9']
#
# elif p.id_in_group == 10:
# p.question = current_question['SEQ10']
#
# elif p.id_in_group == 11:
# p.question = current_question['SEQ11']
#
# elif p.id_in_group == 12:
# p.question = current_question['SEQ12']
#
# elif p.id_in_group == 13:
# p.question = current_question['SEQ13']
#
# elif p.id_in_group == 14:
# p.question = current_question['SEQ14']
#
# elif p.id_in_group == 15:
# p.question = current_question['SEQ15']
#
# elif p.id_in_group == 16:
# p.question = current_question['SEQ16']
#
# elif p.id_in_group == 17:
# p.question = current_question['SEQ17']
#
# elif p.id_in_group == 18:
# p.question = current_question['SEQ18']
#
# elif p.id_in_group == 19:
# p.question = current_question['SEQ19']
#
# elif p.id_in_group == 20:
# p.question = current_question['SEQ20']
#
# else:
# p.question = current_question['SEQ1']
# def choice_choices(player: Player):
# return [
# [1, player.optionA],
# [2, player.optionB],
# ['C', player.optionC],
# ]
class Welcome(Page):
form_model = 'player'
@staticmethod
def is_displayed(player: Player):
return player.round_number == 1
class Instructions(Page):
form_model = 'player'
@staticmethod
def is_displayed(player: Player):
return player.round_number == 1
@staticmethod
def vars_for_template(player: Player):
player.round_number == 1
return dict(
intro1 = C.INTRO[0],
intro2 = C.INTRO[1],
intro3 = C.INTRO[2],
intro4 = C.INTRO[3],
intro5 = C.INTRO[4],
intro6 = C.INTRO[5],
intro7 = C.INTRO[6],
intro8 = C.INTRO[7],
)
class P1Instructions(Page):
form_model = 'player'
@staticmethod
def is_displayed(player: Player):
return player.round_number == 1
def before_next_page(player: Player, timeout_happened):
player.participant.vars['start_time'] = time.time()
class Games(Page):
form_model = 'player'
form_fields = ['choice']
def vars_for_template(player: Player):
return dict(
pos1 = player.question[0],
pos2 = player.question[4],
pos3 = player.question[1],
pos4 = player.question[5],
pos5 = player.question[2],
pos6 = player.question[6],
pos7 = player.question[3],
pos8 = player.question[7],
)
@staticmethod
def before_next_page(player: Player, timeout_happened):
participant = player.participant
player.record_decision_time()
# player.is_correct = player.choice == player.solution
# participant.quiz_num_correct += int(player.is_correct)
class FinalInformation(Page):
form_model = 'player'
form_fields = ['my_Username']
# form_fields = ['my_Username', 'my_Gender', 'my_Strategy', 'my_Study',
# 'my_Agreement1', 'my_Agreement2', 'my_Agreement3', 'my_Agreement4', 'my_Agreement5', 'my_Agreement6',
# 'my_Agreement7', 'my_Agreement8', 'my_Agreement9', 'my_Agreement10', 'my_Agreement11',
# 'my_Courses']
@staticmethod
def is_displayed(player: Player):
return player.round_number == C.NUM_ROUNDS
class CompletionPage(Page):
form_model = 'player'
@staticmethod
def is_displayed(player: Player):
return player.round_number == C.NUM_ROUNDS
# @staticmethod
# def vars_for_template(player: Player):
# return dict(round_players=player.in_all_rounds())
page_sequence = [FinalInformation, CompletionPage]