from random import choices from re import A from django.forms import RadioSelect from otree.api import * author = 'Aoi Kokado' doc = """ 演習Ⅲ論文用実験 """ class Constants(BaseConstants): name_in_url = 'Jikken_2022' players_per_group = 2 num_rounds = 12 instructions_template = 'Jikken_2022/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): total_points = models.CurrencyField() class Player(BasePlayer): join = models.StringField( choices=[['提携', '提携'], ['自社', '自社']], label='参入方法を選択してください。', widget=widgets.RadioSelectHorizontal, ) units_1 = models.StringField( choices=[['2', '2'], ['3', '3'], ['4', '4'], ['5', '5']], label='生産量Aの選択', widget=widgets.RadioSelectHorizontal, ) units_2 = models.StringField( choices=[['2', '2'], ['3', '3'], ['4', '4'], ['5', '5']], label='生産量Bの選択', widget=widgets.RadioSelectHorizontal, ) points_1 = models.CurrencyField(label='生産量Aのポイントを記入してください。(半角)') points_2 = models.CurrencyField(label='生産量Bのポイントを記入してください。(半角)') # FUNCTIONS def creating_session(subsession: Subsession): if subsession.round_number == 1: subsession.group_randomly() else: subsession.group_like_round(1) def other_player(player: Player): return player.get_others_in_group()[0] def other_player(player: Player): return player.get_others_in_group()[0] def other_player(player: Player): return player.get_others_in_group()[0] # PAGES class Introduction(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Decide_1(Page): # timeout_seconds = 40 form_model = 'player' form_fields = ['join'] class ResultsWaitPage_1(WaitPage): body_text = "相手の参入方法の選択を待っています。" class choiced(Page): timeout_seconds = 10 @staticmethod def vars_for_template(player: Player): return dict(other_player_join=other_player(player).join) class outputs_1(Page): @staticmethod def vars_for_template(player: Player): return dict(other_player_join=other_player(player).join) @staticmethod def is_displayed(player: Player): return player.join == '自社' and other_player(player).join == '自社' # timeout_seconds = 60 form_model = 'player' form_fields = ['units_1', 'units_2'] class outputs_2(Page): @staticmethod def vars_for_template(player: Player): return dict(other_player_join=other_player(player).join) @staticmethod def is_displayed(player: Player): return player.join == '自社' and other_player(player).join == '提携' # timeout_seconds = 60 form_model = 'player' form_fields = ['units_1', 'units_2'] class outputs_3(Page): @staticmethod def vars_for_template(player: Player): return dict(other_player_join=other_player(player).join) @staticmethod def is_displayed(player: Player): return player.join == '提携' and other_player(player).join == '自社' # timeout_seconds = 60 form_model = 'player' form_fields = ['units_1', 'units_2'] class outputs_4(Page): @staticmethod def vars_for_template(player: Player): return dict(other_player_join=other_player(player).join) @staticmethod def is_displayed(player: Player): return player.join == '提携' and other_player(player).join == '提携' # timeout_seconds = 60 form_model = 'player' form_fields = ['units_1', 'units_2'] class ResultsWaitPage_2(WaitPage): body_text = "相手の生産量の決定を待っています。" class Results_1_a(Page): # timeout_seconds = 90 @staticmethod def is_displayed(player: Player): return player.join == '自社' and other_player(player).join == '自社' and player.id_in_group == 1 @staticmethod def vars_for_template(player: Player): return dict( other_player_join=other_player(player).join, other_player_units_1=other_player(player).units_1, other_player_units_2=other_player(player).units_2, ) form_model = 'player' form_fields = ['points_1', 'points_2'] class Results_1_b(Page): # timeout_seconds = 90 @staticmethod def is_displayed(player: Player): return player.join == '自社' and other_player(player).join == '自社' and player.id_in_group == 2 @staticmethod def vars_for_template(player: Player): return dict( other_player_join=other_player(player).join, other_player_units_1=other_player(player).units_1, other_player_units_2=other_player(player).units_2, ) form_model = 'player' form_fields = ['points_1', 'points_2'] class Results_2_a(Page): # timeout_seconds = 90 @staticmethod def is_displayed(player: Player): return player.join == '自社' and other_player(player).join == '提携' and player.id_in_group == 1 @staticmethod def vars_for_template(player: Player): return dict( other_player_join=other_player(player).join, other_player_units_1=other_player(player).units_1, other_player_units_2=other_player(player).units_2, ) form_model = 'player' form_fields = ['points_1', 'points_2'] class Results_2_b(Page): # timeout_seconds = 90 @staticmethod def is_displayed(player: Player): return player.join == '自社' and other_player(player).join == '提携' and player.id_in_group == 2 @staticmethod def vars_for_template(player: Player): return dict( other_player_join=other_player(player).join, other_player_units_1=other_player(player).units_1, other_player_units_2=other_player(player).units_2, ) form_model = 'player' form_fields = ['points_1', 'points_2'] class Results_3_a(Page): # timeout_seconds = 90 @staticmethod def is_displayed(player: Player): return player.join == '提携' and other_player(player).join == '自社' and player.id_in_group == 1 @staticmethod def vars_for_template(player: Player): return dict( other_player_join=other_player(player).join, other_player_units_1=other_player(player).units_1, other_player_units_2=other_player(player).units_2, ) form_model = 'player' form_fields = ['points_1', 'points_2'] class Results_3_b(Page): # timeout_seconds = 90 @staticmethod def is_displayed(player: Player): return player.join == '提携' and other_player(player).join == '自社' and player.id_in_group == 2 @staticmethod def vars_for_template(player: Player): return dict( other_player_join=other_player(player).join, other_player_units_1=other_player(player).units_1, other_player_units_2=other_player(player).units_2, ) form_model = 'player' form_fields = ['points_1', 'points_2'] class Results_4_a(Page): # timeout_seconds = 90 @staticmethod def is_displayed(player: Player): return player.join == '提携' and other_player(player).join == '提携' and player.id_in_group == 1 @staticmethod def vars_for_template(player: Player): return dict( other_player_join=other_player(player).join, other_player_units_1=other_player(player).units_1, other_player_units_2=other_player(player).units_2, ) form_model = 'player' form_fields = ['points_1', 'points_2'] class Results_4_b(Page): # timeout_seconds = 90 @staticmethod def is_displayed(player: Player): return player.join == '提携' and other_player(player).join == '提携' and player.id_in_group == 2 @staticmethod def vars_for_template(player: Player): return dict( other_player_join=other_player(player).join, other_player_units_1=other_player(player).units_1, other_player_units_2=other_player(player).units_2, ) form_model = 'player' form_fields = ['points_1', 'points_2'] class ResultsWaitPage_3(WaitPage): pass class points(Page): pass page_sequence = [ Introduction, Decide_1, ResultsWaitPage_1, choiced, outputs_1, outputs_2, outputs_3, outputs_4, ResultsWaitPage_2, Results_1_a, Results_1_b, Results_2_a, Results_2_b, Results_3_a, Results_3_b, Results_4_a, Results_4_b, ResultsWaitPage_3, points, ]