# -*- coding: utf-8 -*- # from __future__ import division from otree.db import models import otree.models import otree.constants from otree import widgets from otree.common import Currency as c, currency_range import random import itertools # from django_countries.fields import CountryField doc=""" In this game the payoff is determined by a random number. Lying is possible. The game assigns subjects to either the tax treatment or the subsidy treatment. Within each treatment the game randomly decides for every round whether even or odd numbers lead to the higher payoff. """ class Constants(otree.constants.BaseConstants): name_in_url = 'EvenorOdd' players_per_group = None num_rounds = 11 payoff_high = c(3) payoff_low = c(1.5) difference = c(1.5) class Subsession(otree.models.BaseSubsession): def before_session_starts(self): if self.round_number == 1: taxes = itertools.cycle([True, False]) pledges = itertools.cycle([True, True, False, False]) for p in self.get_players(): p.participant.vars['tax'] = next(taxes) p.participant.vars['round'] = random.randint(1, Constants.num_rounds-1) p.participant.vars['pledge'] = next(pledges) for p in self.get_players(): p.odd = random.choice([True, False]) p.taxtrue = p.participant.vars['tax'] p.pledgetrue = p.participant.vars['pledge'] p.paying_round = p.participant.vars['round'] class Group(otree.models.BaseGroup): subsession = models.ForeignKey(Subsession) class Player(otree.models.BasePlayer): group = models.ForeignKey(Group, null=True) subsession = models.ForeignKey(Subsession) taxtrue = models.BooleanField( doc="""Whether this player has tax-method""" ) odd = models.BooleanField( doc="""Whether this player has odd-method""" ) pledgetrue = models.BooleanField( doc="""Whether this player agrees to tell the truth""" ) paying_round = models.SmallIntegerField() answer = models.BooleanField( choices=[ (True, ''), (False, '') ], widget=widgets.RadioSelect, verbose_name="" ) roundpay = models.CurrencyField() relevant_roundpay = models.CurrencyField() payment_method = models.BooleanField( choices=[ (True, 'Skrill'), (False, 'Bank transfer') ], widget=widgets.RadioSelect, verbose_name="How do you want to be paid?" ) IBAN = models.CharField( blank=True, max_length=34, verbose_name='Please enter your IBAN number if you chose to receive your payment by bank transfer.' ) BIC = models.CharField( blank=True, max_length=11, verbose_name='Please enter your BIC/SWIFT code if you chose to receive your payment by bank transfer.' ) transfer_name = models.CharField( blank=True, verbose_name='Please enter your name if you chose to receive your payment by bank transfer.' ) country = CountryField(verbose_name='What is your country of citizenship?') age = models.PositiveIntegerField(verbose_name='What is your age?', choices=range(13, 125), initial=None) gender = models.CharField(initial=None, choices=['Male', 'Female'], verbose_name='What is your gender?', widget=widgets.RadioSelect()) career = models.CharField(initial=None, choices=['Student', 'Entry level', 'Experienced', 'Manager', 'Executive director', 'Senior executive', 'None of those' ], widget=widgets.RadioSelect, verbose_name='What is your current career level?') study = models.CharField(verbose_name='What is your field of study? (Please indicate "None" if not applicable)') family = models.CharField(initial=None, choices=['Married', 'Living together as married', 'Divorced', 'Widowed', 'Single'], widget=widgets.RadioSelect, verbose_name='Are you currently') children = models.SmallIntegerField(verbose_name='Do you have any children?', choices=[(0, 'None'), (1, 'One'), (2, 'Two'), (3, 'Three'), (4, 'Four'), (5, 'Five or more')]) purpose = models.CharField(verbose_name='What is the purpose of this experiment in your opinion?') trust = models.PositiveIntegerField(choices=[(1, 'Most people can be trusted.'), (2, 'Need to be very careful')], verbose_name='', widget=widgets.RadioSelect()) advantage = models.PositiveIntegerField(verbose_name='', choices=[(1, ''), (2, ''), (3, ''), (4, ''), (5, ''), (6, ''), (7, ''), (8, ''),(9, ''), (10, '')], widget=widgets.RadioSelectHorizontal()) claim_benefits = models.PositiveIntegerField(verbose_name='', choices=[(1, ''), (2, ''), (3, ''), (4, ''), (5, ''), (6, ''), (7, ''), (8, ''),(9, ''), (10, '')], widget=widgets.RadioSelectHorizontal()) fare_evasion = models.PositiveIntegerField(verbose_name='', choices=[(1, ''), (2, ''), (3, ''), (4, ''), (5, ''), (6, ''), (7, ''), (8, ''),(9, ''), (10, '')], widget=widgets.RadioSelectHorizontal()) stealing = models.PositiveIntegerField(verbose_name='', choices=[(1, ''), (2, ''), (3, ''), (4, ''), (5, ''), (6, ''), (7, ''), (8, ''),(9, ''), (10, '')], widget=widgets.RadioSelectHorizontal()) tax_evasion = models.PositiveIntegerField(verbose_name='', choices=[(1, ''), (2, ''), (3, ''), (4, ''), (5, ''), (6, ''), (7, ''), (8, ''),(9, ''), (10, '')], widget=widgets.RadioSelectHorizontal()) bribe = models.PositiveIntegerField(verbose_name='', choices=[(1, ''), (2, ''), (3, ''), (4, ''), (5, ''), (6, ''), (7, ''), (8, ''),(9, ''), (10, '')], widget=widgets.RadioSelectHorizontal()) # def set_variables(self): # if self.round_number == 1: # self.session.vars['tax'] = self.taxtrue # self.session.vars['pledge'] = self.pledgetrue # self.session.vars['round'] = self.paying_round def set_roundpay(self): if self.answer: self.roundpay = Constants.payoff_high else: self.roundpay = Constants.payoff_low if self.round_number == self.participant.vars['round']: self.relevant_roundpay = self.roundpay else: self.relevant_roundpay = 0 def set_payoff(self): if self.round_number != Constants.num_rounds: self.payoff = self.relevant_roundpay else: if self.payment_method: self.payoff = 0 else: self.payoff = - sum([p.payoff for p in self.in_previous_rounds()])