from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import _random class Constants(BaseConstants): name_in_url = 'Elicitation_wtp' players_per_group = 2 num_rounds = 1 section_3_num = 5 class Subsession(BaseSubsession): def creating_session(self): pass class Group(BaseGroup): Game_choice = models.IntegerField( choices=[ [0, 'Task 1'], [1, 'Task 2'], ], label='', widget=widgets.RadioSelect, ) WTP_choice = models.FloatField( label='Please enter a number between 0.25 and 5 which is a multiple of 0.25.', choices=[0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5], min=0.25, max=5) realized = models.IntegerField() #0 for Task 1 and 1 for Task 2 rand = models.IntegerField() rand_exodraw = models.IntegerField() rand_endodraw = models.FloatField() def get_rand(self): self.rand = random.choices([1, 2, 3, 4, 5, 6], k=1)[0] return self.rand def get_rand_exodraw(self): self.rand_exodraw = random.choices([1, 2], k=1)[0] return self.rand_exodraw def get_rand_endodraw(self): choicelist = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5] self.rand_endodraw = random.choices(choicelist, k=1)[0] return self.rand_endodraw class Player(BasePlayer): elicitation_pay = models.FloatField() def role(self): if self.id_in_group == 1: return 'Row Player' else: return 'Column Player'