from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'reject_allowance_02_treatment' players_per_group = None num_rounds = 20 # Adjust max_block and max_order instead max_block = 2 # 0 .. max_block max_order = 3 # 1 .. max_order Demand_Initial = 100 Ovarage_Cost = [[25,50,75],[50,75,25],[75,25,50],[25,75,50],[50,25,75],[75,50,25]] Underage_Cost = [[75,50,25],[50,25,75],[25,75,50],[75,25,50],[50,75,25],[25,50,75]] class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: import itertools treatments = itertools.cycle([0,1,2,3,4,5]) for p in self.get_players(): p.participant.vars['num_treatment'] = next(treatments) class Group(BaseGroup): pass class Player(BasePlayer): num_treatment = models.IntegerField() num_block = models.IntegerField(initial=0) num_order = models.IntegerField(initial=1) Q = models.IntegerField(min=0, max=999) Y = models.IntegerField() O = models.CurrencyField() U = models.CurrencyField() def live_yield(self,data): self.Q = data["Q"] return {"expected_yield":1}#round(Q/2.0)} def buildResultTable(self): result_table = '
Block | ' result_table += 'Runde | ' result_table += 'Kosten | ' result_table += 'Gewinn | ' result_table += '||
---|---|---|---|---|---|
' self.participant.payoff = 0 for b in range(0, Constants.max_block + 1): Payoff_Round = random.randint(1,Constants.max_order) for r in range(1, Constants.max_order + 1): l_intTotal_Cost = self.participant.vars['O_Cost_' + str(b) + '_' + str(r)] + self.participant.vars['U_Cost_' + str(b) + '_' + str(r)] if r == Payoff_Round: l_intTotal_Points = max(0,8000-l_intTotal_Cost) l_strTotal_Points = str(l_intTotal_Points) self.participant.payoff += l_intTotal_Points Fett_Begin = '' Fett_End = '' else: l_strTotal_Points = '' Fett_Begin = '' Fett_End = '' result_table += ' | |||||
' + Fett_Begin + str(b + 1) + Fett_End + ' | ' result_table += '' + Fett_Begin + str(r) + Fett_End + ' | ' result_table += '' + Fett_Begin + str(l_intTotal_Cost) + Fett_End + ' | ' result_table += '' + Fett_Begin + l_strTotal_Points + Fett_End + ' | ' result_table += '||
' result_table += ' | |||||
Gesamtgewinn: | ' + str(self.participant.payoff) + ' | ' result_table += '