from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants #from builtins import Constants class Welcome(Page): def is_displayed(self) -> bool: return self.round_number == 1 class InstructionsStrangerMatching(Page): def is_displayed(self) -> bool: return self.round_number == 1 def vars_for_template(self): return { 'GG': Constants.payoff_meyou_GG, 'LL': Constants.payoff_meyou_LL, 'LG': Constants.payoff_meyou_LG, 'GL': Constants.payoff_meyou_GL, 'rounds_with_stranger': min(Constants.num_rounds,self.session.config['partner_matching_start_round']-1), } class InstructionsPartnerMatching(Page): def is_displayed(self) -> bool: return self.round_number == self.session.config['partner_matching_start_round'] def vars_for_template(self): return { 'GG': Constants.payoff_meyou_GG, 'LL': Constants.payoff_meyou_LL, 'LG': Constants.payoff_meyou_LG, 'GL': Constants.payoff_meyou_GL, 'rounds_with_partner': max(0,Constants.num_rounds-self.session.config['partner_matching_start_round']+1), } class Choice(Page): form_model = 'player' form_fields = ['choice'] def vars_for_template(self): return { 'GG': Constants.payoff_meyou_GG, 'LL': Constants.payoff_meyou_LL, 'LG': Constants.payoff_meyou_LG, 'GL': Constants.payoff_meyou_GL, 'current_round': self.round_number if self.subsession.matching == "stranger" else self.round_number - self.session.config['partner_matching_start_round'] + 1, 'rounds_with_stranger': min(Constants.num_rounds,self.session.config['partner_matching_start_round']-1), 'rounds_with_partner': max(0,Constants.num_rounds-self.session.config['partner_matching_start_round']+1), } class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() class Results(Page): def vars_for_template(self): return { 'my_choice': self.player.choice, 'others_choice': self.group.get_player_by_id(self.player.id_in_group % 2 + 1).choice, 'my_payoff': self.player.payoff, } class ResultsSummary(Page): def is_displayed(self) -> bool: return self.round_number == Constants.num_rounds def vars_for_template(self): stranger_rounds = self.session.config['rounds_stranger'] partner_rounds = self.session.config['rounds_partner'] self.player.participant_vars_dump = str(self.player.participant.vars) print(str(self.player.participant.vars)) return { 'my_choices_stranger': [self.player.in_round(round).choice for round in stranger_rounds], 'others_choices_stranger': [self.player.in_round(round).others_choice for round in stranger_rounds], 'my_payoff_stranger': [self.player.in_round(round).payoff for round in stranger_rounds], 'my_total_stranger_payoff': sum([self.player.in_round(round).payoff for round in stranger_rounds]), 'my_total_stranger_payoff_euro': (sum([self.player.in_round(round).payoff for round in stranger_rounds]).to_real_world_currency(self.session) if len(stranger_rounds) > 0 else None), 'my_choices_partner': [self.player.in_round(round).choice for round in partner_rounds], 'others_choices_partner': [self.player.in_round(round).others_choice for round in partner_rounds], 'my_payoff_partner': [self.player.in_round(round).payoff for round in partner_rounds], 'my_total_partner_payoff': sum([self.player.in_round(round).payoff for round in partner_rounds]), 'my_total_partner_payoff_euro': (sum([self.player.in_round(round).payoff for round in partner_rounds]).to_real_world_currency(self.session) if len(partner_rounds) > 0 else None), } class WaitForAll(WaitPage): wait_for_all_groups = False class EmptyPage(Page): pass page_sequence = [ Welcome, WaitForAll, InstructionsStrangerMatching, InstructionsPartnerMatching, WaitForAll, Choice, ResultsWaitPage, #EmptyPage, Results, ResultsSummary ]