from otree.api import * doc = """ Each player decides what job to choose ... game made by Galiya """ class C(BaseConstants): NAME_IN_URL = 'usaid_game' PLAYERS_PER_GROUP = 10 NUM_ROUNDS = 10 INSTRUCTIONS_TEMPLATE = 'usaid_game/instructions.html' SALARY_MIN = 80000 SALARY_MAX = 160000 STEP = (SALARY_MAX - SALARY_MIN)/PLAYERS_PER_GROUP class Subsession(BaseSubsession): pass class Group(BaseGroup): num_blue_jobseekers = models.IntegerField() num_white_jobseekers= models.IntegerField() class Player(BasePlayer): lang = models.StringField( choices=[['kz', 'қазақ тілі'], ['ru', 'русский язык']], label='Выберите язык игры / Тілді таңдаңыз', widget=widgets.RadioSelect, ) if lang == 'kz': from .lexicon_kz import Lexicon else: from .lexicon_ru import Lexicon position = models.IntegerField(label=Lexicon.position_label) consent = models.BooleanField() jobseeker = models.BooleanField(choices=Lexicon.jobseeker_choices, label=Lexicon.jobseeker_label) age = models.IntegerField(label =Lexicon.age_label, min=10, max=100) gender = models.StringField(choices=Lexicon.gender_choices, label=Lexicon.gender_label, widget=widgets.RadioSelect, ) city = models.StringField( choices=Lexicon.city_choices, label=Lexicon.city_label, widget=widgets.RadioSelect, ) education = models.StringField( choices=Lexicon.education_choices, label=Lexicon.education_label, widget=widgets.RadioSelect, ) education_mother = models.StringField( choices=Lexicon.education_choices, label=Lexicon.education_mother_label, widget=widgets.RadioSelect, ) education_father = models.StringField( choices=Lexicon.education_choices, label=Lexicon.education_farther_label, widget=widgets.RadioSelect, ) job_father = models.StringField( choices=Lexicon.job_father_choices, label=Lexicon.job_father_label, widget=widgets.RadioSelect, ) job_mother = models.StringField( choices=Lexicon.job_father_choices, label=Lexicon.job_mother_label, widget=widgets.RadioSelect, ) blue_job_salary = models.IntegerField( label=Lexicon.blue_job_salary_label) white_job_salary = models.IntegerField( label=Lexicon.white_job_salary_label) employment_status = models.StringField( choices=Lexicon.employment_status_choices, label=Lexicon.employment_status_label, widget=widgets.RadioSelect, ) employment = models.StringField( choices=Lexicon.employment_choices, label=Lexicon.employment_label, widget=widgets.RadioSelect, ) job_self = models.StringField( choices=Lexicon.job_self_choices, label=Lexicon.job_self_label, widget=widgets.RadioSelect, ) unemployment = models.StringField( choices=Lexicon.unemployment_choices, label=Lexicon.unemployment_label, widget=widgets.RadioSelect, ) # FUNCTIONS def set_payoffs(group: Group): players = group.get_players() group.num_blue_jobseekers = sum([p.jobseeker for p in players]) group.num_white_jobseekers = C.PLAYERS_PER_GROUP-sum([p.jobseeker for p in players]) for p in players: p.payoff = C.SALARY_MIN + C.STEP * sum([p.jobseeker for p in players]) if p.jobseeker: p.payoff = C.SALARY_MAX - C.STEP * sum([p.jobseeker for p in players]) # PAGES class Languagechoice (Page): form_model = 'player' form_fields = ['lang'] class ConsentForm(Page): def is_displayed(player: Player): return player.round_number == 1 class Introduction(Page): def is_displayed(player: Player): return player.round_number == 1 form_model = 'player' form_fields = ['position'] class Decision(Page): form_model = 'player' form_fields = ['jobseeker'] @staticmethod def vars_for_template(player: Player): lang = player.lang if lang == 'kz': from .lexicon_kz import Lexicon else: from .lexicon_ru import Lexicon return dict(Lexicon=Lexicon) class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): def vars_for_template(player: Player): lang = player.lang if lang == 'kz': from .lexicon_kz import Lexicon else: from .lexicon_ru import Lexicon return dict(Lexicon=Lexicon, others = player.get_others_in_group(), round_1_players = player.in_round(1).get_others_in_group(), mean_rounds = sum([p.payoff for p in player.in_all_rounds()])/player.round_number, payoff_other = C.SALARY_MAX + C.SALARY_MIN - player.payoff) class Finalsurvey(Page): form_model = 'player' form_fields = ['age', 'gender', 'city', 'education', 'education_mother', 'education_father', 'job_father', 'job_mother', 'blue_job_salary', 'white_job_salary', 'employment_status', 'employment', 'job_self', 'unemployment' ] def is_displayed(player: Player): return player.round_number == C.NUM_ROUNDS @staticmethod def vars_for_template(player: Player): lang = player.lang if lang == 'kz': from .lexicon_kz import Lexicon else: from .lexicon_ru import Lexicon return dict(Lexicon=Lexicon) class Exit(Page): def vars_for_template(player: Player): lang = player.lang if lang == 'kz': from .lexicon_kz import Lexicon else: from .lexicon_ru import Lexicon return dict(Lexicon=Lexicon, final_payoff = 2000 + 0.02*sum([p.payoff for p in player.in_all_rounds()])/C.NUM_ROUNDS) def is_displayed(player: Player): return player.round_number == C.NUM_ROUNDS page_sequence = [ Languagechoice, ConsentForm, Introduction, Decision, ResultsWaitPage, Results, Finalsurvey, Exit ]