from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from . import models from .models import Constants import random import itertools import numpy as np from sklearn.utils import shuffle class InformationLetter(Page): def is_displayed(self): return self.round_number == 1 class InformedConsent(Page): def is_displayed(self): return self.round_number == 1 class Introduction(Page): # timeout_seconds = 600 def is_displayed(self): return self.round_number == 1 def vars_for_template(self): if self.round_number == 1: self.player.shuffle_once() form_model = models.Player form_fields = ['test_question_{}'.format(ii) for ii in range(1, 5)] def error_message(self, values): if values['test_question_1'] != 45 or values['test_question_2'] != 10 or values[ 'test_question_3'] != 40 or values['test_question_4'] != 'True': return 'One or more test questions is incorrect, please either re-read instructions and try again' class AgeGender(Page): def is_displayed(self): return self.round_number == 1 form_model = models.Player form_fields = ['age', 'gender'] # # class Final(Page): # def is_displayed(self): # return self.round_number == Constants.num_rounds # # def vars_for_template(self): # self.player.round_to_pay() # # self.player.calculate_final_payout() # # # def after_all_players_arrive(self): # self.player.round_to_pay() # # self.player.calculate_final_payout() # # # def before_session_starts(self): # self.round_list = range(1, self.round_number + 1) # self.payout_chosen_trial = shuffle(self.round_list) # # self.participant.vars['payout_chosen_trial'] = self.payout_chosen_trial[0] # this page is absolutely essential because it somehow prevents # the current_offer from being set to None. class AnotherWaitPage(Page): # wait_for_all_groups = True def vars_for_template(self): self.player.set_responder_identity() assert self.player.current_offer != None timeout_seconds = .001 # chatgpt's code (doesn't work) # class Offer(Page): # # timeout_seconds = 600 # def vars_for_template(self): # assert self.player.current_offer is not None # self.player.set_responder_identity() # form_model = models.Player # form_fields = ['amount_returned'] # def get_form(self, data=None, files=None, **kwargs): # form = super().get_form(data=data, files=files, **kwargs) # form.fields['amount_returned'].choices = self.amount_returned_choices() # return form # def amount_returned_choices(self): # choices = list(range(0, self.player.current_offer_mult_3 + 1)) # return choices ### this is mine, it used to work, the above is chatgpt's class Offer(Page): ### code that used to work--my code!!! # timeout_seconds = 600 def vars_for_template(self): # self.group.initial_slider_setter() assert self.player.current_offer != None self.player.set_responder_identity() # self.group.set_return_options() form_model = models.Player form_fields = ['amount_returned'] # form_fields = ['amount_offered'] # def amount_returned_choices(self): # # choices = [0, self.group.current_offer] # choices = [ii for ii in range(0, self.player.current_offer_mult_3+1)] # return choices ##### class ResultsWaitPage(WaitPage): pass class Results(Page): def vars_for_template(self): self.group.set_payoffs() self.player.set_payoffs() # self.group.set_responder_identity() # self.session.config['treatment'] == 'strategy' if self.session.config['order'] == 'soc_first': if self.session.config['order'] == 'soc_first': if self.round_number <= (Constants.num_rounds/4): self.group.soc_or_no = 'Social' if self.group.current_opponent == 'opp1': return {'image_path': 'my_trust_RL/block1_images/circle_filled.png'} elif self.group.current_opponent == 'opp2': return {'image_path': 'my_trust_RL/block1_images/stairs_filled.png'} elif self.group.current_opponent == 'opp3': return {'image_path': 'my_trust_RL/block1_images/star_filled.png'} elif self.round_number > (Constants.num_rounds/4): self.group.soc_or_no = 'Non-social' if self.group.current_opponent == 'opp1': return {'image_path': 'my_trust_RL/block2_images/square_frame.png'} elif self.group.current_opponent == 'opp2': return {'image_path': 'my_trust_RL/block2_images/helix_frame.png'} elif self.group.current_opponent == 'opp3': return {'image_path': 'my_trust_RL/block2_images/clover_frame.png'} elif self.session.config['order'] == 'comp_first': if self.round_number > (Constants.num_rounds / 4): self.group.soc_or_no = 'Social' if self.group.current_opponent == 'opp1': return {'image_path': 'my_trust_RL/block3_images/bird_filled.png'} elif self.group.current_opponent == 'opp2': return {'image_path': 'my_trust_RL/block3_images/tetris_F_filled.png'} elif self.group.current_opponent == 'opp3': return {'image_path': 'my_trust_RL/block3_images/trapazoid_filled.png'} elif self.round_number <= (Constants.num_rounds / 4): self.group.soc_or_no = 'Non-social' if self.group.current_opponent == 'opp1': return {'image_path': 'my_trust_RL/block4_images/diamond_frame.png'} elif self.group.current_opponent == 'opp2': return {'image_path': 'my_trust_RL/block4_images/crescent_frame.png'} elif self.group.current_opponent == 'opp3': return {'image_path': 'my_trust_RL/block4_images/triangle_frame.png'} # def after_all_players_arrive(self): # self.group.set_payoffs() page_sequence = [ InformationLetter, InformedConsent, AgeGender, Introduction, AnotherWaitPage, Offer # Results # Final ]