from otree.api import * import math import pandas as pd import itertools import numpy as np class C(BaseConstants): NAME_IN_URL = 'results' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 1 RESULTS_TEMPLATE = 'cpr_results/templates/results.html' SURVEY_TEMPLATE = 'cpr_results/templates/survey.html' ELICITATION_TEMPLATE = 'cpr_results/templates/elicitation.html' ECUS_PER_POUND = 100 POUNDS_PER_ECU = 1 / ECUS_PER_POUND PARTICIPATION_FEE = 3 # SVO_VALUES = pd.read_csv("cpr_defaults/svo_values.csv") class Subsession(BaseSubsession): pass def creating_session(subsession): pass class Group(BaseGroup): pass class Player(BasePlayer): extraction = models.IntegerField(initial=0) motivation = models.LongStringField( label="In the last task, what was your reasoning behind your desired extraction?", initial="") default_thoughts = models.LongStringField( label="Did the presence of a default value in the first 5 rounds affected your desired extraction?") feedback = models.LongStringField( label="Are there any comments or feedback you would like to provide for this experiment?", initial="") knowledge_gametheory = models.LongStringField( label="Were you familiar with these types of experiment?", initial="") game_theory_concept = models.IntegerField( widget=widgets.RadioSelect, choices=[0,1,2,3,4,5] ) behavioural_experiment_concept = models.IntegerField( widget=widgets.RadioSelect, choices=[0, 1, 2, 3, 4, 5] ) cpr_concept = models.IntegerField( widget=widgets.RadioSelect, choices=[0, 1, 2, 3, 4, 5] ) internal_id = models.IntegerField() chosen_task = models.IntegerField() payoff_pounds = models.CurrencyField() total_payoff_exp = models.CurrencyField() # FUNCTIONS # PAGES class Results(Page): @staticmethod def vars_for_template(player): player.payoff = 0 player.payoff_pounds = 0 player.participant.payoff_task3 = np.round(player.participant.payoff_task3, 2) if player.participant.payoff_task3 < 0: player.participant.payoff_task3 = 0 if player.participant.role_svo == "A": player.participant.payoff_task1 = player.participant.self_payoff_task_1 else: other_players = player.get_others_in_subsession() for p in other_players: if p.participant.role_svo == "A" and p.participant.other_payoff_task_1 > 0: player.participant.payoff_task1 = p.participant.other_payoff_task_1 player.participant.self_option_task_1 = p.participant.self_option_task_1 if player.participant.payoff_task1 == 0: # if they come first or there aren't any A's with payoffs picked player.participant.payoff_task1 = player.participant.self_payoff_task_1 if player.participant.completion_status == "incomplete": player.participant.completion_status = "completed" player.payoff = player.participant.payoff_task1 + player.participant.payoff_task2 + player.participant.payoff_task3 player.payoff_pounds = player.payoff * C.POUNDS_PER_ECU player.total_payoff_exp = player.payoff_pounds + C.PARTICIPATION_FEE class Survey(Page): form_model = 'player' # form_fields = ['motivation', 'feedback', 'knowledge_gametheory', "concepts_gametheory"] @staticmethod def is_displayed(player): return player.participant.finished_participant is False @staticmethod def get_form_fields(player): if int(player.subsession.session.config["default_extraction"]) > 0: return ['motivation', "default_thoughts", 'feedback', 'knowledge_gametheory', "game_theory_concept", "behavioural_experiment_concept", "cpr_concept"] else: return ['motivation', 'feedback', 'knowledge_gametheory', "game_theory_concept", "behavioural_experiment_concept", "cpr_concept"] @staticmethod def vars_for_template(player): default = int(player.subsession.session.config["default_extraction"]) > 0 return dict(default = default) @staticmethod def before_next_page(player, timeout_happened): player.participant.finished_participant = True player.participant.reason_finished = "You successfully completed the three tasks. You will be paid for your time and the extra bonus. Total bonus= £%.2f" % player.payoff_pounds page_sequence = [Results, Survey] # page_sequence = [Survey]