from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random """import time import json""" # def progress(p): # curpageindex = page_sequence.index(type(p))+1 # progress = ((p.round_number-1)*pages_per_round+curpageindex).tot_pages*100 # return progress class Introduction(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' """form_fields = ['fakeUpload']""" class SmileIntensityOne(Page): form_model = 'player' form_fields = [ 'smileIntensityOne1' ] def is_displayed(self): return self.round_number == 1 def get_form_fields(self): fields = self.form_fields return fields def vars_for_template(self): photo = self.session.vars['photo_conditions'][self.participant.id_in_session % 8 - 1] return { # 'progress': progress(self), 'image_path': 'trust_game_demo/Cond_{}_Img_{}.jpg'.format(photo, 1), } class SmileIntensityTwo(Page): form_model = 'player' form_fields = [ 'smileIntensityTwo1', 'smileIntensityTwo2' ] def is_displayed(self): return self.round_number == 1 def get_form_fields(self): fields = self.form_fields random.shuffle(fields) return fields def vars_for_template(self): photo = self.session.vars['photo_conditions'][self.participant.id_in_session % 8 - 1] return { # 'progress': progress(self), 'image_path': 'trust_game_demo/Cond_{}_Img_{}.jpg'.format(photo, 1), } class Liking(Page): form_model = 'player' form_fields = [ 'liking1', 'liking2', 'liking3', 'liking4' ] def is_displayed(self): return self.round_number == 1 def get_form_fields(self): fields = self.form_fields random.shuffle(fields) return fields def vars_for_template(self): photo = self.session.vars['photo_conditions'][self.participant.id_in_session % 8 - 1] return { # 'progress': progress(self), 'image_path': 'trust_game_demo/Cond_{}_Img_{}.jpg'.format(photo, 1), } class Attractiveness(Page): form_model = 'player' form_fields = [ 'attractiveness1', 'attractiveness2', 'attractiveness3' ] def is_displayed(self): return self.round_number == 1 def get_form_fields(self): fields = self.form_fields random.shuffle(fields) return fields def vars_for_template(self): photo = self.session.vars['photo_conditions'][self.participant.id_in_session % 8 - 1] return { # 'progress': progress(self), 'image_path': 'trust_game_demo/Cond_{}_Img_{}.jpg'.format(photo, 1), } class Trust(Page): form_model = 'player' form_fields = [ 'trust1', 'trust2', 'trust3', 'trust4', 'trust5' ] def is_displayed(self): return self.round_number == 1 def get_form_fields(self): fields = self.form_fields random.shuffle(fields) return fields def vars_for_template(self): photo = self.session.vars['photo_conditions'][self.participant.id_in_session % 8 - 1] return { # 'progress': progress(self), 'image_path': 'trust_game_demo/Cond_{}_Img_{}.jpg'.format(photo, 1), } class Handedness(Page): form_model = 'player' form_fields = [ 'handedness1', 'handedness2', 'handedness3', 'handedness4', 'handedness5', 'handedness6', 'handedness7', 'handedness8', 'handedness9', 'handedness10' ] def is_displayed(self): return self.round_number == 1 def get_form_fields(self): fields = self.form_fields random.shuffle(fields) return fields class NarcissismOne(Page): form_model = 'player' form_fields = [ 'narcissism1', 'narcissism2', 'narcissism3', 'narcissism4', 'narcissism5', 'narcissism6', 'narcissism7', 'narcissism8', 'narcissism9', 'narcissism10' ] def is_displayed(self): return self.round_number == 1 def get_form_fields(self): fields = self.form_fields random.shuffle(fields) return fields class NarcissismTwo(Page): form_model = 'player' form_fields = [ 'narcissism11', 'narcissism12', 'narcissism13', 'narcissism14', 'narcissism15', 'narcissism16', 'narcissism17', 'narcissism18', 'narcissism19', 'narcissism20' ] def is_displayed(self): return self.round_number == 1 def get_form_fields(self): fields = self.form_fields random.shuffle(fields) return fields class NarcissismThree(Page): form_model = 'player' form_fields = [ 'narcissism21', 'narcissism22', 'narcissism23', 'narcissism24', 'narcissism25', 'narcissism26', 'narcissism27', 'narcissism28', 'narcissism29', 'narcissism30' ] def is_displayed(self): return self.round_number == 1 def get_form_fields(self): fields = self.form_fields random.shuffle(fields) return fields class NarcissismFour(Page): form_model = 'player' form_fields = [ 'narcissism31', 'narcissism32', 'narcissism33', 'narcissism34', 'narcissism35', 'narcissism36', 'narcissism37', 'narcissism38', 'narcissism39', 'narcissism40' ] def is_displayed(self): return self.round_number == 1 def get_form_fields(self): fields = self.form_fields random.shuffle(fields) return fields class FirstMove(Page): """This page is only for P1 (Player or computer) P1 (if human) can choose to Trade/Trust P2, or cancel the trade. If P1 is the computer, it will automatically choose based on the predetermined list of conditions. """ form_model = 'player' form_fields = ['decision'] """ Only display this page if the current player is P1 """ def is_displayed(self): return self.session.vars['role_conditions'][self.subsession.round_number - 1] == 'First' def vars_for_template(self): photo = self.session.vars['photo_conditions'][self.participant.id_in_session % 8 - 1] return { 'image_path': 'trust_game_demo/Cond_{}_Img_{}.jpg'.format(photo, 1), } class FirstWaitPage(WaitPage): pass """player_is_first = self.session.vars['role_conditions'][self.subsession.round_number - 1] == 'First' if player_is_first: player_traded = FirstMove.player.decision == 1 need_to time.sleep(random.randint(1, 5))""" class CustomWait(Page): def get_timeout_seconds(self): return random.randint(1, 5) class SecondMove(Page): """This page is only for P2 P2 (if human) has to choose whether to Trade/Cooperate with P1, or cancel. As above, if P2 is the computer, it will automatically select the option corresponding to the current condition""" form_model = 'player' form_fields = ['decision'] def is_displayed(self): player_is_second = self.session.vars['role_conditions'][self.subsession.round_number - 1] == 'Second' other_move = self.session.vars['comp_decisions'][self.subsession.round_number - 1] comp_trade = other_move == 'Trade' return player_is_second is True & comp_trade is True def vars_for_template(self): other_move = self.session.vars['comp_decisions'][self.subsession.round_number - 1] photo = self.session.vars['photo_conditions'][self.participant.id_in_session % 8 - 1] return { 'image_path': 'trust_game_demo/Cond_{}_Img_{}.jpg'.format(photo, 1), 'other_move': other_move, 'prompt': 'The above player decided to {}. Would you like to Trade or Cancel?'.format(other_move)} class SecondMoveCancel(Page): """This page is only for P2 P2 (if human) has to choose whether to Trade/Cooperate with P1, or cancel. As above, if P2 is the computer, it will automatically select the option corresponding to the current condition""" def is_displayed(self): player_is_second = self.session.vars['role_conditions'][self.subsession.round_number - 1] == 'Second' other_move = self.session.vars['comp_decisions'][self.subsession.round_number - 1] comp_cancel = other_move == 'Cancel' return player_is_second is True & comp_cancel is True def vars_for_template(self): other_move = self.session.vars['comp_decisions'][self.subsession.round_number - 1] photo = self.session.vars['photo_conditions'][self.participant.id_in_session % 8 - 1] return { 'image_path': 'trust_game_demo/Cond_{}_Img_{}.jpg'.format(photo, 1), 'other_move': other_move, 'prompt': 'The above player decided to {}. Please click Next to continue'.format(other_move)} """class SecondWaitPage(WaitPage): player_is_second = self.session.vars['role_conditions'][self.subsession.round_number - 1] == 'Second' player_traded = FirstMove.player.decision == 1""" class Results(Page): """Do not need to display full results in between each round (?) However, do need to have a field that tracks running total.""" """So, here, replace tripled_amount with previous_round_result and current_total_score/payout?""" def vars_for_template(self): player_is_second = self.session.vars['role_conditions'][self.subsession.round_number - 1] == 'Second' comp_text = self.session.vars['comp_decisions'][self.subsession.round_number - 1] if player_is_second: if comp_text == 'Cancel': comp_desc = 'The other player canceled the trade.' player_desc = 'Since the trade was canceled, no response was required from you.' round_result = 5 comp_result = 5 elif self.player.decision_text() == 'Trade': comp_desc = 'The other player decided to trade with you.' player_desc = 'You decided to accept the trade.' round_result = 6.50 comp_result = 6.50 else: comp_desc = 'The other player decided to trade with you.' player_desc = 'You decided not to accept the trade.' round_result = 10 comp_result = 3 else: if self.player.decision_text() == "Cancel": player_desc = 'You canceled the trade.' comp_desc = 'Since the trade was canceled, no response was required from the other player.' round_result = 5 comp_result = 5 elif comp_text == "Trade": player_desc = 'You decided to trade with the other player.' comp_desc = 'The other player decided to accept the trade.' round_result = 6.5 comp_result = 6.5 else: player_desc = 'You decided to trade with the other player.' comp_desc = 'The other player decided not to accept the trade.' round_result = 3 comp_result = 10 self.player.payoff = round_result self.session.vars['running_total'] = self.session.vars['running_total'] + round_result self.session.vars['comp_total'] = self.session.vars['comp_total'] + comp_result return { 'round_prompt': 'Round {} out of {}'.format(self.subsession.round_number, 12), 'round_desc_prompt': player_desc, 'round_result_prompt': 'You received {} points this round.'.format(round_result), 'comp_desc_prompt': comp_desc, 'comp_result_prompt': 'The other player received {} points.'.format(comp_result), 'comp_total': 'Other player running total: {} points.'.format(self.session.vars['comp_total']), 'running_total': 'Your running total: {} points.'.format(self.session.vars['running_total']) } page_sequence = [ Introduction, SmileIntensityOne, SmileIntensityTwo, Liking, Attractiveness, Trust, NarcissismOne, NarcissismTwo, NarcissismThree, NarcissismFour, Handedness, FirstMove, CustomWait, SecondMove, SecondMoveCancel, Results, ] # pages_per_round = len(page_sequence) # tot_pages = pages_per_round * Constants.num_rounds