from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from django.utils.translation import ugettext as _ import random import string import math author = 'Christoph Huber' doc = """ Post-Experiment Tasks for 'Sampling' """ class Constants(BaseConstants): name_in_url = 'postexp' players_per_group = None num_rounds = 1 currency1 = _("Euro") # "US-Dollars" or "British Pounds" currency2 = '€' # $ OR £ class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): p.participant.vars['rand_code'] = str(random.randint(1000, 9999)) + random.choice(string.ascii_letters) p.participant.vars['task'] = [] p.participant.vars['task_total'] = 4 p.participant.vars['task_sequence'] = [ 'Forecast', 'Choice', 'Error', 'Allocation' ] class Group(BaseGroup): pass class Player(BasePlayer): # Vars for FinLit finlit_1 = models.IntegerField(blank=True) finlit_2 = models.IntegerField(blank=True) finlit_3 = models.IntegerField(blank=True) finlit_4 = models.IntegerField(blank=True) finlit_5 = models.IntegerField(blank=True) # Vars for Risk risk_aversion1 = models.IntegerField(blank=True) risk_aversion2 = models.IntegerField(blank=True) # Vars for Pref1 pref1_1 = models.IntegerField(blank=True) pref1_2 = models.IntegerField(blank=True) pref1_3 = models.IntegerField(blank=True) pref1_4 = models.IntegerField(blank=True) # Vars for Pref2 pref2_1 = models.IntegerField(blank=True) pref2_2 = models.IntegerField(blank=True) pref2_3 = models.IntegerField(blank=True) # Vars for CRT crt4 = models.FloatField(blank=True) crt5 = models.FloatField(blank=True) crt6 = models.FloatField(blank=True) crt7 = models.FloatField(blank=True) # Vars for Demographics age = models.IntegerField(blank=True) female = models.IntegerField(blank=True) income = models.FloatField(blank=True) education = models.IntegerField(blank=True) jobfunction = models.IntegerField(blank=True) jobfunctiongp = models.CharField(blank=True) investment = models.IntegerField(blank=True) whichinvestment = models.CharField(blank=True) finnews = models.IntegerField(blank=True) comments = models.CharField(blank=True) matrikelnr = models.IntegerField(blank=True) rate = models.IntegerField(blank=True) understanding1 = models.IntegerField(blank=True) understanding2 = models.IntegerField(blank=True) understanding3 = models.IntegerField(blank=True) # Vars for Payment random_code = models.StringField(blank=True) PaymentType = models.StringField(blank=True) Email = models.StringField(blank=True) BANKname = models.StringField(blank=True) BANKiban = models.StringField(blank=True) payoff_block = models.IntegerField(blank=True) payoff_month = models.IntegerField(blank=True) payoff_return = models.FloatField(blank=True) def set_random_code(self): self.random_code = self.participant.vars['rand_code'] def set_payout(self): self.payoff_block = random.choice([1, 2, 3]) self.payoff_month = random.choice([1, 2, 3, 4, 5]) self.payoff_return = self.participant.vars['history'][6 * self.payoff_block - 6 + self.payoff_month][7] self.payoff = math.ceil(20 * (1 + 3 * self.payoff_return/100))