from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import csv import numpy doc = """ Results (I-order): Results and Payments for the one-shot and the infinitely-repeated PDs """ class Constants(BaseConstants): name_in_url = 'code:results_Iorder' players_per_group = 2 players_per_supergroup = 4 assert players_per_supergroup % players_per_group == 0, \ SUPERGROUP_NUM_ERR num_rounds = 1 supergroup_threshold1 = 4 # To test: randomly_selected_round = 1 # randomly_selected_round = random.randint(1, 10) randomly_selected_match = random.randint(1, 15) # randomly_selected_match = 15 # rounds_with_guess = [1, 5, 10] # matches_with_guess = [1, 5, 10] # right_guess_payoff = "2 Euro" # n_supergames_task1 = 5 # n_selected_match_task2 = randomly_selected_round - n_supergames_task1 #randomly_selected_round = random.randint(1, 5) # payoff if 1 player defects and the other cooperates""", print(randomly_selected_match) class Subsession(BaseSubsession): task1_order = models.IntegerField() task2_order = models.IntegerField() conversion_rate_eur = models.FloatField() def creating_session(self): self.task1_order = self.session.config['task1_order'] self.task2_order = self.session.config['task2_order'] self.conversion_rate_eur = self.session.config['conversion_rate_eur'] for p in self.get_players(): p.num_supergames = self.session.config['num_supergames'] p.continuation_prob = self.session.config['continuation_prob'] p.delta_limit = self.session.config['delta_limit'] p.conversion_rate = self.session.config['points100_value_eur'] # Payoff from mutual cooperation (Reward Payoff) p.payoff_R = self.session.config['payoff_R'] # Payoff from mutual cooperation (Punishment Payoff) p.payoff_P = self.session.config['payoff_P'] # Payoff from unilateral cooperation (Sucker Payoff) p.payoff_S = self.session.config['payoff_S'] # Payoff from unilateral defection (Temptation Payoff) p.payoff_T = self.session.config['payoff_T'] p.delta_limit = self.session.config['delta_limit'] p.conversion_rate_eur = self.session.config['conversion_rate_eur'] for g in self.get_groups(): for p in g.get_players(): p.randomly_selected_match = Constants.randomly_selected_match class Group(BaseGroup): pass # def random_round(self): # for p in self.get_players(): # p.random_round() class Player(BasePlayer): num_supergames = models.IntegerField() continuation_prob = models.CharField() delta_limit = models.IntegerField() conversion_rate = models.StringField() payoff_R = models.IntegerField() payoff_P = models.IntegerField() payoff_S = models.IntegerField() payoff_T = models.IntegerField() conversion_rate_eur = models.FloatField() task1_supergroup = models.LongStringField() task2_supergroup = models.LongStringField() id_random = models.IntegerField() cq1_n1 = models.IntegerField() cq1_n2 = models.IntegerField() cq1_n3 = models.IntegerField() cq1_n4 = models.IntegerField() cq1_n5 = models.IntegerField() cq2_n1 = models.IntegerField() cq2_n2 = models.IntegerField() cq2_n3 = models.IntegerField() cq2_n4 = models.IntegerField() cq2_n5 = models.IntegerField() cq2_n6 = models.IntegerField() cq2_n7 = models.IntegerField() task1_payoff_int = models.IntegerField() task1_payoff_eur = models.FloatField() task1_payoff_eur_to_show = models.FloatField() task1_relevant_choice = models.IntegerField() task1_relevant_choice_type = models.StringField task1_decisive_choice = models.IntegerField() task1_decisive_choice_type = models.StringField task1_decisive_choice_type_partner = models.StringField task1_payoff_final = models.FloatField() task1_payoff_final_to_show = models.FloatField() task2_payoff_cum_int_m1 = models.IntegerField() task2_payoff_cum_int_m2 = models.IntegerField() task2_payoff_cum_int_m3 = models.IntegerField() task2_payoff_cum_int_m4 = models.IntegerField() task2_payoff_cum_int_m5 = models.IntegerField() task2_payoff_cum_int_m6 = models.IntegerField() task2_payoff_cum_int_m7 = models.IntegerField() task2_payoff_cum_int_m8 = models.IntegerField() task2_payoff_cum_int_m9 = models.IntegerField() task2_payoff_cum_int_m10 = models.IntegerField() task2_payoff_cum_int_m11 = models.IntegerField() task2_payoff_cum_int_m12 = models.IntegerField() task2_payoff_cum_int_m13 = models.IntegerField() task2_payoff_cum_int_m14 = models.IntegerField() task2_payoff_cum_int_m15 = models.IntegerField() task2_m1_length = models.IntegerField() task2_m2_length = models.IntegerField() task2_m3_length = models.IntegerField() task2_m4_length = models.IntegerField() task2_m5_length = models.IntegerField() task2_m6_length = models.IntegerField() task2_m7_length = models.IntegerField() task2_m8_length = models.IntegerField() task2_m9_length = models.IntegerField() task2_m10_length = models.IntegerField() task2_m11_length = models.IntegerField() task2_m12_length = models.IntegerField() task2_m13_length = models.IntegerField() task2_m14_length = models.IntegerField() task2_m15_length = models.IntegerField() randomly_selected_match = models.IntegerField() task2_payoff_int = models.IntegerField() task2_payoff_eur = models.FloatField() task2_payoff_eur_to_show = models.FloatField() task2_payoff_final = models.FloatField() task2_payoff_final_to_show = models.FloatField()