from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random from django.utils import timezone from django.db.models import DateTimeField class Constants(BaseConstants): name_in_url = 'ultimatum_game' players_per_group = 2 num_rounds = 4 instructions_template = 'ultimatum_game/Instructions.html' # Initial amount allocated to the dictator endowment = c(100) payoff_if_rejected = c(0) points_name = 'TJS' class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): p.timestamp_start = timezone.now() class Group(BaseGroup): sent = models.CurrencyField( doc="""Amount proposer decided to send to responder""", min=0, max=Constants.endowment, ) decision = models.StringField(initial=None, choices=['Accept', 'Reject'] ) average_accept = models.IntegerField(initial=150) average_overall = models.IntegerField(initial=150) def end_of_game(self): for p in self.get_players(): p.timestamp_end = timezone.now() def find_avarage(self): games = self.in_previous_rounds() previous = [] print("previous games") for i in games: previous.append(i.sent) return previous class Player(BasePlayer): timestamp_start = DateTimeField(default=timezone.now) timestamp_end = DateTimeField() answer1 = models.IntegerField(label="What will be the payoff of each participant?") answer2 = models.IntegerField(label="What will be the payoff of proposer?") answer3 = models.IntegerField(label="What will be the payoff of responder?") pass age = models.IntegerField(label="What is your year of birth:") gender = models.StringField(choices=['Female', 'Male', 'Other'], label='What is your gender?') nationality = models.StringField( label='What is your nationality?') education = models.StringField(choices=['I have a part-time job', 'I have a full time job', 'I have a stipend or scholarship', 'I depend on my family members', 'I am usually broke'], label='How do you make a living?') comment = models.StringField( label='Do you have any other comments?') def export_data(self, *args, **kwargs): data = super().export_data(*args, **kwargs) # Add timestamp columns to the data export data['timestamp_start'] = self.timestamp_start data['timestamp_end'] = self.timestamp_end return data