class Group(BaseGroup): # variables that change for each group treatment_endowment = models.IntegerField() treatment_treatment = models.TextField() a_takes = models.DecimalField(min=0, max=100, max_digits=5, decimal_places=2) total_taken = models.CurrencyField() b_predicts = models.PositiveIntegerField(min=0, max=100) b_willing = models.DecimalField(min=0, max_digits=6, decimal_places=3) b_message = models.TextField() b_message_price = models.DecimalField(max_digits=5, decimal_places=2) price_method = models.TextField() price_display = models.TextField() b_eligible = models.BooleanField() target_income = models.DecimalField(max_digits=5, decimal_places=2) reader_index = models.IntegerField() def final_pay(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.final_reward = self.treatment_endowment+ p1.task_reward + self.total_taken if self.price_method != 'WTA': if self.b_eligible: p2.final_reward = self.treatment_endowment+ p2.task_reward - self.total_taken - self.b_message_price else: p2.final_reward = self.treatment_endowment + p2.task_reward - self.total_taken else: # WTA if self.b_eligible: p2.final_reward = self.treatment_endowment + p2.task_reward - self.total_taken else: # gave up right to send message p2.final_reward = self.treatment_endowment + p2.task_reward - self.total_taken + self.b_message_price def reader_pay(self): for p in self.get_players(): p.final_reward = self.treatment_endowment + p.task_reward
class Group(BaseGroup): prize = models.StringField(choices=['игрок A', 'игрок B'], widget=widgets.RadioSelect()) def get_winner_name(self): s = self.prize.replace('игрок', 'игрок{}') return { 'nominative': s.format(''), 'genitive': s.format('а'), 'dative': s.format('у'), 'accusative': s.format('а'), 'instrumental': s.format('ом'), 'prepositional': s.format('е'), } contribution_A = models.IntegerField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", ) contribution_B = models.IntegerField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", ) task_corrects_A = models.IntegerField(default=0) task_corrects_B = models.IntegerField(default=0) def set_pay(self): if self.prize == 'игрок A': for p in self.get_players(): if p.role() == "игрок A": p.pay = (Constants.endowment - self.contribution_A + Constants.prize) elif p.role() == "игрок B": p.pay = (Constants.endowment - self.contribution_B) elif p.role() == "судья": p.pay = (Constants.endowment + self.contribution_A + self.contribution_B) else: for p in self.get_players(): if p.role() == "игрок A": p.pay = (Constants.endowment - self.contribution_A) elif p.role() == "игрок B": p.pay = (Constants.endowment - self.contribution_B + Constants.prize) elif p.role() == "судья": p.pay = (Constants.endowment + self.contribution_A + self.contribution_B) def set_payoff(self): # this is the payoff of the paid rounds for player in self.get_players(): for rounds in self.session.vars['paying_rounds']: if player.round_number == rounds: player.payoff = player.pay
class Player(BasePlayer): amount_to_destroy = models.IntegerField( min=0, max=3, doc="""Amount of your partner's vouchers you set to destroy.""", ) destroyed = models.IntegerField(default=0) points = models.IntegerField(default=0)
class Player(BasePlayer): riskchoice1 = models.CharField(max_length=50, choices=sorted(Constants.loteries1), widget=widgets.RadioSelectHorizontal()) riskchoice2 = models.CharField(max_length=50, choices=sorted(Constants.loteries2), widget=widgets.RadioSelectHorizontal()) riskchoice3 = models.CharField(max_length=50, choices=sorted(Constants.loteries3), widget=widgets.RadioSelectHorizontal()) riskchoice4 = models.CharField(max_length=50, choices=sorted(Constants.loteries4), widget=widgets.RadioSelectHorizontal()) selected_puzzle = models.IntegerField(choices=[1, 2, 3, 4]) wining_range = models.JSONField(default=None) roll = models.IntegerField() def get_wining_range(self): if not self.wining_range: if self.selected_puzzle in (1, 2): self.wining_range = [1, 5] elif self.selected_puzzle in (3, 4): self.wining_range = random.choice(Constants.random_ranges) return self.wining_range def get_selected_puzzle(self): initial_payoff = 0 if self.selected_puzzle in (1, 3) else 10 if self.selected_puzzle == 1: return 1, self.riskchoice1, Constants.loteries1, self.get_wining_range( ), initial_payoff if self.selected_puzzle == 2: return 2, self.riskchoice2, Constants.loteries2, self.get_wining_range( ), initial_payoff if self.selected_puzzle == 3: return 3, self.riskchoice3, Constants.loteries3, self.get_wining_range( ), initial_payoff return 4, self.riskchoice4, Constants.loteries4, self.get_wining_range( ), initial_payoff def set_payoff(self): self.selected_puzzle = random.randint(1, 4) sp, choice, loteries, wrange, initial_payoff = self.get_selected_puzzle( ) lotery = loteries[choice] self.roll = random.randint(1, 10) if self.roll <= wrange[-1]: self.payoff = initial_payoff + lotery[0] else: self.payoff = initial_payoff + lotery[1]
class Player(BasePlayer): mpcr = models.FloatField(doc='''marginal per capital reutrn ''') is_correct = models.BooleanField(doc="did the user get the task correct?") final_score = models.IntegerField( doc="player's total score up to this round") quiz_text = models.CharField(doc="quiz question") quiz_sol = models.IntegerField(doc="solution") quiz_user_answer = models.FloatField(verbose_name='Your answer:', min=0, max=999, initial=None, doc='quiz answer') quiz_sol_text = models.CharField(doc="solution text")
class Player(BasePlayer): subperiod_time = models.PositiveIntegerField( doc="""The length of the real effort task timer.""") period_number = models.PositiveIntegerField(doc='''period number''') subperiod_number = models.PositiveIntegerField(doc='''subperiod number''') rp = models.FloatField(doc='''customer reserve price''') mc = models.FloatField(doc='''firm mill cost''') transport_cost = models.FloatField(doc="""transport, or shopping cost""") loc = models.FloatField(doc="player's location") price = models.FloatField(doc="player's price in previous round/subperiod") next_subperiod_price = models.FloatField( doc="player's price in current round/subperiod") boundary_lo = models.FloatField(doc="player's low end of boundary") boundary_hi = models.FloatField(doc="player's high end of boundary") prev_round_payoff = models.FloatField( doc="player's payoffs this previous round/subperiod") prev_round_cumulative_payoff = models.FloatField( doc="player's payoffs cumulative the previous round/subperiod.") paid_period = models.IntegerField( doc='''1 if this is a paid period, 0 otherwise''')
class Player(BasePlayer): def score_round(self): # update player payoffs if (self.correct_text == self.user_text): self.is_correct = True self.payoff_score = 1 else: self.is_correct = False self.payoff_score = 0 task_timer = models.PositiveIntegerField( doc="""The length of the real effort task timer.""" ) correct_text = models.CharField( doc="user's transcribed text") user_text = models.CharField( doc="user's transcribed text", widget=widgets.TextInput(attrs={'autocomplete':'off'})) is_correct = models.BooleanField( doc="did the user get the task correct?") ret_final_score = models.IntegerField( doc="player's total score up to this round") payoff_score = models.FloatField( doc = '''score in this task''' )
class Player(BasePlayer): decision1 = models.CharField(max_length=50, choices=sorted(Constants.options), widget=widgets.RadioSelectHorizontal()) decision2 = models.CharField(max_length=50, choices=sorted(Constants.options), widget=widgets.RadioSelectHorizontal()) decision3 = models.CharField(max_length=50, choices=sorted(Constants.options), widget=widgets.RadioSelectHorizontal()) decision4 = models.CharField(max_length=50, choices=sorted(Constants.options), widget=widgets.RadioSelectHorizontal()) decision5 = models.CharField(max_length=50, choices=sorted(Constants.options), widget=widgets.RadioSelectHorizontal()) decision6 = models.CharField(max_length=50, choices=sorted(Constants.options), widget=widgets.RadioSelectHorizontal()) decision7 = models.CharField(max_length=50, choices=sorted(Constants.options), widget=widgets.RadioSelectHorizontal()) decision8 = models.CharField(max_length=50, choices=sorted(Constants.options), widget=widgets.RadioSelectHorizontal()) decision9 = models.CharField(max_length=50, choices=sorted(Constants.options), widget=widgets.RadioSelectHorizontal()) decision10 = models.CharField(max_length=50, choices=sorted(Constants.options), widget=widgets.RadioSelectHorizontal()) selected_decision = models.IntegerField() def get_decision(self): option = getattr(self, "decision{}".format(self.selected_decision)) return option, Constants.options[option], Constants.decisions[self.selected_decision-1] def set_payoff(self): self.selected_decision = random.randint(1, 10) option, option_desc, decision = self.get_decision() self.payoff = decision[option] def fields_iterator(self): for idx in range(1, 11): yield getattr(self, "decision{}".format(idx))
class Group(BaseGroup): total_production = models.IntegerField(initial=0) # define group variable # determine total production: def set_total_production(self): total_production = sum(p.production_strings for p in self.get_players()) # retrieves a list of all individual productions # and sums them up self.total_production = total_production # determine income: def set_incomes(self): for p in self.get_players(): if self.round_number == 2: # second round is paid to the high wage p.income_strings_gross = p.production_strings * Constants.tokensper_string_high p.net_income = p.income_strings_gross + p.income_in_switch else: p.income_strings_gross = p.production_strings * Constants.tokensper_string p.net_income = p.income_strings_gross + p.income_in_switch for p in self.get_players(): p.participant.vars[ f'net_income_{self.round_number}'] = p.net_income print('vars is', p.participant.vars) # determine payoffs: def set_payoffs(self): for p in self.get_players(): p.earnings = p.net_income p.payoff = p.net_income * Constants.eurosper_token
class Player(BasePlayer): ret_timer = models.PositiveIntegerField( doc="""The length of the real effort task timer.""") user_text = models.CharField(doc="user's transcribed text") is_correct = models.BooleanField(doc="did the user get the task correct?") ret_final_score = models.IntegerField( doc="player's total score up to this round") round_payoff = models.FloatField( doc= "total number of correct real effort tasks, completed before timer expired" ) def set_final_score(self): correct_cnt = 0 for p in self.in_all_rounds(): if p.round_payoff != None: correct_cnt = correct_cnt + p.round_payoff else: correct_cnt = correct_cnt + 0 if correct_cnt == None: self.ret_final_score = 20 elif (correct_cnt < 10): self.ret_final_score = 2 + (2 * correct_cnt) else: self.ret_final_score = 20
class Player(BasePlayer): user_text = models.CharField( doc="user's transcribed text") is_correct = models.BooleanField( doc="did the user get the task correct?") final_score = models.IntegerField( doc="player's total score up to this round") quiz_01 = models.PositiveIntegerField( verbose_name='Your earnings:', min = 0, max = 999, initial=None, doc='quiz answer') quiz_02 = models.PositiveIntegerField( verbose_name='Your earnings:', min = 0, max = 999, initial=None, doc='quiz answer') quiz_03 = models.PositiveIntegerField( verbose_name='Your earnings:', min = 0, max = 999, initial=None, doc='quiz answer') quiz_04 = models.FloatField( verbose_name='Your earnings:', min = 0, max = 999, initial=None, doc='quiz answer') quiz_05 = models.FloatField( verbose_name='Your earnings:', min = 0, max = 999, initial=None, doc='quiz answer') quiz_06= models.FloatField( verbose_name='Your earnings:', min = 0, max = 999, initial=None, doc='quiz answer') quiz_07 = models.FloatField( verbose_name='Your earnings:', min = 0, max = 999, initial=None, doc='quiz answer')
class Subsession(BaseSubsession): paying_round = models.IntegerField() def before_session_starts(self): for p in self.get_players(): p.set_prices() if self.round_number == Constants.num_rounds: self.paying_round = random.randint(1, Constants.num_rounds) self.session.vars['paying_round'] = self.paying_round
class Player(BasePlayer): def computer_destroyed_points(self): choice = random.choice([0,1]) if choice == 1: # heads nothing self.coin_toss = "Heads" else: # tails all self.vouchers = 0 self.coin_toss = "Tails" player_destroyed = models.IntegerField(min=0) computer_destroyed = models.IntegerField(default=0) vouchers = models.IntegerField(default=0) coin_toss = models.CharField()
class Player(BasePlayer): my_entity = models.CharField( choices=Constants.c_entity, verbose_name="De quelle entité avez-vous la responsabilité?", widget=widgets.RadioSelect()) # Phase 1 nb_mcf1 = models.IntegerField(min=0, max=10) nb_mcf2 = models.IntegerField(min=0, max=10) nb_mcf3 = models.IntegerField(min=0, max=10) nb_mcffinal = models.IntegerField(min=0, max=10) # Phase 2 salaire_moyen = models.IntegerField(min=0) nb_mcf_avec_salaire_moyen = models.IntegerField(min=0) # Phase 3 hff = models.IntegerField(min=0, max=240) cout_vacation_avec_hff = models.IntegerField(min=0, max=180000) # GlobalResults cout_total = models.IntegerField(min=0) recettes = models.TextField( verbose_name="Quelle(s) source(s) de financement imaginez-vous?") commentaires = models.TextField(blank=True, verbose_name="Commentaires libres:")
class Player(BasePlayer): iban = IBANField(verbose_name="IBAN") bic = BICField(verbose_name="BIC") bankname = models.CharField(verbose_name="Nachname:", max_length=50) bankvname = models.CharField(verbose_name="Vorname:", max_length=50) street = models.CharField(verbose_name="Straße / Hausnr.:", max_length=50) city = models.CharField(verbose_name="Stadt:", max_length=50) zipcode = models.IntegerField(verbose_name="PLZ:") user_agent = models.CharField() window_height = models.CharField() window_width = models.CharField() ibanmsgseen = models.PositiveIntegerField(default=0)
class Player(BasePlayer): def role(self): if self.id_in_group == 1: return "игрок A" elif self.id_in_group == 2: return "игрок B" else: return "судья" last_correct_answer = models.IntegerField() tasks_correct = models.IntegerField(default=0) tasks_attempted = models.IntegerField(default=0) pay = models.CurrencyField() training_answer_A = models.IntegerField(verbose_name='Игрок A заработает') training_answer_B = models.IntegerField(verbose_name='Игрок B заработает') training_answer_C = models.IntegerField(verbose_name='Судья заработает')
class Player(BasePlayer): skewchoice1 = models.CharField(max_length=50, choices=sorted(Constants.skewchoices1), widget=widgets.RadioSelectHorizontal()) skewchoice2 = models.CharField(max_length=50, choices=sorted(Constants.skewchoices2), widget=widgets.RadioSelectHorizontal(), null=True, blank=True) skewchoice3 = models.CharField(max_length=50, choices=sorted(Constants.skewchoices3), widget=widgets.RadioSelectHorizontal(), null=True, blank=True) winning_choice = models.IntegerField() def selected_skew(self): if self.skewchoice3: return 3, self.skewchoice3, Constants.skewchoices3[ self.skewchoice3] if self.skewchoice2: return 2, self.skewchoice2, Constants.skewchoices2[ self.skewchoice2] return 1, self.skewchoice1, Constants.skewchoices1[self.skewchoice1] def set_payoff(self): snum, soption, choices = self.selected_skew() sample = [] for idx, e in enumerate(Constants.pie_data): sample.extend([idx] * e) self.winning_choice = random.choice(sample) self.payoff = choices[self.winning_choice]
class Player(BasePlayer): test = models.CharField(choices=["test1", "test2", "test3"]) intensity_group = models.CharField(choices=Constants.c_groups) balls_before_draw = models.CharField() balls_after_draw = models.CharField() ball_position_drawn = models.IntegerField() game_played = models.CharField(choices=Constants.c_games) offer_0 = models.FloatField() price_0 = models.FloatField() won_offer_price = models.BooleanField() give_shock = models.IntegerField(choices=[0, 1]) def set_ballsbeforedraw(self, x): self.balls_before_draw = json.dumps(x) def get_ballsbeforedraw(self): return json.loads(self.balls_before_draw) def set_ballsafterdraw(self, x): self.balls_after_draw = json.dumps(x) def get_ballsafterdraw(self): return json.loads(self.balls_after_draw) def determine_and_apply_drawing_result(self): if self.price_0 > self.offer_0: self.won_offer_price = False else: self.won_offer_price = True if self.won_offer_price: if self.game_played == '1ball': # '1ball': Exchange 1 red ball temp = self.get_ballsafterdraw() temp[temp.index( Constants.c_ball_colors[1])] = Constants.c_ball_colors[0] self.set_ballsafterdraw(temp) elif self.game_played == '2balls': # '2balls': Exchange 2 red balls temp = self.get_ballsafterdraw() temp[temp.index( Constants.c_ball_colors[1])] = Constants.c_ball_colors[0] temp[temp.index( Constants.c_ball_colors[1])] = Constants.c_ball_colors[0] self.set_ballsafterdraw(temp) def draw_ball(self): self.ball_position_drawn = random.randint(1, Constants.c_number_of_balls) temp = self.get_ballsafterdraw() print("temp:", temp) print("temp[self.ball_position_drawn - 1]:", temp[2]) print("self.ball_position_drawn:", self.ball_position_drawn) print("Constants.c_ball_colors[1]", Constants.c_ball_colors[1]) if temp[self.ball_position_drawn] == Constants.c_ball_colors[1]: self.give_shock = 1 else: self.give_shock = 0 print("self.give_shock:", self.give_shock) def role(self): if self.id_in_group == 1: return 'Experimenter' else: return 'Player'
class Player(BasePlayer): sex = models.IntegerField(initial=None, choices=[(1, 'Femme'), (0, 'Homme')], verbose_name='Sexe', widget=widgets.RadioSelect()) sisters_brothers = models.IntegerField( initial=None, choices=[(1, 'Oui'), (0, 'Non')], verbose_name='Avez-vous des frères et soeurs', widget=widgets.RadioSelect()) religion = models.IntegerField(initial=None, choices=[(0, 'Catholique'), (1, 'Juive'), (2, 'Musulmane'), (3, 'Protestante'), (4, 'Autres religions'), (5, 'Aucune')], verbose_name='Religion', widget=widgets.RadioSelect()) religion_practice = models.IntegerField( initial='0', verbose_name= 'Pratiquez-vous régulièrement votre religion ? (de 0: Jamais,' 'à 5: Toujours)', widget=widgets.SliderInput(attrs={ 'step': '1', 'min': '0', 'max': '5' })) student = models.IntegerField(initial=None, choices=[(1, 'Oui'), (0, 'Non')], verbose_name='Etes-vous étudiant(e) ?', widget=widgets.RadioSelect()) field_of_studies = models.IntegerField( initial=None, choices=[(0, 'Economie-Gestion'), (1, 'Droit'), (2, 'Sciences politiques'), (3, 'Psychologie'), (4, 'Autres sciences sociales'), (5, 'Mathématiques'), (6, 'Sciences'), (7, 'Autres')], verbose_name= 'Discipline étudiée (actuellement ou lorsque vous étiez étudiant(e)) ?', widget=widgets.RadioSelect()) level_of_study = models.IntegerField(initial=None, choices=[ (0, 'Licence'), (1, 'Master'), (2, 'Doctorat'), (3, 'Autres') ], verbose_name="Niveau d'études", widget=widgets.RadioSelect()) couple = models.IntegerField(initial=None, choices=[(1, 'Oui'), (0, 'Non')], verbose_name='Etes-vous en couple ?', widget=widgets.RadioSelect()) previous_participation = models.IntegerField( initial=None, choices=[(1, 'Oui'), (0, 'Non')], verbose_name= 'Avez-vous déjà participé à une expérience en laboratoire ?', widget=widgets.RadioSelect()) boring_task = models.IntegerField( initial=None, choices=[(0, 'Très ennuyeuses'), (1, 'Plutot ennuyeuses'), (2, 'Peu ennuyeuses'), (3, 'Pas du tout ennuyeuses')], verbose_name= "Selon vous, les tâches que vous avez accomplies au début de " "l'expérience (le curseur qui devait être placé au milieu d'un trait) " "étaient ?", widget=widgets.RadioSelect()) risk_aversion = models.IntegerField( initial='0', choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], widget=widgets.RadioSelectHorizontal()) confiance = models.IntegerField( initial=None, choices=[(0, 'Je ne sais pas'), (1, 'On n’est jamais trop prudent '), (2, 'La plupart des gens sont dignes de confiance')], verbose_name= "Généralement parlant, direz-vous que la plupart des gens sont dignes de confiance ou que l’on n’est jamais trop prudent avec les gens ?", widget=widgets.RadioSelect()) groupe = models.IntegerField( choices=[(0, 'A'), (1, 'B'), (2, 'C'), (3, 'D'), (4, 'E'), (5, 'F'), (6, 'G')], verbose_name= "Veuillez indiquer dans quelle mesure vous vous sentez envers les autres membres de votre groupe de la partie 2.", )
class Player(BasePlayer): quiz_01 = models.PositiveIntegerField(verbose_name='Your earnings:', min=0, max=999, initial=None, doc='quiz answer') quiz_02 = models.PositiveIntegerField(verbose_name='Your earnings:', min=0, max=999, initial=None, doc='quiz answer') quiz_03 = models.PositiveIntegerField(verbose_name='Your earnings:', min=0, max=999, initial=None, doc='quiz answer') ret_score = models.IntegerField( doc= "player's real effort task score - correct number of RETs mapped to a number." ) vcm_score = models.IntegerField(doc="score player received in vcm round.") vcm_ge_percent = models.IntegerField( doc="player's average group exchange contribution in vcm rounds") role = models.CharField(doc="player role, A or F") def set_payoff(self, A_GE, A_Endow, F_GE, F_Endow): """calc player payoffs""" for p in self.group.get_players(): if p.participant.vars['Role'] == 'F': total_op_individual_exchange = A_Endow - A_GE total_op_group_exchange = A_GE p.round_payoff = (F_Endow - F_GE) - ( 1 / 2 * total_op_individual_exchange) + ( 1 / 2 * F_GE) + Constants.automatic_earnings elif p.participant.vars['Role'] == 'A': total_op_individual_exchange = F_Endow - F_GE total_op_group_exchange = F_GE p.round_payoff = (A_Endow - A_GE) - ( 1 / 2 * total_op_individual_exchange) + ( 1 / 2 * A_GE) + Constants.automatic_earnings round_payoff = models.FloatField(doc="this player's earnings this round") A_stage1 = models.CharField( initial=None, choices=['A1', 'A2'], verbose_name='Make your decision', doc='Player A decision between A1 and A2, Stage 1', widget=widgets.RadioSelect()) F_stage2 = models.CharField( initial=None, choices=['F1', 'F2'], verbose_name='Make your decision', doc='Player F decision between F1 and F2, Stage 2', widget=widgets.RadioSelect()) A_stage3 = models.CharField( initial=None, choices=['A3', 'A4'], verbose_name='Make your decision', doc='Player A decision between A3 and A4, Stage 3', widget=widgets.RadioSelect()) Nature = models.CharField( doc="""'Should nature move, this is nature's move""", widget=widgets.RadioSelect()) terminal_choice = models.CharField( doc="""'the terminal node reached by A and F""", widget=widgets.RadioSelect()) def set_terminal_node(self): """explicitly define terminal node reached by A and F in this group""" A_tn = None F_tn = None N_tn = None #nature for p in self.group.get_players(): if p.participant.vars['Role'] == 'A': if p.A_stage1 == "A1": A_tn = "A1" elif p.A_stage3 == "A3": A_tn = "A3" elif p.A_stage3 == "A4": A_tn = "A4" elif p.participant.vars['Role'] == 'F': if p.F_stage2 == 'F1': F_tn = 'F1' elif p.F_stage2 == 'F2': F_tn = 'F2' if p.Nature == 'N1': N_tn = 'N1' elif p.Nature == 'N2': N_tn = 'N2' TN = None if A_tn == "A1": TN = A_tn elif F_tn == 'F1': TN = F_tn elif A_tn == "A3": TN = A_tn else: TN = N_tn for p in self.group.get_players(): p.terminal_choice = TN
class Player(BasePlayer): # <built-in> subsession = models.ForeignKey(Subsession) group = models.ForeignKey(Group, null=True) # </built-in> # whether bomb is collected or not bomb = models.IntegerField() # location of bomb with row/col info bomb_location = models.TextField() # number of collected boxes boxes_collected = models.IntegerField() # set/scheme of collected boxes boxes_scheme = models.TextField() # --- set round results and player's payoff # ------------------------------------------------------------------------------------------------------------------ round_to_pay = models.IntegerField() round_result = models.CurrencyField() def set_payoff(self): # randomly determine round to pay on player level if self.subsession.round_number == 1: self.session.vars['round_to_pay'] = random.randint( 1, Constants.num_rounds) # determine round_result as (potential) payoff per round if self.bomb == 0: self.round_result = c(self.boxes_collected * Constants.box_value) else: self.round_result = c(0) # set payoffs if <random_payoff = True> to round_result of randomly chosen round if Constants.random_payoff == True: if self.subsession.round_number == self.session.vars[ 'round_to_pay']: self.payoff = self.round_result else: self.payoff = c(0) # set payoffs to round_result if <random_payoff = False> else: self.payoff = self.round_result # --- store values as global variables for session-wide use # ------------------------------------------------------------------------------------------------------------------ def set_globals(self): self.session.vars['bomb'] = [p.bomb for p in self.in_all_rounds()] self.session.vars['bomb_location'] = [ p.bomb_location for p in self.in_all_rounds() ] self.session.vars['boxes_collected'] = [ p.boxes_collected for p in self.in_all_rounds() ] self.session.vars['boxes_scheme'] = [ p.boxes_scheme for p in self.in_all_rounds() ] self.session.vars['round_result'] = [ p.round_result for p in self.in_all_rounds() ] self.session.vars['bret_payoff'] = [ p.payoff for p in self.in_all_rounds() ]
class Player(BasePlayer): # pratice sliders practice_slider_value_one = models.IntegerField(widget=widgets.SliderInput( attrs={ 'step': '1', 'min': '0', 'max': '100' })) practice_slider_value_two = models.IntegerField(widget=widgets.SliderInput( attrs={ 'step': '1', 'min': '0', 'max': '100' })) # input from player player_slider_value_one = models.IntegerField(widget=widgets.SliderInput( attrs={ 'step': '1', 'min': '0', 'max': '100' })) player_slider_value_two = models.IntegerField(widget=widgets.SliderInput( attrs={ 'step': '1', 'min': '0', 'max': '100' })) player_slider_value_three = models.IntegerField(widget=widgets.SliderInput( attrs={ 'step': '1', 'min': '0', 'max': '100' })) player_slider_value_four = models.IntegerField(widget=widgets.SliderInput( attrs={ 'step': '1', 'min': '0', 'max': '100' })) player_slider_value_five = models.IntegerField(widget=widgets.SliderInput( attrs={ 'step': '1', 'min': '0', 'max': '100' })) player_slider_value_six = models.IntegerField(widget=widgets.SliderInput( attrs={ 'step': '1', 'min': '0', 'max': '100' })) player_slider_value_seven = models.IntegerField(widget=widgets.SliderInput( attrs={ 'step': '1', 'min': '0', 'max': '100' })) player_slider_value_eight = models.IntegerField(widget=widgets.SliderInput( attrs={ 'step': '1', 'min': '0', 'max': '100' })) player_slider_value_nine = models.IntegerField(widget=widgets.SliderInput( attrs={ 'step': '1', 'min': '0', 'max': '100' })) player_slider_value_ten = models.IntegerField(widget=widgets.SliderInput( attrs={ 'step': '1', 'min': '0', 'max': '100' })) # practice random value practice_random_slider_value_one = models.IntegerField() practice_random_slider_value_two = models.IntegerField() # correct values random_slider_value_one = models.IntegerField() random_slider_value_two = models.IntegerField() random_slider_value_three = models.IntegerField() random_slider_value_four = models.IntegerField() random_slider_value_five = models.IntegerField() random_slider_value_six = models.IntegerField() random_slider_value_seven = models.IntegerField() random_slider_value_eight = models.IntegerField() random_slider_value_nine = models.IntegerField() random_slider_value_ten = models.IntegerField() correct_sliders = models.IntegerField()
class Player(BasePlayer): player_role = models.CharField(doc="player role, A or F") quiz_01 = models.PositiveIntegerField(verbose_name='Your earnings:', min=0, max=999, initial=None, doc='quiz answer') quiz_02 = models.PositiveIntegerField(verbose_name='Your earnings:', min=0, max=999, initial=None, doc='quiz answer') ret_score = models.IntegerField( doc= "player's real effort task score - correct number of RETs mapped to a number." ) vcm_score = models.FloatField(doc="score player received in vcm round.") vcm_ge_percent = models.FloatField( doc="player's average group exchange contribution in vcm rounds") op_ret_scores = models.CharField( doc='this subjects opposing player ret scores from task 1.') op_ge_overallavg = models.CharField( doc= 'this subjects opposing player overall average group contribution from vcm.' ) round_base_points = models.FloatField( doc= ''' player's base score. if no adjustments are made to own or counterpart GE contributions, player will earn this ''' ) def set_payoff(self, A_GE, A_Endow, F_GE, F_Endow): """calc player payoffs""" ''' called inside group functions, eg A1A2_update ''' op_GE = self.participant.vars['group_exchange_other2p'] op_IE = self.participant.vars['individual_exchange_other2p'] for p in self.group.get_players(): if p.participant.vars['Role'] == 'F': total_op_individual_exchange = (A_Endow - A_GE) + sum(op_IE) total_op_group_exchange = A_GE + sum(op_GE) p.round_payoff = (F_Endow - F_GE) - ( 1 / 2 * total_op_individual_exchange) + ( 1 / 2 * F_GE) + Constants.automatic_earnings #for debugging and results screen p.postStage_self_individual_exchange = F_Endow - F_GE p.postStage_self_ge = F_GE p.postStage_op_individual_exchange = str([(A_Endow - A_GE)] + op_IE) p.postStage_op_group_exchange = str([A_GE] + op_GE) p.postStage_round_points = p.round_payoff elif p.participant.vars['Role'] == 'A': total_op_individual_exchange = (F_Endow - F_GE) + sum(op_IE) total_op_group_exchange = F_GE + sum(op_GE) p.round_payoff = (A_Endow - A_GE) - ( 1 / 2 * total_op_individual_exchange) + ( 1 / 2 * A_GE) + Constants.automatic_earnings #for debugging and results screen p.postStage_self_individual_exchange = A_Endow - A_GE p.postStage_self_ge = A_GE p.postStage_op_individual_exchange = str([(F_Endow - F_GE)] + op_IE) p.postStage_op_group_exchange = str([F_GE] + op_GE) p.postStage_round_points = p.round_payoff round_payoff = models.FloatField(doc="this player's earnings this round") A_stage1 = models.CharField( initial=None, choices=['A1', 'A2'], verbose_name='Make your decision', doc='Player A decision between A1 and A2, Stage 1', widget=widgets.RadioSelect()) F_stage2 = models.CharField( initial=None, choices=['F1', 'F2'], verbose_name='Make your decision', doc='Player F decision between F1 and F2, Stage 2', widget=widgets.RadioSelect()) A_stage3 = models.CharField( initial=None, choices=['A3', 'A4'], verbose_name='Make your decision', doc='Player A decision between A3 and A4, Stage 3', widget=widgets.RadioSelect()) Nature = models.CharField( doc="""'Should nature move, this is nature's move""", widget=widgets.RadioSelect()) terminal_choice = models.CharField( doc="""'the terminal node reached by A and F""", widget=widgets.RadioSelect()) def set_terminal_node(self): """explicitly define terminal node reached by A and F in this group""" A_tn = None F_tn = None N_tn = None #nature for p in self.group.get_players(): p.player_role = p.participant.vars['Role'] if p.participant.vars['Role'] == 'A': if p.A_stage1 == "A1": A_tn = "A1" elif p.A_stage3 == "A3": A_tn = "A3" elif p.A_stage3 == "A4": A_tn = "A4" elif p.participant.vars['Role'] == 'F': if p.F_stage2 == 'F1': F_tn = 'F1' elif p.F_stage2 == 'F2': F_tn = 'F2' if p.Nature == 'N1': N_tn = 'N1' elif p.Nature == 'N2': N_tn = 'N2' TN = None if A_tn == "A1": TN = A_tn elif F_tn == 'F1': TN = F_tn elif A_tn == "A3": TN = A_tn else: TN = N_tn for p in self.group.get_players(): p.terminal_choice = TN postStage_self_individual_exchange = models.FloatField( doc='''"player's individual exchange contribution after stage game"''') postStage_self_ge = models.FloatField( doc='''"player's group exchange contribution after stage game"''') postStage_op_individual_exchange = models.CharField( doc= '''"player's three other countryparty player's individual after stage game"''' ) postStage_op_group_exchange = models.CharField( doc= '''"player's three other countryparty player's group exchange after stage game"''' ) postStage_round_points = models.FloatField( doc='''"player's final score from stage game"''')
class Player(otree.models.BasePlayer): treatment = models.IntegerField( doc= "The player's treatment; identical to subsession.treatment. See public_goods doc for description" ) contribution = models.DecimalField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", max_digits=12, decimal_places=2, ) signal = models.DecimalField( max_digits=12, decimal_places=2, doc="The MPCR observed by the subject for the given round") round_points = models.DecimalField( max_digits=12, decimal_places=2, doc= "This is the total points (tokens) for the subject for a given round. It includes the points from the public good (one forth of the total points present in the public good plus tokens present in the private account). Notice that points/payoff for any given round will be materially paid to subjects at the end of the experiment only if the game that includes that round is randomly selected for payment." ) def set_signal_value(self): mpcr = self.group.efficiency_rate signalVariance = self.session.config['signalVariance'] choicesLeft = [ mpcr - Decimal(x * .1) for x in range(1, signalVariance + 1) ] choicesRight = [ mpcr + Decimal(x * .1) for x in range(1, signalVariance + 1) ] #chop off choices if at the tail if mpcr < Decimal(.06): choices = choicesRight + [mpcr] elif Decimal(.06) < mpcr < Decimal(.16) and signalVariance == 2: choices = choicesRight + [mpcr] + choicesLeft[:1] elif mpcr > Decimal(1.16): choices = choicesLeft + [mpcr] elif Decimal(1.06) < mpcr < Decimal(1.16) and signalVariance == 2: choices = choicesLeft + [mpcr] + choicesRight[:1] else: choices = [mpcr] + choicesLeft + choicesRight signal = random.choice(choices) self.signal = signal.quantize(Decimal('.01')) def get_signal_values(self): if self.session.config['signalVariance'] == 2: signalVariance = Decimal(.2) else: signalVariance = Decimal(.1) left = self.signal - signalVariance right = self.signal + signalVariance signals = dict(left=left.quantize(Decimal('.01')), right=right.quantize(Decimal('.01'))) return signals def set_image(self): playerimage = PlayerImage(participant_id=self.participant.id, image=self.image) playerimage.save() def get_game_info(self): for p in self.in_all_rounds(): if p.subsession.round_number == 1: info = [] info.append(p) return info def get_game_payoffs(self): payoffs = [] for p in self.in_all_rounds(): payoffs.append(p.round_points) def get_round_period(self): x = 1 for r in [1]: if self.subsession.round_number in range( r, r + Constants.rounds_per_game): game_round = self.subsession.round_number - r break else: x += 1 return [game_round + 1, x]
class Player(otree.models.BasePlayer): risk_points = models.DecimalField(max_digits=12, decimal_places=2) GAMBLES = ( ('1', "Gamble 1"), ('2', "Gamble 2"), ('3', "Gamble 3"), ('4', "Gamble 4"), ('5', "Gamble 5"), ) URNS = ( ('0', "Black: ? | White: ?"), ('1', "Black:50% | White:50%"), ) COLORS = ( ('0', "Black"), ('1', "White"), ) risk_flip = models.IntegerField( doc="The flip chosen by the computer. 0:Heads 1: Tails") risk_choice = models.CharField( initial=None, choices=GAMBLES, verbose_name="Choose the gamble you to play", doc= "The coinflip gamble the subject wants to play. Variable takes value 1,...,5 which correspond to Gamble 1, ..., Gamble 5." ) risk_payoff = models.DecimalField(max_digits=12, decimal_places=2) amb_chosen_game = models.CharField( doc="The game randomly choosen by the computer among the ten available." ) amb_chosen_ball = models.CharField( doc="The ball chosen by the computer; 0: Black,1: White") amb_payoff = models.DecimalField(max_digits=12, decimal_places=2) amb_points = models.DecimalField(max_digits=12, decimal_places=2) amb_choice1_urn = models.CharField( initial=None, choices=URNS, ) amb_choice1_color = models.CharField( initial=None, choices=COLORS, widget=widgets.RadioSelectHorizontal(), verbose_name="") amb_choice2_urn = models.CharField( initial=None, choices=URNS, ) amb_choice2_color = models.CharField( initial=None, choices=COLORS, widget=widgets.RadioSelectHorizontal(), verbose_name="") amb_choice3_urn = models.CharField( initial=None, choices=URNS, ) amb_choice3_color = models.CharField( initial=None, choices=COLORS, widget=widgets.RadioSelectHorizontal(), verbose_name="") amb_choice4_urn = models.CharField( initial=None, choices=URNS, ) amb_choice4_color = models.CharField( initial=None, choices=COLORS, widget=widgets.RadioSelectHorizontal(), verbose_name="") amb_choice5_urn = models.CharField( initial=None, choices=URNS, ) amb_choice5_color = models.CharField( initial=None, choices=COLORS, widget=widgets.RadioSelectHorizontal(), verbose_name="") amb_choice6_urn = models.CharField( initial=None, choices=URNS, ) amb_choice6_color = models.CharField( initial=None, choices=COLORS, widget=widgets.RadioSelectHorizontal(), verbose_name="") amb_choice7_urn = models.CharField( initial=None, choices=URNS, ) amb_choice7_color = models.CharField( initial=None, choices=COLORS, widget=widgets.RadioSelectHorizontal(), verbose_name="") amb_choice8_urn = models.CharField( initial=None, choices=URNS, ) amb_choice8_color = models.CharField( initial=None, choices=COLORS, widget=widgets.RadioSelectHorizontal(), verbose_name="") amb_choice9_urn = models.CharField( initial=None, choices=URNS, ) amb_choice9_color = models.CharField( initial=None, choices=COLORS, widget=widgets.RadioSelectHorizontal(), verbose_name="") amb_choice10_urn = models.CharField( initial=None, choices=URNS, ) amb_choice10_color = models.CharField( initial=None, choices=COLORS, widget=widgets.RadioSelectHorizontal(), verbose_name="") def get_chosen_urn(self): urn = getattr(self, "amb_choice{}_urn".format(self.amb_chosen_game)) if urn == "0": u = "Black: ? | White: ?" else: u = "Black: 50% | White: 50%" return u def get_chosen_color(self): color = getattr(self, "amb_choice{}_color".format(self.amb_chosen_game)) if color == "0": c = "Black" else: c = "White" return c def get_drawn_color(self): if self.amb_chosen_ball == "0": color = "Black" else: color = "White" return color def set_amb_payoffs(self): self.amb_chosen_game = random.choice(range(1, 11)) gamble = Constants.URNDICT[str(self.amb_chosen_game)] urn = getattr(self, "amb_choice{}_urn".format(self.amb_chosen_game)) color = getattr(self, "amb_choice{}_color".format(self.amb_chosen_game)) self.amb_chosen_ball = random.choice(Constants.URNS[str(urn)]) if self.amb_chosen_ball == color: self.amb_points = gamble[int(urn)] self.amb_payoff = self.amb_points * self.session.real_world_currency_per_point else: self.amb_points = 0 self.amb_payoff = 0 self.participant.vars['amb_points'] = self.amb_points self.participant.vars['amb_payoff'] = self.amb_payoff def set_risk_payoffs(self): flip = random.choice([0, 1]) self.risk_flip = flip result = Constants.RISKDICT[self.risk_choice] self.risk_points = result[flip] self.risk_payoff = Decimal( result[flip]) * self.session.real_world_currency_per_point self.participant.vars['risk_points'] = self.risk_points self.participant.vars['risk_payoff'] = self.risk_payoff def set_payoffs(self): self.payoff = sum([self.risk_payoff, self.amb_payoff]) def flipcoin(self): result = random.choice([0, 1]) self.risk_flip = result def get_form_fields(self): form_fields = [] for x in range(1, len(Constants.URNDICT) + 1): form_fields.append("amb_choice{}_urn".format(x)) form_fields.append("amb_choice{}_color".format(x)) return form_fields
class Player(BasePlayer): #defining quantity vars CashQuantity = models.IntegerField(initial=0) MasonMoneyQuantity = models.IntegerField(initial=0) BarnesNobleQuantity = models.IntegerField(initial=0) FandangoQuantity = models.IntegerField(initial=0) GapQuantity = models.IntegerField(initial=0) #defining price vars CashPrice = models.DecimalField(..., max_digits=5, decimal_places=1, default=0) MasonMoneyPrice = models.DecimalField(..., max_digits=5, decimal_places=1, default=0) BarnesNoblePrice = models.DecimalField(..., max_digits=5, decimal_places=1, default=0) FandangoPrice = models.DecimalField(..., max_digits=5, decimal_places=1, default=0) GapPrice = models.DecimalField(..., max_digits=5, decimal_places=1, default=0) #defining spending vars CashSpending = models.DecimalField(..., max_digits=5, decimal_places=1, default=0) MasonMoneySpending = models.DecimalField(..., max_digits=5, decimal_places=1, default=0) BarnesNobleSpending = models.DecimalField(..., max_digits=5, decimal_places=1, default=0) FandangoSpending = models.DecimalField(..., max_digits=5, decimal_places=1, default=0) GapSpending = models.DecimalField(..., max_digits=5, decimal_places=1, default=0) Expenditure = models.DecimalField(..., max_digits=5, decimal_places=1, default=0) def compute_spendings(self): self.CashSpending = self.CashPrice * decimal.Decimal(self.CashQuantity) self.MasonMoneySpending = self.MasonMoneyPrice * decimal.Decimal( self.MasonMoneyQuantity) self.BarnesNobleSpending = self.BarnesNoblePrice * decimal.Decimal( self.BarnesNobleQuantity) self.FandangoSpending = self.FandangoPrice * decimal.Decimal( self.FandangoQuantity) self.GapSpending = self.GapPrice * decimal.Decimal(self.GapQuantity) self.Expenditure = self.CashSpending + self.MasonMoneySpending + self.BarnesNobleSpending + self.FandangoSpending + self.GapSpending def set_prices(self): self.CashPrice = random.randint(5, 30) / 2 self.MasonMoneyPrice = 17.5 - self.CashPrice self.FandangoPrice = random.randrange(5, 14) / 2 self.BarnesNoblePrice = random.randrange(5, 20) / 2 self.GapPrice = 12.5 - self.BarnesNoblePrice #questionnaires Q1 = models.CharField(choices=['Yes', 'No'], widget=widgets.RadioSelect()) Q2 = models.CharField(choices=['Yes', 'No'], widget=widgets.RadioSelect()) Q3 = models.CharField(choices=['Yes', 'No'], widget=widgets.RadioSelect()) Q4 = models.CharField(choices=['Yes', 'No'], widget=widgets.RadioSelect()) Q5 = models.CharField(choices=['Yes', 'No'], widget=widgets.RadioSelect()) Gender = models.CharField(choices=[('M', 'Male'), ('F', 'Female')], default='M') Age = models.IntegerField(min=18, max=99) ShareFood = models.CurrencyField(min=0, max=100) ShareBooks = models.CurrencyField(min=0, max=100) ShareCloths = models.CurrencyField(min=0, max=100) ShareMovies = models.CurrencyField(min=0, max=100) AllArrived = models.IntegerField(initial=0) def all_arrive(self): AllArrived = 1
class Player(BasePlayer): # variables that change for each player task_reward = models.DecimalField(max_digits=5, decimal_places=2) intermediate_reward = models.DecimalField(max_digits=5, decimal_places=2) final_reward = models.DecimalField(max_digits=5, decimal_places=2) total_pay = models.DecimalField(max_digits=5, decimal_places=2) p_role = models.TextField() survey_response0 = models.IntegerField() survey_response1 = models.IntegerField() survey_response2 = models.IntegerField() survey_response3 = models.IntegerField() survey_response4 = models.IntegerField() survey_response5 = models.IntegerField() survey_responseA = models.IntegerField() survey_responseB = models.IntegerField() survey_responseC = models.IntegerField() survey_responseD = models.IntegerField() survey_responseE = models.IntegerField() survey_responseF = models.IntegerField() def get_partner(self): return self.get_others_in_group()[0]
class Group(BaseGroup): # Data pour phase 1 nb_mcf_fmm = models.IntegerField(min=0, max=10) nb_mcf_ft = models.IntegerField(min=0, max=10) nb_mcf_fges = models.IntegerField(min=0, max=10) nb_mcf_flsh = models.IntegerField(min=0, max=10) nb_mcf_fd = models.IntegerField(min=0, max=10) nb_mcf_espol = models.IntegerField(min=0, max=10) nb_mcf_santesocial = models.IntegerField(min=0, max=10) nb_mcf_commonhome = models.IntegerField(min=0, max=10) nb_mcf_anthropolab = models.IntegerField(min=0, max=10) # Data agrégées nb_mcf_total = models.IntegerField(min=0) # Data pour phase 2 salaire_moyen_fmm = models.IntegerField(min=0) salaire_moyen_ft = models.IntegerField(min=0) salaire_moyen_fges = models.IntegerField(min=0) salaire_moyen_flsh = models.IntegerField(min=0) salaire_moyen_fd = models.IntegerField(min=0) salaire_moyen_espol = models.IntegerField(min=0) salaire_moyen_santesocial = models.IntegerField(min=0) salaire_moyen_commonhome = models.IntegerField(min=0) salaire_moyen_anthropolab = models.IntegerField(min=0) nb_mcf_avec_salaire_moyen_fmm = models.IntegerField(min=0) nb_mcf_avec_salaire_moyen_ft = models.IntegerField(min=0) nb_mcf_avec_salaire_moyen_fges = models.IntegerField(min=0) nb_mcf_avec_salaire_moyen_flsh = models.IntegerField(min=0) nb_mcf_avec_salaire_moyen_fd = models.IntegerField(min=0) nb_mcf_avec_salaire_moyen_espol = models.IntegerField(min=0) nb_mcf_avec_salaire_moyen_santesocial = models.IntegerField(min=0) nb_mcf_avec_salaire_moyen_commonhome = models.IntegerField(min=0) nb_mcf_avec_salaire_moyen_anthropolab = models.IntegerField(min=0) # Data agrégées salaire_moyen_icl = models.IntegerField(min=0) nb_mcf_avec_salaire_moyen_icl = models.IntegerField(min=0) # Data pour phase 3 hff_fmm = models.IntegerField(min=0, max=240) hff_ft = models.IntegerField(min=0, max=240) hff_fges = models.IntegerField(min=0, max=240) hff_flsh = models.IntegerField(min=0, max=240) hff_fd = models.IntegerField(min=0, max=240) hff_espol = models.IntegerField(min=0, max=240) hff_santesocial = models.IntegerField(min=0, max=240) hff_commonhome = models.IntegerField(min=0, max=240) hff_anthropolab = models.IntegerField(min=0, max=240) cout_vacation_avec_hff_fmm = models.IntegerField(min=0, max=180000) cout_vacation_avec_hff_ft = models.IntegerField(min=0, max=180000) cout_vacation_avec_hff_fges = models.IntegerField(min=0, max=180000) cout_vacation_avec_hff_flsh = models.IntegerField(min=0, max=180000) cout_vacation_avec_hff_fd = models.IntegerField(min=0, max=180000) cout_vacation_avec_hff_espol = models.IntegerField(min=0, max=180000) cout_vacation_avec_hff_santesocial = models.IntegerField(min=0, max=180000) cout_vacation_avec_hff_commonhome = models.IntegerField(min=0, max=180000) cout_vacation_avec_hff_anthropolab = models.IntegerField(min=0, max=180000) # Data agrégées hff_moyen_icl = models.IntegerField(min=0, max=240) cout_vacation_avec_hff_moyen_icl = models.IntegerField(min=0, max=180000) # Data recettes recettes_icl = models.TextField() commentaires_icl = models.TextField() def compute_group_grandes_masses_results1(self): self.nb_mcf_total = 0 for p in self.get_players(): p.nb_mcffinal = p.nb_mcf1 self.nb_mcf_total += p.nb_mcf1 if p.my_entity == 'FMM-SanteSocial': self.nb_mcf_fmm = p.nb_mcf1 elif p.my_entity == 'FT': self.nb_mcf_ft = p.nb_mcf1 elif p.my_entity == 'FGES': self.nb_mcf_fges = p.nb_mcf1 elif p.my_entity == 'FLSH': self.nb_mcf_flsh = p.nb_mcf1 elif p.my_entity == 'FD': self.nb_mcf_fd = p.nb_mcf1 elif p.my_entity == 'Espol': self.nb_mcf_espol = p.nb_mcf1 elif p.my_entity == 'Sante-Social': self.nb_mcf_santesocial = p.nb_mcf1 elif p.my_entity == 'Common-Home': self.nb_mcf_commonhome = p.nb_mcf1 elif p.my_entity == 'Anthropo-Lab': self.nb_mcf_anthropolab = p.nb_mcf1 def compute_group_grandes_masses_results2(self): self.nb_mcf_total = 0 for p in self.get_players(): p.nb_mcffinal = p.nb_mcf2 self.nb_mcf_total += p.nb_mcf2 if p.my_entity == 'FMM-SanteSocial': self.nb_mcf_fmm = p.nb_mcf2 elif p.my_entity == 'FT': self.nb_mcf_ft = p.nb_mcf2 elif p.my_entity == 'FGES': self.nb_mcf_fges = p.nb_mcf2 elif p.my_entity == 'FLSH': self.nb_mcf_flsh = p.nb_mcf2 elif p.my_entity == 'FD': self.nb_mcf_fd = p.nb_mcf2 elif p.my_entity == 'Espol': self.nb_mcf_espol = p.nb_mcf2 elif p.my_entity == 'Sante-Social': self.nb_mcf_santesocial = p.nb_mcf2 elif p.my_entity == 'Common-Home': self.nb_mcf_commonhome = p.nb_mcf2 elif p.my_entity == 'Anthropo-Lab': self.nb_mcf_anthropolab = p.nb_mcf2 def compute_group_grandes_masses_results3(self): self.nb_mcf_total = 0 for p in self.get_players(): p.nb_mcffinal = p.nb_mcf3 self.nb_mcf_total += p.nb_mcf3 if p.my_entity == 'FMM-SanteSocial': self.nb_mcf_fmm = p.nb_mcf3 elif p.my_entity == 'FT': self.nb_mcf_ft = p.nb_mcf3 elif p.my_entity == 'FGES': self.nb_mcf_fges = p.nb_mcf3 elif p.my_entity == 'FLSH': self.nb_mcf_flsh = p.nb_mcf3 elif p.my_entity == 'FD': self.nb_mcf_fd = p.nb_mcf3 elif p.my_entity == 'Espol': self.nb_mcf_espol = p.nb_mcf3 elif p.my_entity == 'Sante-Social': self.nb_mcf_santesocial = p.nb_mcf3 elif p.my_entity == 'Common-Home': self.nb_mcf_commonhome = p.nb_mcf3 elif p.my_entity == 'Anthropo-Lab': self.nb_mcf_anthropolab = p.nb_mcf3 def compute_group_masse_salariale_results(self): # Compute le salaire moyen self.salaire_moyen_icl = 0 self.nb_mcf_avec_salaire_moyen_icl = 0 for p in self.get_players(): self.salaire_moyen_icl += p.salaire_moyen self.nb_mcf_avec_salaire_moyen_icl += p.nb_mcf_avec_salaire_moyen if p.my_entity == 'FMM-SanteSocial': self.salaire_moyen_fmm = p.salaire_moyen self.nb_mcf_avec_salaire_moyen_fmm = p.nb_mcf_avec_salaire_moyen elif p.my_entity == 'FT': self.salaire_moyen_ft = p.salaire_moyen self.nb_mcf_avec_salaire_moyen_ft = p.nb_mcf_avec_salaire_moyen elif p.my_entity == 'FGES': self.salaire_moyen_fges = p.salaire_moyen self.nb_mcf_avec_salaire_moyen_fges = p.nb_mcf_avec_salaire_moyen elif p.my_entity == 'FLSH': self.salaire_moyen_flsh = p.salaire_moyen self.nb_mcf_avec_salaire_moyen_flsh = p.nb_mcf_avec_salaire_moyen elif p.my_entity == 'FD': self.salaire_moyen_fd = p.salaire_moyen self.nb_mcf_avec_salaire_moyen_fd = p.nb_mcf_avec_salaire_moyen elif p.my_entity == 'Espol': self.salaire_moyen_espol = p.salaire_moyen self.nb_mcf_avec_salaire_moyen_espol = p.nb_mcf_avec_salaire_moyen elif p.my_entity == 'Sante-Social': self.salaire_moyen_santesocial = p.salaire_moyen self.nb_mcf_avec_salaire_moyen_santesocial = p.nb_mcf_avec_salaire_moyen elif p.my_entity == 'Common-Home': self.salaire_moyen_commonhome = p.salaire_moyen self.nb_mcf_avec_salaire_moyen_commonhome = p.nb_mcf_avec_salaire_moyen elif p.my_entity == 'Anthropo-Lab': self.salaire_moyen_anthropolab = p.salaire_moyen self.nb_mcf_avec_salaire_moyen_anthropolab = p.nb_mcf_avec_salaire_moyen # Terminer les moyennes self.salaire_moyen_icl /= len(self.get_players()) self.nb_mcf_avec_salaire_moyen_icl /= len(self.get_players()) def compute_group_croissance_intext_results(self): # Compute la décharge moyenne self.hff_moyen_icl = 0 self.cout_vacation_avec_hff_moyen_icl = 0 for p in self.get_players(): self.hff_moyen_icl += p.hff self.cout_vacation_avec_hff_moyen_icl += p.cout_vacation_avec_hff if p.my_entity == 'FMM-SanteSocial': self.hff_fmm = p.hff self.cout_vacation_avec_hff_fmm = p.cout_vacation_avec_hff elif p.my_entity == 'FT': self.hff_ft = p.hff self.cout_vacation_avec_hff_ft = p.cout_vacation_avec_hff elif p.my_entity == 'FGES': self.hff_fges = p.hff self.cout_vacation_avec_hff_fges = p.cout_vacation_avec_hff elif p.my_entity == 'FLSH': self.hff_flsh = p.hff self.cout_vacation_avec_hff_flsh = p.cout_vacation_avec_hff elif p.my_entity == 'FD': self.hff_fd = p.hff self.cout_vacation_avec_hff_fd = p.cout_vacation_avec_hff elif p.my_entity == 'Espol': self.hff_espol = p.hff self.cout_vacation_avec_hff_espol = p.cout_vacation_avec_hff elif p.my_entity == 'Sante-Social': self.hff_santesocial = p.hff self.cout_vacation_avec_hff_santesocial = p.cout_vacation_avec_hff elif p.my_entity == 'Common-Home': self.hff_commonhome = p.hff self.cout_vacation_avec_hff_commonhome = p.cout_vacation_avec_hff elif p.my_entity == 'Anthropo-Lab': self.hff_anthropolab = p.hff self.cout_vacation_avec_hff_anthropolab = p.cout_vacation_avec_hff # Terminer les moyennes self.hff_moyen_icl /= len(self.get_players()) self.cout_vacation_avec_hff_moyen_icl /= len(self.get_players()) def compute_group_recettes_results(self): self.recettes_icl = '' self.commentaires_icl = '' for p in self.get_players(): self.recettes_icl += "\n**********************\n" + p.my_entity + "\n**********************\n" + p.recettes + "\n" self.commentaires_icl += "\n**********************\n" + p.my_entity + "\n**********************\n" + p.commentaires + "\n"
class Player(BasePlayer): keep = models.CurrencyField() real_effort_dictator_endowment = models.IntegerField(initial=0)
class Player(BasePlayer): player_role = models.CharField(doc="player role, A or F") quiz_01_a = models.FloatField( verbose_name="In A1, Role F's Group Exchange Contribution", min=0, max=999, initial=None, doc='''quiz_01_a answer In A1, Role F's Group Exchange Contribution''') quiz_01_b = models.FloatField( verbose_name="In A1, Role A's Group Exchange Contribution", min=0, max=999, initial=None, doc='''quiz_01_b answer In A1, Role A's Group Exchange Contribution''') quiz_01_c = models.FloatField( verbose_name="In A1, Role A's Score", min=0, max=999, initial=None, doc='''quiz_01_c answer In A1, Role A's Score''') quiz_01_d = models.FloatField( verbose_name="In A1, Role F's Score", min=0, max=999, initial=None, doc='''quiz_01_d answer In A1, Role F's Score''') quiz_01_e = models.FloatField( verbose_name="In F1, Role A's Score", min=0, max=999, initial=None, doc='''quiz_01_c answer In F1, Role A's Score''') quiz_01_f = models.FloatField( verbose_name="In F1, Role F's Score", min=0, max=999, initial=None, doc='''quiz_01_d answer In F1, Role F's Score''') quiz_02_a = models.FloatField( verbose_name="In N1, Role A's Score", min=0, max=999, initial=None, doc='''quiz_02_a answer In N1, Role A's Score''') quiz_02_b = models.FloatField( verbose_name="In N1, Role F's Score", min=0, max=999, initial=None, doc='''quiz_02_b answer In N1, Role F's Score''') quiz_02_c = models.FloatField( verbose_name="In N2, Role A's Score", min=0, max=999, initial=None, doc='''quiz_02_c answer In N2, Role A's Score''') quiz_02_d = models.FloatField( verbose_name="In N2, Role F's Score", min=0, max=999, initial=None, doc='''quiz_02_d answer In N2, Role F's Score''') quiz_02_e = models.FloatField( verbose_name="The Probability of N1 Occurring", min=0, max=999, initial=None, doc='''quiz_02_e answer The Probability of N1 Occurring''') ret_score = models.IntegerField( doc= "player's real effort task score - correct number of RETs mapped to a number." ) vcm_score = models.FloatField(doc="score player received in vcm round.") vcm_ge_percent = models.FloatField( doc="player's average group exchange contribution in vcm rounds") passive_Player_Earnings = models.FloatField( doc=''' The score of this round's passive player. ''') def set_round_payoff(self): """calc player payoffs""" ''' called inside group functions, eg A1A2_update ''' for p in self.group.get_players(): # group exchange F_GE = (p.GE_Low_F) if ((p.terminal_choice == 'F1') | (p.terminal_choice == 'N1')): F_GE = (p.GE_Low_F * p.F1_F_mult) GE = p.GE_Low_A + F_GE + 40 #scores A_score = (GE * p.mpcr) + (20 - p.GE_Low_A) F_score = (GE * p.mpcr) + (20 - F_GE) if ((p.terminal_choice == 'N2') | (p.terminal_choice == 'N1')): A_score = (GE * p.mpcr) + (20 - p.GE_Low_A) - p.boycott_cost if (p.participant.vars['Role'] == 'A'): p.postStage_self_individual_exchange = 20 - p.GE_Low_A p.postStage_self_ge = p.GE_Low_A p.postStage_op_individual_exchange = str(20 - F_GE) p.postStage_op_group_exchange = str(F_GE) p.round_payoff = A_score p.postStage_round_points = A_score elif (p.participant.vars['Role'] == 'F'): p.postStage_self_individual_exchange = F_GE p.postStage_self_ge = p.GE_Low_F p.postStage_op_individual_exchange = str(20 - p.GE_Low_A) p.postStage_op_group_exchange = str(p.GE_Low_A) p.postStage_round_points = F_score p.round_payoff = F_score def set_payoff(self, round): # in views, determine round to pay # similar to VCM pass def passivePlayerEarnings(self): for p in self.group.get_players(): # group exchange F_GE = (p.GE_Low_F) if ((p.terminal_choice == 'F1') | (p.terminal_choice == 'N1')): F_GE = (p.GE_Low_F * p.F1_F_mult) GE = p.GE_Low_A + F_GE + 40 self.passive_Player_Earnings = (GE * p.mpcr) #scores return (GE * p.mpcr) stage_round_count = models.PositiveIntegerField( doc='The stage round number.') paid_round = models.PositiveIntegerField(doc=''' Paid stage round ''') paid_active_round_score = models.FloatField( doc=''' Score from paid actie player round''') round_payoff = models.FloatField(doc="this player's earnings this round") GE_Low_A = models.FloatField( doc="player A's group exchange contribution at 1X") GE_Low_F = models.FloatField( doc="player F's group exchange contribution at 1X") mpcr = models.FloatField( doc="marginal per-capita rate of return to vcm game") boycott_cost = models.FloatField(doc="cost of boycoff to player A") passive_ge_contrib = models.FloatField( doc="passive players' total contribution to group exchange") A1_A_mult = models.FloatField(doc="multiplier on GE of A at node A1") A1_F_mult = models.FloatField(doc="multiplier on GE of F at node A1") F1_A_mult = models.FloatField(doc="multiplier on GE of A at node F1") F1_F_mult = models.FloatField(doc="multiplier on GE of F at node F1") A3_A_mult = models.FloatField(doc="multiplier on GE of A at node A3") A3_F_mult = models.FloatField(doc="multiplier on GE of F at node A3") N1_prob = models.FloatField( doc="Probability of N1, where prob of N2 is (1 - N1_prob)") A_stage1 = models.CharField( initial=None, choices=['A1', 'A2'], verbose_name='Make your decision', doc='Player A decision between A1 and A2, Stage 1', widget=widgets.RadioSelect()) F_stage2 = models.CharField( initial=None, choices=['F1', 'F2'], verbose_name='Make your decision', doc='Player F decision between F1 and F2, Stage 2', widget=widgets.RadioSelect()) A_stage3 = models.CharField( initial=None, choices=['A3', 'A4'], verbose_name='Make your decision', doc='Player A decision between A3 and A4, Stage 3', widget=widgets.RadioSelect()) Nature = models.CharField( doc="""'Should nature move, this is nature's move""", widget=widgets.RadioSelect()) terminal_choice = models.CharField( doc="""'the terminal node reached by A and F""", widget=widgets.RadioSelect()) def set_terminal_node(self): """explicitly define terminal node reached by A and F in this group""" A_tn = None F_tn = None N_tn = None #nature for p in self.group.get_players(): p.player_role = p.participant.vars['Role'] if p.participant.vars['Role'] == 'A': if p.A_stage1 == "A1": A_tn = "A1" elif p.A_stage3 == "A3": A_tn = "A3" elif p.A_stage3 == "A4": A_tn = "A4" elif p.participant.vars['Role'] == 'F': if p.F_stage2 == 'F1': F_tn = 'F1' elif p.F_stage2 == 'F2': F_tn = 'F2' if p.Nature == 'N1': N_tn = 'N1' elif p.Nature == 'N2': N_tn = 'N2' TN = None if A_tn == "A1": TN = A_tn elif F_tn == 'F1': TN = F_tn elif A_tn == "A3": TN = A_tn else: TN = N_tn for p in self.group.get_players(): p.terminal_choice = TN postStage_self_individual_exchange = models.FloatField( doc='''"player's individual exchange contribution after stage game"''') postStage_self_ge = models.FloatField( doc='''"player's group exchange contribution after stage game"''') postStage_op_individual_exchange = models.CharField( doc= '''"player's three other countryparty player's individual after stage game"''' ) postStage_op_group_exchange = models.CharField( doc= '''"player's three other countryparty player's group exchange after stage game"''' ) postStage_round_points = models.FloatField( doc='''"player's final score from stage game"''') followup_1 = models.CharField() # Survey questions q_birthMonth = models.PositiveIntegerField( verbose_name="What is the month of your birth?", choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], doc=''' birth month ''', ) q_birthYear = models.PositiveIntegerField( verbose_name="What is the year of your birth?", min=1900, max=2016, doc=''' birth year ''', ) q_sex = models.CharField( verbose_name="Are you male or female?", choices=["male", "female"], doc=''' male or female ''', ) q_languages = models.CharField( verbose_name="What language do you speak most often at home?", doc='''languages''', ) q_YearsInUAE = models.PositiveIntegerField( verbose_name="How long have you lived in the UAE (in years)?", doc=''' How long have you lived in the UAE (in years)? ''', ) q_nationality = models.CharField( verbose_name="What is your nationality?", doc=''' What is your nationality? ''', ) q_major = models.CharField( verbose_name="What is your major?", doc=''' What is your major? ''', ) q_part2strat = models.CharField( verbose_name= "In Part 2, how did you decide how much to contribute to the group exchange?", doc= ''' In Part 2, how did you decide how much to contribute to the group exchange? ''', widget=widgets.Textarea) q_part3_A1strat = models.CharField( blank=None, verbose_name= "In Part 3, if you were a Role A player, how did you decide between A1 and A2?", doc= ''' In Part 3, if you were a Role A player, how did you decide between A1 and A2? ''', widget=widgets.Textarea) q_part3_F1strat = models.CharField( blank=None, verbose_name= "In Part 3, if you were a Role F player, how did you decide between F1 and F2?", doc= ''' In Part 3, if you were a Role F player, how did you decide between F1 and F2? ''', widget=widgets.Textarea) q_part3_A3strat = models.CharField( blank=None, verbose_name= "In Part 3, if you were a Role A player, how did you decide between A3 and A4?", doc= ''' In Part 3, if you were a Role A player, how did you decide between A3 and A4? ''', widget=widgets.Textarea) q_part3_dynamic = models.CharField( blank=None, verbose_name= "In Part 3, how did your strategy change over the many rounds you played?", doc=''' In Part 3, how did your strategy change over rounds? ''', widget=widgets.Textarea)