from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) #from .fields import OtherModelField import random #random.init() import itertools import json treat_op = ( (0, 'control'), (1, 'public'), (2, 'consumption'), ) subtreat_op = ( (0, 'control'), (1, 'transfer'), (2, 'outside'), ) class Constants(BaseConstants): name_in_url = "BE_coinflip" players_per_group = 2 tasks = ['1', '2', '3', '4'] num_rounds = len(tasks) new_template = "BE_coinflip/new.html" class Subsession(BaseSubsession): # def before_session_starts(self): # for g in self.get_groups(): # g.type = self.session.config['type'] # for g in self.get_groups(): # g.treatment = self.session.config['treatment'] # for g in self.get_groups(): # g.subtreatment = self.session.config['subtreatment'] def creating_session(self): for player in self.get_players(): slider_initial = random.randint(0, 50) player.slider_initial = slider_initial player.slider = slider_initial #if self.participant.vars['gender'] == "M": # self.player.id_in_group = 2 #elif self.participant.vars['gender'] == "F": # self.player.id_in_group = 1 type = itertools.cycle(['EPH']) for g in self.get_groups(): g.type = next(type) treatment = itertools.cycle([0, 0, 0, 1, 1, 1, 2, 2, 2]) for g in self.get_groups(): g.treatment = next(treatment) subtreatment = itertools.cycle([0, 1, 2]) for g in self.get_groups(): g.subtreatment = next(subtreatment) if self.round_number == 1: for p in self.get_players(): round_numbers = list(range(1, Constants.num_rounds + 1)) random.shuffle(round_numbers) p.participant.vars['task_rounds'] = dict(zip(Constants.tasks, round_numbers)) class Group(BaseGroup): def random_num(): return random.randint(0, 10) ########## UNDERSTANDING QUESTIONS ######## understand_marble = models.IntegerField() understand_plate = models.IntegerField( label="", choices=[ [0, 'The bad plate - খারাপ বাটি'], [1, 'The good plate - ভাল বাটি'], ], ) treatment = models.IntegerField( choices=[ [0, 'Control'], [1, 'Consumption'], [2, 'Public'], ] ) subtreatment = models.IntegerField( choices=[ [0, 'Normal'], [1, 'Transfer'], [2, 'Outside_Option'], ] ) type = models.StringField( choices=[ 'EA', 'EPC', 'EPH', ] ) #################### PUNISHMENT EXPERIMENT #################### riceplate_practice = models.IntegerField( label="", choices=[ [0, 'The bad plate - খারাপ বাটি'], [1, 'The good plate - ভাল বাটি'], ], ) be01 = models.IntegerField( label="", choices=[ [0, 'The bad plate - খারাপ বাটি'], [1, 'The good plate - ভাল বাটি'], ], ) be02 = models.IntegerField( label="", choices=[ [0, "No sound - শব্দ শুনতে চাই না"], [1, "Sound - শব্দ শুনতে চাই "], ], ) be03 = models.IntegerField( label="", choices=[ [0, "Blue - নীল "], [1, "Red - লাল"], ], ) be03_w = models.IntegerField( label="", choices=[ [0, 'No Food- আমি পুরুষটিকে খাবার দিতে চাই না '], [1, 'Yes Give Food - আমি পুরুষটিকে খাবার দিতে চাই'], ] ) #### FOR SIGNALING TEST ### signaling = models.IntegerField( label="", min=0, max=50, widget=widgets.Slider(attrs={'step': '5'}), default=random_num, ) class Player(BasePlayer): slider_initial = models.IntegerField() slider = models.IntegerField( label="", min=0, max=50, widget=widgets.Slider(attrs={'step': '1'}), ) public_schedule = models.IntegerField( label='', choices=[ [1, 'Punishment Private'], [0, 'Punishment Public'], ], ) # UNDERSTANDING QUESTIONS understand1 = models.IntegerField( label='', choices=[ [1, 'The good bag'], [0, 'The bad bag'], ], ) understand1a = models.IntegerField( label="", choices=[ [0, 'The bad plate - খারাপ বাটি'], [1, 'The good plate - ভাল বাটি'], ], ) understand1b = models.IntegerField( label="", choices=[ [0, 'The bad plate - খারাপ বাটি'], [1, 'The good plate - ভাল বাটি'], ], ) understand1c = models.IntegerField( label="", choices=[ [0, 'The bad plate - খারাপ বাটি'], [1, 'The good plate - ভাল বাটি'], ], ) understand2 = models.IntegerField( label='', choices=[ [1, 'The good bag'], [0, 'The bad bag'], ], ) understand2a = models.IntegerField( label="", choices=[ [0, 'The bad plate - খারাপ বাটি'], [1, 'The good plate - ভাল বাটি'], ], ) understand2b = models.IntegerField( label="", choices=[ [0, 'The bad plate - খারাপ বাটি'], [1, 'The good plate - ভাল বাটি'], ], ) understand2c = models.IntegerField( label="", choices=[ [0, 'The bad plate - খারাপ বাটি'], [1, 'The good plate - ভাল বাটি'], ], ) understand2c_cons = models.IntegerField( label="", choices=[ [0, 'The bad plate - খারাপ বাটি'], [1, 'The good plate - ভাল বাটি'], ], ) plateget = models.IntegerField( label="", choices=[ [0, 'The bad plate - খারাপ বাটি'], [1, 'The good plate - ভাল বাটি'], ], ) whyplateget = models.LongStringField() ### Defining questions for counter question1 = models.IntegerField(initial=0, blank=True) question2 = models.IntegerField(initial=0, blank=True) question3 = models.IntegerField(initial=0, blank=True) question4 = models.IntegerField(initial=0, blank=True) question5 = models.IntegerField(initial=0, blank=True) question6 = models.IntegerField(initial=0, blank=True) question7 = models.IntegerField(initial=0, blank=True) question8 = models.IntegerField(initial=0, blank=True) question9 = models.IntegerField(initial=0, blank=True) def counter1(self): self.question1 = self.question1 + 1 print('counter1', self.question1) def counter1a(self): self.question2 = self.question2 + 1 print('counter1a', self.question2) def counter1b(self): self.question3 = self.question3 + 1 print('counter1b', self.question3) def counter1c(self): self.question4 = self.question4 + 1 print('counter1c', self.question4) def counter2(self): self.question5 = self.question5 + 1 print('counter2', self.question5) def counter2a(self): self.question6 = self.question6 + 1 print('counter2a', self.question6) def counter2b(self): self.question7 = self.question7 + 1 print('counter2b', self.question7) def counter2c(self): self.question8 = self.question8 + 1 print('counter2c', self.question8) def counter2c_cons(self): self.question9 = self.question9 + 1 print('counter2c_cons', self.question9) def understand1_error_message(self, value): if value is not 1: self.counter1() return 'Wrong answer. Please review the instructions!' def understand1a_error_message(self, value): if value is not 1: self.counter1a() return 'Wrong answer. Please review the instructions!' def understand1b_error_message(self, value): if value is not 0: self.counter1b() return 'Wrong answer. Please review the instructions!' def understand1c_error_message(self, value): if value is not 1: self.counter1c() return 'Wrong answer. Please review the instructions!' def understand2_error_message(self, value): if value is not 0: self.counter2() return 'Wrong answer. Please review the instructions!' def understand2a_error_message(self, value): if value is not 1: self.counter2a() return 'Wrong answer. Please review the instructions!' def understand2b_error_message(self, value): if value is not 0: self.counter2b() return 'Wrong answer. Please review the instructions!' def understand2c_error_message(self, value): if value is not 1: self.counter2c() return 'Wrong answer. Please review the instructions!' def understand2c_cons_error_message(self, value): if value is not 0: self.counter2c_cons() return 'Wrong answer. Please review the instructions!' def random_num(): return random.randint(0, 10) def role(self): # write your code here return {'W': "A", 'M': "B"}[self.participant.vars.gender] ######################################################################################################### sound_dislike = models.IntegerField( label="", choices=[ [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], ], widget=widgets.RadioSelectHorizontal(), ) punishment_work = models.IntegerField( label="", choices=[ [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], ], widget=widgets.RadioSelectHorizontal(), ) enumerator_ID = models.StringField( label="Name of enumerator?", choices=[ "Sakib", "Dilshad", "Anne", "Hasib", ], ) practice = models.IntegerField( label="Is this a real game?", choices=[ [1, "Yes"], [0, "No"], ], ) be01a_man = models.IntegerField( label="", min=0, max=40, widget=widgets.Slider(attrs={'step': '1'}, show_value=False), default=random_num, ) be01b_man = models.IntegerField( label="", min=0, max=100, widget=widgets.Slider(attrs={'step': '5'}), ) be02a_man = models.IntegerField( label="", min=0, max=40, widget=widgets.Slider(attrs={'step': '1'}, show_value=False), ) be02b_man = models.IntegerField( label="", min=0, max=100, widget=widgets.Slider(attrs={'step': '5'}), ) HHID = models.IntegerField( label="Household ID", min=0, max=100, ) person_id = models.IntegerField( label="Person ID", min=0, max=100, ) plate = models.IntegerField( label="", choices=[ [0, 'The bad plate - খারাপ বাটি'], [1, 'The good plate - ভাল বাটি'], ], ) be01a_stored = models.IntegerField() be01b_stored = models.IntegerField() be02a_stored = models.IntegerField() be02b_stored = models.IntegerField() be01a_stored_m = models.IntegerField() be01b_stored_m = models.IntegerField() be02a_stored_m = models.IntegerField() be02b_stored_m = models.IntegerField() def guess_be01a_man(self): self.participant.vars['be01a_man_st'] = self.be01a_man print('Slider is', self.participant.vars['be01a_man_st'], 'if she keeps good plate') def guess_be01b_man(self): self.participant.vars['be01b_man_st'] = self.be01b_man print('Slider is', self.participant.vars['be01b_man_st'], 'for money if she keeps the good plate') # print(self.be01b_man) def guess_be02a_man(self): self.participant.vars['be02a_man_st'] = self.be02a_man print('Slider is', self.participant.vars['be02a_man_st'], 'for sound if she keeps the bad plate') # print(self.be02a_man) def guess_be02b_man(self): self.participant.vars['be02b_man_st'] = self.be02b_man print('Slider is', self.participant.vars['be02b_man_st'], 'for money if she keeps tha bad plate') def other_player(self): return self.get_others_in_group()[0] def vars_for_template(self): if self.group.subtreatment != 1 and self.id_in_group == 1: # What I am doing: set the model field value and return that model field in dict() # I've done it for this and the next condition. self.be01a_stored = self.other_player().participant.vars['be01a_man_st'] self.be02a_stored = self.other_player().participant.vars['be02a_man_st'] return dict( be01a_stored=self.be01a_stored, be02a_stored=self.be02a_stored, ) elif self.group.subtreatment == 1 and self.id_in_group == 1: self.be01a_stored = self.other_player().participant.vars['be01a_man_st'] self.be01b_stored = self.other_player().participant.vars['be01b_man_st'] self.be02a_stored = self.other_player().participant.vars['be02a_man_st'] self.be02b_stored = self.other_player().participant.vars['be02b_man_st'] return dict( be01a_stored=self.be01a_stored, be01b_stored=self.be01b_stored, be02a_stored=self.be02a_stored, be02b_stored=self.be02b_stored, ) elif self.group.subtreatment != 1 and self.id_in_group == 2: self.be01a_stored_m = self.participant.vars['be01a_man_st'] self.be02a_stored_m = self.participant.vars['be02a_man_st'] return dict( be01a_stored_m=self.be01a_stored_m, be02a_stored_m=self.be02a_stored_m, ) elif self.group.subtreatment == 1 and self.id_in_group == 2: self.be01a_stored_m = self.participant.vars['be01a_man_st'] self.be02a_stored_m = self.participant.vars['be02a_man_st'] self.be01b_stored_m = self.participant.vars['be01b_man_st'] self.be02b_stored_m = self.participant.vars['be02b_man_st'] return dict( be01a_stored_m=self.be01a_stored_m, be01b_stored_m=self.be01b_stored_m, be02a_stored_m=self.be02a_stored_m, be02b_stored_m=self.be02b_stored_m, ) ############################################################## # FEEDBACK QUESTIONS feedback1 = models.LongStringField(label="") feedback2 = models.LongStringField(label="") extra_comment = models.LongStringField(label="") people_watching = models.LongStringField(label="") ##############################################################