from otree.api import * import random author = 'Mike ZhiRen Wu' doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'emo_classification' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 participation_fee = cu(5) pay_round1 = 1 pay_round2 = 3 pay_round3 = 6 pay_round4 = 9 pay_round5 = 10 class Subsession(BaseSubsession): def creating_session(subsession): session = subsession.session session.answer1 = [] session.classification_list1 = [] session.list_total = [] class Group(BaseGroup): total_classification_positive_1 = models.IntegerField() total_classification_negative_1 = models.IntegerField() total_classification_neutral_1 = models.IntegerField() classification_answer_1 = models.IntegerField() total_classification_positive_2 = models.IntegerField() total_classification_negative_2 = models.IntegerField() total_classification_neutral_2 = models.IntegerField() classification_answer_2 = models.IntegerField() total_classification_positive_3 = models.IntegerField() total_classification_negative_3 = models.IntegerField() total_classification_neutral_3 = models.IntegerField() classification_answer_3 = models.IntegerField() total_classification_positive_4 = models.IntegerField() total_classification_negative_4 = models.IntegerField() total_classification_neutral_4 = models.IntegerField() classification_answer_4 = models.IntegerField() total_classification_positive_5 = models.IntegerField() total_classification_negative_5 = models.IntegerField() total_classification_neutral_5 = models.IntegerField() classification_answer_5 = models.IntegerField() total_classification_positive_6 = models.IntegerField() total_classification_negative_6 = models.IntegerField() total_classification_neutral_6 = models.IntegerField() classification_answer_6 = models.IntegerField() total_classification_positive_7 = models.IntegerField() total_classification_negative_7 = models.IntegerField() total_classification_neutral_7 = models.IntegerField() classification_answer_7 = models.IntegerField() total_classification_positive_8 = models.IntegerField() total_classification_negative_8 = models.IntegerField() total_classification_neutral_8 = models.IntegerField() classification_answer_8 = models.IntegerField() total_classification_positive_9 = models.IntegerField() total_classification_negative_9 = models.IntegerField() total_classification_neutral_9 = models.IntegerField() classification_answer_9 = models.IntegerField() total_classification_positive_10 = models.IntegerField() total_classification_negative_10 = models.IntegerField() total_classification_neutral_10 = models.IntegerField() classification_answer_10 = models.IntegerField() def set_payoffs(group): for p in group.get_players(): if p.classification_1 == 1: p.classification_positive_1 = 1 p.classification_negative_1 = 0 p.classification_neutral_1 = 0 elif p.classification_1 == 2: p.classification_positive_1 = 0 p.classification_negative_1 = 1 p.classification_neutral_1 = 0 else: p.classification_positive_1 = 0 p.classification_negative_1 = 0 p.classification_neutral_1 = 1 if p.classification_3 == 1: p.classification_positive_3 = 1 p.classification_negative_3 = 0 p.classification_neutral_3 = 0 elif p.classification_3 == 2: p.classification_positive_3 = 0 p.classification_negative_3 = 1 p.classification_neutral_3 = 0 else: p.classification_positive_3 = 0 p.classification_negative_3 = 0 p.classification_neutral_3 = 1 if p.classification_6 == 1: p.classification_positive_6 = 1 p.classification_negative_6 = 0 p.classification_neutral_6 = 0 elif p.classification_6 == 2: p.classification_positive_6 = 0 p.classification_negative_6 = 1 p.classification_neutral_6 = 0 else: p.classification_positive_6 = 0 p.classification_negative_6 = 0 p.classification_neutral_6 = 1 if p.classification_9 == 1: p.classification_positive_9 = 1 p.classification_negative_9 = 0 p.classification_neutral_9 = 0 elif p.classification_9 == 2: p.classification_positive_9 = 0 p.classification_negative_9 = 1 p.classification_neutral_9 = 0 else: p.classification_positive_9 = 0 p.classification_negative_9 = 0 p.classification_neutral_9 = 1 if p.classification_10 == 1: p.classification_positive_10 = 1 p.classification_negative_10 = 0 p.classification_neutral_10 = 0 elif p.classification_10 == 2: p.classification_positive_10 = 0 p.classification_negative_10 = 1 p.classification_neutral_10 = 0 else: p.classification_positive_10 = 0 p.classification_negative_10 = 0 p.classification_neutral_10 = 1 classification_positives_1 = [p.classification_positive_1 for p in group.get_players()] classification_negatives_1 = [p.classification_negative_1 for p in group.get_players()] classification_neutrals_1 = [p.classification_neutral_1 for p in group.get_players()] classification_positives_3 = [p.classification_positive_3 for p in group.get_players()] classification_negatives_3 = [p.classification_negative_3 for p in group.get_players()] classification_neutrals_3 = [p.classification_neutral_3 for p in group.get_players()] classification_positives_6 = [p.classification_positive_6 for p in group.get_players()] classification_negatives_6 = [p.classification_negative_6 for p in group.get_players()] classification_neutrals_6 = [p.classification_neutral_6 for p in group.get_players()] classification_positives_9 = [p.classification_positive_9 for p in group.get_players()] classification_negatives_9 = [p.classification_negative_9 for p in group.get_players()] classification_neutrals_9 = [p.classification_neutral_9 for p in group.get_players()] classification_positives_10 = [p.classification_positive_10 for p in group.get_players()] classification_negatives_10 = [p.classification_negative_10 for p in group.get_players()] classification_neutrals_10 = [p.classification_neutral_10 for p in group.get_players()] group.total_classification_positive_1 = sum(classification_positives_1) group.total_classification_negative_1 = sum(classification_negatives_1) group.total_classification_neutral_1 = sum(classification_neutrals_1) group.total_classification_positive_3 = sum(classification_positives_3) group.total_classification_negative_3 = sum(classification_negatives_3) group.total_classification_neutral_3 = sum(classification_neutrals_3) group.total_classification_positive_6 = sum(classification_positives_6) group.total_classification_negative_6 = sum(classification_negatives_6) group.total_classification_neutral_6 = sum(classification_neutrals_6) group.total_classification_positive_9 = sum(classification_positives_9) group.total_classification_negative_9 = sum(classification_negatives_9) group.total_classification_neutral_9 = sum(classification_neutrals_9) group.total_classification_positive_10 = sum(classification_positives_10) group.total_classification_negative_10 = sum(classification_negatives_10) group.total_classification_neutral_10 = sum(classification_neutrals_10) if group.total_classification_positive_1 > group.total_classification_negative_1 and group.total_classification_positive_1 > group.total_classification_neutral_1: group.classification_answer_1 = 1 elif group.total_classification_negative_1 > group.total_classification_positive_1 and group.total_classification_negative_1 > group.total_classification_positive_1: group.classification_answer_1 = 2 elif group.total_classification_neutral_1 > group.total_classification_positive_1 and group.total_classification_neutral_1 > group.total_classification_negative_1: group.classification_answer_1 = 3 elif group.total_classification_positive_1 == group.total_classification_negative_1 > group.total_classification_neutral_1: group.classification_answer_1 = random.choice([1, 2]) elif group.total_classification_positive_1 == group.total_classification_neutral_1 > group.total_classification_negative_1: group.classification_answer_1 = random.choice([1, 3]) elif group.total_classification_positive_1 == group.total_classification_neutral_1 > group.total_classification_negative_1: group.classification_answer_1 = random.choice([2, 3]) else: group.classification_answer_1 = random.choice([1, 2, 3]) if group.total_classification_positive_3 > group.total_classification_negative_3 and group.total_classification_positive_3 > group.total_classification_neutral_3: group.classification_answer_3 = 1 elif group.total_classification_negative_3 > group.total_classification_positive_3 and group.total_classification_negative_3 > group.total_classification_positive_3: group.classification_answer_3 = 2 elif group.total_classification_neutral_3 > group.total_classification_positive_3 and group.total_classification_neutral_3 > group.total_classification_negative_3: group.classification_answer_3 = 3 elif group.total_classification_positive_3 == group.total_classification_negative_3 > group.total_classification_neutral_3: group.classification_answer_3 = random.choice([1, 2]) elif group.total_classification_positive_3 == group.total_classification_neutral_3 > group.total_classification_negative_3: group.classification_answer_3 = random.choice([1, 3]) elif group.total_classification_positive_3 == group.total_classification_neutral_3 > group.total_classification_negative_3: group.classification_answer_3 = random.choice([2, 3]) else: group.classification_answer_3 = random.choice([1, 2, 3]) if group.total_classification_positive_6 > group.total_classification_negative_6 and group.total_classification_positive_6 > group.total_classification_neutral_6: group.classification_answer_6 = 1 elif group.total_classification_negative_6 > group.total_classification_positive_6 and group.total_classification_negative_6 > group.total_classification_positive_6: group.classification_answer_6 = 2 elif group.total_classification_neutral_6 > group.total_classification_positive_6 and group.total_classification_neutral_6 > group.total_classification_negative_6: group.classification_answer_6 = 3 elif group.total_classification_positive_6 == group.total_classification_negative_6 > group.total_classification_neutral_6: group.classification_answer_6 = random.choice([1, 2]) elif group.total_classification_positive_6 == group.total_classification_neutral_6 > group.total_classification_negative_6: group.classification_answer_6 = random.choice([1, 3]) elif group.total_classification_positive_6 == group.total_classification_neutral_6 > group.total_classification_negative_6: group.classification_answer_6 = random.choice([2, 3]) else: group.classification_answer_6 = random.choice([1, 2, 3]) if group.total_classification_positive_9 > group.total_classification_negative_9 and group.total_classification_positive_9 > group.total_classification_neutral_9: group.classification_answer_9 = 1 elif group.total_classification_negative_9 > group.total_classification_positive_9 and group.total_classification_negative_9 > group.total_classification_positive_9: group.classification_answer_9 = 2 elif group.total_classification_neutral_9 > group.total_classification_positive_9 and group.total_classification_neutral_9 > group.total_classification_negative_9: group.classification_answer_9 = 3 elif group.total_classification_positive_9 == group.total_classification_negative_9 > group.total_classification_neutral_9: group.classification_answer_9 = random.choice([1, 2]) elif group.total_classification_positive_9 == group.total_classification_neutral_9 > group.total_classification_negative_9: group.classification_answer_9 = random.choice([1, 3]) elif group.total_classification_positive_9 == group.total_classification_neutral_9 > group.total_classification_negative_9: group.classification_answer_9 = random.choice([2, 3]) else: group.classification_answer_9 = random.choice([1, 2, 3]) if group.total_classification_positive_10 > group.total_classification_negative_10 and group.total_classification_positive_10 > group.total_classification_neutral_10: group.classification_answer_10 = 1 elif group.total_classification_negative_10 > group.total_classification_positive_10 and group.total_classification_negative_10 > group.total_classification_positive_10: group.classification_answer_10 = 2 elif group.total_classification_neutral_10 > group.total_classification_positive_10 and group.total_classification_neutral_10 > group.total_classification_negative_10: group.classification_answer_10 = 3 elif group.total_classification_positive_10 == group.total_classification_negative_10 > group.total_classification_neutral_10: group.classification_answer_10 = random.choice([1, 2]) elif group.total_classification_positive_10 == group.total_classification_neutral_10 > group.total_classification_negative_10: group.classification_answer_10 = random.choice([1, 3]) elif group.total_classification_positive_10 == group.total_classification_neutral_10 > group.total_classification_negative_10: group.classification_answer_10 = random.choice([2, 3]) else: group.classification_answer_10 = random.choice([1, 2, 3]) for p in group.get_players(): if p.classification_1 == group.classification_answer_1: p.payoff_1 = 7 else: p.payoff_1 = 0 if p.classification_3 == group.classification_answer_3: p.payoff_2 = 7 else: p.payoff_2 = 0 if p.classification_6 == group.classification_answer_6: p.payoff_3 = 7 else: p.payoff_3 = 0 if p.classification_9 == group.classification_answer_9: p.payoff_4 = 7 else: p.payoff_4 = 0 if p.classification_10 == group.classification_answer_10: p.payoff_5 = 7 else: p.payoff_5 = 0 p.Classification_payoff = p.payoff_1 + p.payoff_2 + p.payoff_3 + p.payoff_4 + p.payoff_5 p.payoff = 5 + p.payoff_1 + p.payoff_2 + p.payoff_3 + p.payoff_4 + p.payoff_5 class Player(BasePlayer): gender = models.StringField(choices=['男', '女']) age = models.IntegerField() major = models.StringField() Classification_payoff = models.IntegerField() payoff_1 = models.IntegerField() payoff_2 = models.IntegerField() payoff_3 = models.IntegerField() payoff_4 = models.IntegerField() payoff_5 = models.IntegerField() classification_positive_1 = models.IntegerField() classification_positive_3 = models.IntegerField() classification_positive_6 = models.IntegerField() classification_positive_9 = models.IntegerField() classification_positive_10 = models.IntegerField() classification_negative_1 = models.IntegerField() classification_negative_3 = models.IntegerField() classification_negative_6 = models.IntegerField() classification_negative_9 = models.IntegerField() classification_negative_10 = models.IntegerField() classification_neutral_1 = models.IntegerField() classification_neutral_3 = models.IntegerField() classification_neutral_6 = models.IntegerField() classification_neutral_9 = models.IntegerField() classification_neutral_10 = models.IntegerField() classification_1 = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, '正面情绪'], [2, '负面情绪'], [3, '没有情绪']]) classification_2 = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, '正面情绪'], [2, '负面情绪'], [3, '没有情绪']]) classification_3 = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, '正面情绪'], [2, '负面情绪'], [3, '没有情绪']]) classification_4 = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, '正面情绪'], [2, '负面情绪'], [3, '没有情绪']]) classification_5 = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, '正面情绪'], [2, '负面情绪'], [3, '没有情绪']]) classification_6 = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, '正面情绪'], [2, '负面情绪'], [3, '没有情绪']]) classification_7 = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, '正面情绪'], [2, '负面情绪'], [3, '没有情绪']]) classification_8 = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, '正面情绪'], [2, '负面情绪'], [3, '没有情绪']]) classification_9 = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, '正面情绪'], [2, '负面情绪'], [3, '没有情绪']]) classification_10 = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, '正面情绪'], [2, '负面情绪'], [3, '没有情绪']]) # PAGES class Welcome(Page): pass class Instruction(Page): pass class Payment_Instruction(Page): pass class Classification_1(Page): form_model = 'player' form_fields = ['classification_1'] class Classification_2(Page): form_model = 'player' form_fields = ['classification_2'] class Classification_3(Page): form_model = 'player' form_fields = ['classification_3'] class Classification_4(Page): form_model = 'player' form_fields = ['classification_4'] class Classification_5(Page): form_model = 'player' form_fields = ['classification_5'] class Classification_6(Page): form_model = 'player' form_fields = ['classification_6'] class Classification_7(Page): form_model = 'player' form_fields = ['classification_7'] class Classification_8(Page): form_model = 'player' form_fields = ['classification_8'] class Classification_9(Page): form_model = 'player' form_fields = ['classification_9'] class Classification_10(Page): form_model = 'player' form_fields = ['classification_10'] class Classification_Adjustment(Page): form_model = 'player' form_fields = ['classification_1', 'classification_2', 'classification_3', 'classification_4', 'classification_5', 'classification_6', 'classification_7', 'classification_8', 'classification_9', 'classification_10'] class Questionnaire(Page): form_model = 'player' form_fields = ['gender', 'age', 'major'] class BeforeResult(Page): pass class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' class Results(Page): pass page_sequence = [ Welcome, Instruction, Payment_Instruction, Classification_1, Classification_2, Classification_3, Classification_4, Classification_5, Classification_6, Classification_7, Classification_8, Classification_9, Classification_10, Classification_Adjustment, Questionnaire, BeforeResult, ResultsWaitPage, Results, ]