from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from django import forms from django.core.validators import MinValueValidator, MaxValueValidator import numpy as np import random import itertools ## COPY BACK TO LINE 63: , 'Bonus', 'CharityLow', 'CharityHigh' author = 'Patrick Rooney' doc = """ Other-Focused Turnarounds Game """ class Constants(BaseConstants): name_in_url = 'oft' players_per_group = 4 unity = 1 num_rounds = 3 #subsession1_endround = 10 #subsession2_startround = 11 #subsession2_endround = 20 #subsession3_startround = 21 #subsession3_endround = 30 pay_combos = {'00', '01', '02', '03', '04', '10', '11', '12', '13', '14', '20', '21', '22', '23', '24', '30', '31', '32', '33', '34', '40', '41', '42', '43', '44' } solution1 = 'Earnings are public.' solution2 = 'Old products have been replaced.' solution3 = 'The CEO is on vacation.' solution4 = 'Inventory is full.' payoff_list = np.array([(200, 200, 200, 200, 200), (150, 210, 210, 210, 210), (100, 160, 220, 220, 220), (50, 110, 170, 230, 230), (0, 60, 120, 180, 240)]) class Subsession(BaseSubsession): def creating_session(self): print('in creating session') if self.round_number == 1: paying_round1 = random.randint(1, Constants.num_rounds/3) self.session.vars['paying_round1'] = paying_round1 paying_round2 = random.randint(Constants.num_rounds/3+1, Constants.num_rounds*2/3) self.session.vars['paying_round2'] = paying_round2 paying_round3 = random.randint(Constants.num_rounds*2/3+1, Constants.num_rounds) self.session.vars['paying_round3'] = paying_round3 print('The first part paid round is', paying_round1) print('The second part paid round is', paying_round2) print('The third part paid round is', paying_round3) if self.round_number == 1: for group in self.get_groups(): group.condition = random.choice(['Control']) print('set player.condition to', group.condition) else: self.group_like_round(1) class Group(BaseGroup): condition = models.StringField() min = models.IntegerField() first = models.IntegerField() second = models.IntegerField() third = models.IntegerField() fourth = models.IntegerField() def set_payoffs(self): players = self.get_players() sentences = [p.total_sentences for p in players] sent_random = np.random.choice(sentences, 4, replace=False) self.min = min(sentences) self.first = sent_random[0] self.second = sent_random[1] self.third = sent_random[2] self.fourth = sent_random[3] for p in players: p.payoff = Constants.payoff_list.item((p.total_sentences, self.min)) p.first_p = Constants.payoff_list.item((self.first, self.min)) p.second_p = Constants.payoff_list.item((self.second, self.min)) p.third_p = Constants.payoff_list.item((self.third, self.min)) p.fourth_p = Constants.payoff_list.item((self.fourth, self.min)) class Player(BasePlayer): round_id = models.StringField() paying_round1 = models.IntegerField() paying_round2 = models.IntegerField() paying_round3 = models.IntegerField() total_payoff = models.IntegerField() total_earnings = models.DecimalField() practice_response1 = models.IntegerField(label='', choices=[1], widget=widgets.TextInput) practice_response2 = models.IntegerField(label='', choices=[210], widget=widgets.TextInput) practice_response3 = models.IntegerField(label='', choices=[0], widget=widgets.TextInput) practice_response4 = models.IntegerField(label='', choices=[100], widget=widgets.TextInput) practice_response5 = models.IntegerField(label='', choices=[0], widget=widgets.TextInput) practice_response6 = models.IntegerField(label='', choices=[200], widget=widgets.TextInput) true_false1 = models.StringField(label='', choices=['True'], widget=widgets.TextInput) true_false2 = models.StringField(label='', choices=['True'], widget=widgets.TextInput) submitted_answer1 = models.StringField(label='Earnings are public.', widget=widgets.TextInput, blank=True) submitted_answer2 = models.StringField(label='Old products have been replaced.', widget=widgets.TextInput, blank=True) submitted_answer3 = models.StringField(label='The CEO is on vacation.', widget=widgets.TextInput, blank=True) submitted_answer4 = models.StringField(label='Inventory is full.', widget=widgets.TextInput, blank=True) is_correct1 = models.BooleanField() is_correct2 = models.BooleanField() is_correct3 = models.BooleanField() is_correct4 = models.BooleanField() total_sentences = models.IntegerField() min_p = models.IntegerField() first_p = models.IntegerField() second_p = models.IntegerField() third_p = models.IntegerField() fourth_p = models.IntegerField() reflection = models.StringField(label='', widget=widgets.Textarea, blank=True) age = models.IntegerField(label='', min=0, max=100) gender = models.StringField( label='', widget=widgets.RadioSelect, choices=['Male', 'Female', 'Non-Binary', 'Prefer not to Disclose'] ) race = models.StringField( label='', widget=widgets.RadioSelect, choices=['White', 'Black', 'East Asian', 'South Asian', 'Middle Eastern', 'Hispanic', 'Multi-racial', 'Other'] ) major = models.StringField( label='', widget=widgets.RadioSelect, choices=['Economics', 'Other Social Science', 'Chemical/Physical/Biological Sciences', 'Engineering/Computer Science', 'Humanities', 'Other'] ) religion = models.StringField( label='', widget=widgets.RadioSelect, choices=['Frequently // Once a week', 'Often // Once a month', 'Sometimes // Once every few months', 'Seldom // Once or twice a year', 'Never'] ) volunteer = models.StringField(label='', widget=widgets.RadioSelect, choices=['Yes', 'No']) donate = models.StringField(label='', widget=widgets.RadioSelect, choices=['Yes', 'No']) confirm_payment = models.StringField( label='', choices=['I have confirmed that I have been given correct payment'], widget=widgets.RadioSelect ) def check_correct(self): self.is_correct1 = (self.submitted_answer1 == Constants.solution1) self.is_correct2 = (self.submitted_answer2 == Constants.solution2) self.is_correct3 = (self.submitted_answer3 == Constants.solution3) self.is_correct4 = (self.submitted_answer4 == Constants.solution4) def sum_sentences(self): self.total_sentences = self.is_correct1 + self.is_correct2 + self.is_correct3 + self.is_correct4