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_revelation/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_revelation' 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() 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 Blank(Page): timeout_seconds = 1 @staticmethod def before_next_page(player: Player, timeout_happened): player.Melessa_ID = player.participant.melessa_id class Part5(Page): @staticmethod def before_next_page(player, timeout_happened): return dict( rank=set_ranking(player), # PositiveFeedback=set_PositiveFeedback(player), # NegativeFeedback=set_NegativeFeedback(player), ) class Resolve_2(Page): pass #def vars_for_template(self): #def vars_for_template(self): #print(Player.Rank) class LastPage3(Page): pass page_sequence = [ #GeneralInstructions, Blank, Part5, #Resolve_1, Resolve_2, #LastPage3, ]