from otree.api import * import csv import random doc = """ This is the third and last session of the work project. """ # ############################################################################################################# # ##################################### FUNCTIONS ####################################################### # ############################################################################################################# # We will need to copy here the extra Payoff Function # payoffs 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('work_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.num_tasks_total = int(row['NumberTasks']) def set_extrapayoff4(player): if player.num_tasks_total < 60 and player.BeliefTopHalf4 > max([random.randint(0, 100), random.randint(0, 100)]): player.extraPayoff4 = Constants.extra_payoff elif player.num_tasks_total > 50 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 = 'work_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 days_single = 7 days_double = 14 base_tasks = 40 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): Melessa_ID = models.StringField() num_tasks_total = models.IntegerField() BeliefTopHalf4 = models.IntegerField(min=0, max=100, initial=None, label='Your guess: (enter a value between 0 and 100)') details_beliefs_4_1=models.BooleanField(initial=False) extraPayoff4 = models.IntegerField(initial=0) ################################################################################################################### ################################## PAGES #################################################### ################################################################################################################### class GeneralInstructions(Page): form_model = 'player' form_fields = ['Melessa_ID'] @staticmethod def before_next_page(player: Player, timeout_happened): player.participant.melessa_id = player.Melessa_ID @staticmethod def error_message(player: Player, values): with open('work_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 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, timeout_happened): if player.field_maybe_none('BeliefTopHalf4') != None: return dict( num_tasks_total=set_ranking(player), extraPayoff4=set_extrapayoff4(player), #extrapayofftotal=set_extrapayoff(player) ) class Blank(Page): timeout_seconds=1 @staticmethod def before_next_page(player: Player, timeout_happened): player.participant.extra_payoff_4=player.extraPayoff4 class Part1(Page): pass class Reminder_General(Page): pass page_sequence = [ GeneralInstructions, Part1, Reminder_General, BeliefInstructions4a, BeliefInstructions4b, BelievesTopHalf4, Blank, #ExplanationTask, #Resolve, #EnterSolution, #LastPage3, ]