from otree.api import * #import pandas as pd import csv import random doc = """ This is the second session of the iq project. First Subjects have to do IQ test, ... """ # ############################################################################################################# # ##################################### FUNCTIONS ####################################################### # ############################################################################################################# # We will need to copy here the extra Payoff Function # payoffis the sum of the base payoff and the extra payoff an individual can get after the first session. # def set_Payoff_Session1(player): # player.payoff = player.base_payoff + player.extraPayoff1 + player.extraPayoff2 # We need to import the Rank from the data we collected in the first session. # Then we have to look for the Melessa ID in the list and figure out what was the Positive Feedback of that person. # Similar than the function get_PositiveFeedback in the second session. def set_ranking(player): with open('iq_session3/static/data.csv', 'r') as df: data = csv.DictReader(df) for row in data: # print(row) if player.Melessa_ID == str(row['ID']): player.Rank = int(row['Rank']) def set_extrapayoff4(player): if player.Rank < 6 and player.BeliefTopHalf4 > max([random.randint(0, 100), random.randint(0, 100)]): player.extraPayoff4 = Constants.extra_payoff elif player.Rank > 5 and player.BeliefTopHalf4 < min([random.randint(0, 100), random.randint(0, 100)]): player.extraPayoff4 = Constants.extra_payoff else: player.extraPayoff4 = 0 ############################################################################################################## ########################################### MODELS ########################################################### ############################################################################################################## class Constants(BaseConstants): name_in_url = 'iq_session3' players_per_group = None num_rounds = 1 # we have to set actual payment when we know how long it takes to do the experiment, these are just example numbers so far. base_payment = 14 extra_payoff = 6 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): #Melessa_ID = models.IntegerField() Melessa_ID = models.StringField() # iq_result = models.IntegerField() # Rank (from 1 to 10 ) that depends on the relative performance in the iq test Rank = models.IntegerField() BeliefTopHalf4 = models.IntegerField(min=0, max=100, initial=None) #payoutrelevant4 = models.IntegerField(initial=99) extraPayoff4 = models.IntegerField(initial=0) #extraPayoff3 = models.IntegerField(initial=0) #extraPayoff2 = models.IntegerField(initial=0) #extraPayoff1 = models.IntegerField(initial=0) #payselect = models.IntegerField(initial=99) #extrapayofftotal = models.IntegerField(initial=0) details_beliefs_4_1 = models.BooleanField(initial=False) #details_beliefs_4_2 = models.BooleanField(initial=False) ################################################################################################################### ################################## PAGES #################################################### ################################################################################################################### class GeneralInstructions(Page): form_model = 'player' form_fields = ['Melessa_ID'] @staticmethod def before_next_page(player: Player, timeout_happened): return dict( Rank=set_ranking(player), # PositiveFeedback=set_PositiveFeedback(player), # NegativeFeedback=set_NegativeFeedback(player), ) @staticmethod def error_message(player: Player, values): with open('iq_session3/static/data.csv', 'r') as df: data = csv.DictReader(df) fehler = 1 for row in data: # print(row) if values['Melessa_ID'] == str(row['ID']): fehler = 0 if fehler == 1: return 'Number not found. Please use the number you wrote down at the end of the first session.' # Here we have to copy in the beliefs pages ... class Part1(Page): @staticmethod def before_next_page(player: Player, timeout_happened): player.participant.melessa_id = player.Melessa_ID class BeliefInstructions4b(Page): @staticmethod def is_displayed(player: Player): return player.details_beliefs_4_1==True class BeliefInstructions4a(Page): form_model = 'player' form_fields = ['details_beliefs_4_1'] class BelievesTopHalf4(Page): form_model = 'player' form_fields = ['BeliefTopHalf4'] @staticmethod def before_next_page(player: Player, timeout_happened): return dict( extraPayoff4=set_extrapayoff4(player), # PositiveFeedback=set_PositiveFeedback(player), # NegativeFeedback=set_NegativeFeedback(player), ) class Blank(Page): timeout_seconds=1 @staticmethod def before_next_page(player: Player, timeout_happened): player.participant.extra_payoff_4=player.extraPayoff4 page_sequence = [ GeneralInstructions, Part1, BeliefInstructions4a, BeliefInstructions4b, BelievesTopHalf4, Blank, #Resolve_1, #Resolve_2, #LastPage3, ]