def play_round(self): if self.round_number == 1: yield (pages.InstructionsPage) max_value = Participant.get_experiment( self.player).phase_three.auction( self.player.round_number).max_value yield SubmissionMustFail(pages.BidPage, {'bid': -1}) yield SubmissionMustFail(pages.BidPage, {'bid': max_value + 1}) yield SubmissionMustFail(pages.BidPage) yield (pages.BidPage, {'bid': 0}) assert self.player.bid == 0 else: max_value = Participant.get_experiment( self.player).phase_three.auction( self.player.round_number).max_value r_bid = random.randint(0, max_value) yield (pages.BidPage, {'bid': r_bid}) assert self.player.bid == r_bid, "Entered bid {}, Player bid {}".format( r_bid, self.player.bid) signal = Participant.get_experiment( self.player).phase_three.signal(self.player.round_number) bid = Participant.get_experiment(self.player).phase_three.auction( self.player.round_number).get_bid(signal) assert bid == r_bid, "Entered bid {}, Auction bid {}".format( r_bid, bid)
def before_next_page(self): experiment = Participant.get_experiment(self.player) experiment.phase_four.set_cutoff(self.round_number, float(self.player.cutoff)) experiment.phase_four.set_bet(self.round_number, self.player.bet) self.player.lottery = Participant.get_experiment(self.player).phase_four.get_lottery(self.round_number).lid self.player.question = experiment.phase_four.get_lottery(self.round_number).lid
def after_all_players_arrive(self): players = self.group.get_players()[:] for i, player in enumerate(players): player_id = player.participant.id_in_session others = players[:i] + players[i + 1:] other_player = random.choice(others) other_id = other_player.participant.id_in_session experiment = Participant.get_experiment(player) other_experiment = Participant.get_experiment(other_player) payment_method = PaymentMethod(player_id, other_id, experiment, other_experiment) method_one_results = payment_method.method_one_payment( MethodOneResults()) method_two_results = payment_method.method_two_payment( MethodTwoResults()) method_three_results = payment_method.method_three_results( MethodThreeResults()) Participant.set_payment_one_results(player, method_one_results) Participant.set_payment_two_results(player, method_two_results) Participant.set_payment_three_results(player, method_three_results) part_one_earnings = method_one_results.earnings + method_two_results.earnings part_one_payoff = experiment.PART_ONE_WEIGHT * part_one_earnings * experiment.CONVERSION_RATE part_two_payoff = experiment.PART_TWO_WEIGHT * method_three_results.earnings * experiment.CONVERSION_RATE final_payoff = experiment.SHOW_UP_FEE + experiment.ENDOWMENT + part_one_payoff + part_two_payoff player.payoff = final_payoff player.save_results(method_one_results, method_two_results, method_three_results)
def play_round(self): if self.round_number == 1: yield (pages.InstructionsPage) max_value = Participant.get_experiment( self.player).phase_two.get_auction( self.player.round_number).max_value yield SubmissionMustFail(pages.CutoffSelectionPage, { 'cutoff': -1, 'clicked': 1 }) yield SubmissionMustFail(pages.CutoffSelectionPage, { 'cutoff': max_value + 1, 'clicked': 1 }) yield (pages.CutoffSelectionPage, {'cutoff': 0, 'clicked': 1}) assert self.player.cutoff == 0 else: max_value = Participant.get_experiment( self.player).phase_two.get_auction( self.player.round_number).max_value r_cutoff = random.randint(0, max_value) yield (pages.CutoffSelectionPage, { 'cutoff': r_cutoff, 'clicked': 1 }) assert self.player.cutoff == r_cutoff, "Entered cutoff {}, Player cutoff {}".format( r_cutoff, self.player.cutoff) cutoff = Participant.get_experiment( self.player).phase_two.get_auction( self.player.round_number).cutoff assert cutoff == r_cutoff, "Entered cutoff {}, Auction cutoff {}".format( r_cutoff, cutoff)
def before_next_page(self): experiment = Participant.get_experiment(self.player) experiment.phase_two.set_cutoff(self.round_number, float(self.player.cutoff)) self.player.auction = experiment.phase_two.get_auction( self.round_number).aid
def before_next_page(self): experiment = Participant.get_experiment(self.player) experiment.phase_three.set_bid(self.round_number, float(self.player.bid)) self.player.auction = experiment.phase_three.auction(self.round_number).aid self.player.signal = experiment.phase_three.signal(self.round_number) self.player.low_update = experiment.phase_three.low_update(self.round_number) self.player.high_update = experiment.phase_three.high_update(self.round_number)
def before_next_page(self): experiment = Participant.get_experiment(self.player) self.player.left_auction = experiment.phase_one.left_auction( self.round_number).aid self.player.right_auction = experiment.phase_one.right_auction( self.round_number).aid experiment.phase_one.set_preference(self.round_number, self.player.preference)
def play_round(self): if self.player.round_number == 1: yield (pages.InstructionsPage) yield SubmissionMustFail(pages.SelectAuctionPage, {'preference': 1000000}) yield SubmissionMustFail(pages.SelectAuctionPage) yield (pages.SelectAuctionPage, {'preference': -1}) assert self.player.preference == -1 else: auction_ids = [ Participant.get_experiment(self.player).phase_one.left_auction(self.player.round_number).aid, Participant.get_experiment(self.player).phase_one.right_auction(self.player.round_number).aid, -1] random_auction_id = random.choice(auction_ids) yield (pages.SelectAuctionPage, {'preference': random_auction_id}) assert self.player.preference == random_auction_id, "actual preference was {}".format(self.player.preference) auction_id = Participant.get_experiment(self.player).phase_one.get_preference(self.player.round_number) assert random_auction_id == auction_id, "expected {}, but received {}".format(random_auction_id, auction_id)
def vars_for_template(self): experiment = Participant.get_experiment(self.player) lottery = experiment.phase_four.get_lottery(self.round_number) return { 'lottery': lottery, 'lottery_type': lottery.ltype, 'low_value': lottery.low_value, 'high_value': lottery.high_value, 'bet_high_red': lottery.BET_HIGH_RED, 'bet_high_blue': lottery.BET_HIGH_BLUE, 'num_red': lottery.number_red if lottery.has_number_red() else '', 'num_blue': lottery.number_blue if lottery.has_number_blue() else '', 'bags': [(i, lottery.total - i) for i in range(lottery.total + 1)] }
def vars_for_template(self): experiment = Participant.get_experiment(self.player) results = Participant.get_payment_one_results(self.player) random_position = 'Left' if results.left_auction.aid == results.auction.aid else 'Right' if results.preferred_position == experiment.phase_one.LEFT: preferred_position = 'Left' elif results.preferred_position == experiment.phase_one.RIGHT: preferred_position = 'Right' else: preferred_position = 'Indifferent' if results.random_signal_is_percentage: random_signal = round(results.random_signal * 100, 2) else: random_signal = results.random_signal if results.other_random_signal_is_percentage: others_random_signal = round(results.other_random_signal * 100, 2) else: others_random_signal = results.other_random_signal return { 'player_id': results.player_id, 'other_id': results.other_player_id, 'preferred_position': preferred_position, 'left_auction': results.left_auction, 'right_auction': results.right_auction, 'auction': results.auction, 'random_position': random_position, 'bid': results.bid, 'others_bid': results.other_bid, 'winner': results.lottery_won, 'signal_is_percentage': results.random_signal_is_percentage, 'signal': random_signal, 'others_signal': others_random_signal, 'others_signal_is_percentage': results.other_random_signal_is_percentage, 'low_value': results.low_value, 'high_value': results.high_value, 'low_prob': round(results.low_prob * 100, 2), 'high_prob': round(results.high_prob * 100, 2), 'high_chosen': results.high_prize_chosen, 'earnings': results.earnings, 'realized': results.realized, 'auction_type': results.auction.atype, 'low_prize_chosen': results.low_prize_chosen, 'high_prize_chosen': results.high_prize_chosen, }
def vars_for_template(self): experiment = Participant.get_experiment(self.player) auction = experiment.phase_three.auction(self.round_number) if auction.signal_is_percentage: signals = ", ".join(["{}%".format(round(s * 100)) for s in auction.signals]) else: signals = ", ".join(map(str, auction.signals)) return { 'signal_is_percentage': auction.signal_is_percentage, 'auction': auction, 'signal': experiment.phase_three.signal(self.round_number), 'low_update': experiment.phase_three.low_update(self.round_number), 'high_update': experiment.phase_three.high_update(self.round_number), 'signals': signals, }
def vars_for_template(self): experiment = Participant.get_experiment(self.player) method_one = Participant.get_payment_one_results(self.player) method_two = Participant.get_payment_two_results(self.player) method_three = Participant.get_payment_three_results(self.player) part_one_earnings = method_one.earnings + method_two.earnings part_one_payoff = experiment.PART_ONE_WEIGHT * part_one_earnings * experiment.CONVERSION_RATE part_two_payoff = experiment.PART_TWO_WEIGHT * method_three.earnings * experiment.CONVERSION_RATE final_payoff = experiment.SHOW_UP_FEE + experiment.ENDOWMENT + part_one_payoff + part_two_payoff return { 'show_up_fee': experiment.SHOW_UP_FEE, 'endowment': experiment.ENDOWMENT, 'rate': experiment.CONVERSION_RATE, 'method_1': round(method_one.earnings, 2), 'method_2': round(method_two.earnings, 2), 'method_3': round(method_three.earnings, 2), 'total_in_credits': round(part_one_earnings, 2), 'earnings_1': round(part_one_payoff, 2), 'earnings_2': round(part_two_payoff, 2), 'final_payoff': round(final_payoff, 2), }
def play_round(self): if self.round_number == 1: # Instructions Page yield (pages.InstructionsPage) # Roll Dice Page: Test incorrect input yield SubmissionMustFail(pages.RollDicePage, {'die_side': 0}) yield SubmissionMustFail(pages.RollDicePage, {'die_side': 7}) yield SubmissionMustFail(pages.RollDicePage) # Roll Dice Page: Test correct input r_side = random.randint(1, 6) yield (pages.RollDicePage, {'die_side': r_side}) assert self.player.die_side == r_side, "Entered die-side {}, Player die-side {}".format( r_side, self.player.die_side) die_side = Participant.get_experiment( self.player).phase_four.die_side assert die_side == r_side, "Entered die-side {}, Phase die-side {}".format( r_side, die_side) # Bid and Cutoff Entry Page: Test incorrect input lottery = Participant.get_experiment( self.player).phase_four.get_lottery(self.player.round_number) r_bet = random.choice( [lottery.BET_HIGH_RED, lottery.BET_HIGH_BLUE]) r_cutoff = random.randint(lottery.min_cutoff, lottery.max_cutoff) yield SubmissionMustFail(pages.MinBuyoutBetForLotteryPage, ) yield SubmissionMustFail(pages.MinBuyoutBetForLotteryPage, {'cutoff': lottery.min_cutoff}) yield SubmissionMustFail(pages.MinBuyoutBetForLotteryPage, { 'cutoff': lottery.max_cutoff, 'bet': lottery.BET_HIGH_RED }) yield SubmissionMustFail( pages.MinBuyoutBetForLotteryPage, { 'cutoff': lottery.max_cutoff + 1, 'bet': lottery.BET_HIGH_RED, 'clicked': 1 }) yield SubmissionMustFail( pages.MinBuyoutBetForLotteryPage, { 'cutoff': lottery.min_cutoff - 1, 'bet': lottery.BET_HIGH_RED, 'clicked': 1 }) # Bid and Cutoff Entry Page: Test correct input yield (pages.MinBuyoutBetForLotteryPage, { 'cutoff': r_cutoff, 'bet': r_bet, 'clicked': 1 }) assert self.player.cutoff == r_cutoff, "Entered cutoff {}, Player cutoff {}".format( r_cutoff, self.player.cutoff) assert self.player.bet == r_bet, "Entered bet {}, Player bet {}".format( r_cutoff, self.player.bet) assert self.player.clicked == 1, "Entered clicked {}, Player clicked {}".format( 1, self.player.clicked) else: lottery = Participant.get_experiment( self.player).phase_four.get_lottery(self.player.round_number) r_bet = random.choice( [lottery.BET_HIGH_RED, lottery.BET_HIGH_BLUE]) r_cutoff = random.randint(lottery.min_cutoff, lottery.max_cutoff) yield (pages.MinBuyoutBetForLotteryPage, { 'cutoff': r_cutoff, 'bet': r_bet, 'clicked': 1 }) assert self.player.cutoff == r_cutoff, "Entered cutoff {}, Player cutoff {}".format( r_cutoff, self.player.cutoff) assert self.player.bet == r_bet, "Entered bet {}, Player bet {}".format( r_cutoff, self.player.bet) assert self.player.clicked == 1, "Entered clicked {}, Player clicked {}".format( 1, self.player.clicked)
def cutoff_min(self): experiment = Participant.get_experiment(self.player) return experiment.phase_two.get_auction(self.round_number).min_value
def vars_for_template(self): experiment = Participant.get_experiment(self.player) return {'auction': experiment.phase_two.get_auction(self.round_number)}
def before_next_page(self): experiment = Participant.get_experiment(self.player) experiment.phase_four.set_die_side(self.player.die_side)
def preference_error_message(self, value): experiment = Participant.get_experiment(self.player) if not experiment.phase_one.is_valid_auction_id( self.round_number, int(value)): return 'Please select on one of the three options by pressing the corresponding green button'
def vars_for_template(self): experiment = Participant.get_experiment(self.player) return experiment.phase_one.get_auction_pair_dict(self.round_number)
def bid_error_message(self, bid): experiment = Participant.get_experiment(self.player) min_value = experiment.phase_three.auction(self.round_number).min_value max_value = experiment.phase_three.auction(self.round_number).max_value if not min_value <= bid <= max_value: return 'The bid value must be between {} and {}.'.format(min_value, max_value)
def cutoff_min(self): experiment = Participant.get_experiment(self.player) return experiment.phase_four.get_lottery(self.round_number).min_cutoff