from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'Prueba3C2' PLAYERS_PER_GROUP = 3 NUM_ROUNDS = 1 REGR = (0.167, 0.333, 0.5) E = 20 W = 120 PROD = (6, 3, 2) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass def S1calculation(group: Group): group = group players = group.get_players() for p in players : p.total_aporte = round(30 + p.aporte) if p.total_aporte == 0 : p.water_available = 0 if p.total_aporte == 5 : p.water_available = 3 if p.total_aporte == 10 : p.water_available = 6 if p.total_aporte == 15 : p.water_available = 9 if p.total_aporte == 20 : p.water_available = 12 if p.total_aporte == 25 : p.water_available = 36 if p.total_aporte == 30 : p.water_available = 42 if p.total_aporte == 35 : p.water_available = 45 if p.total_aporte == 40 : p.water_available = 51 if p.total_aporte == 45 : p.water_available = 105 if p.total_aporte == 50 : p.water_available = 108 if p.total_aporte == 55 : p.water_available = 114 if p.total_aporte == 60 : p.water_available = 120 p.water_share = round(p.water_available*C.PROD[p.type-1]*C.REGR[p.type-1]) p.left = C.E-p.aporte p.benefits = round(p.left+p.water_share) def my_function(group: Group): group = group players = group.get_players() for p in players : p.type = p.participant.vars["type"] p.type2 = p.participant.vars["type2"] Group.S1calculation = S1calculation class Player(BasePlayer): aporte = models.IntegerField(choices=[[0, '0'], [5, '5'], [10, '10'], [15, '15'], [20, '20']], initial=0, max=C.E, min=0) total_aporte = models.FloatField() water_available = models.FloatField() water_share = models.FloatField() left = models.IntegerField() benefits = models.FloatField() acumulated = models.FloatField(initial=0) acumulated_global = models.FloatField() type = models.IntegerField() type2 = models.StringField() class MyWaitPage(WaitPage): after_all_players_arrive = my_function class EjercicioenGrupo12(Page): form_model = 'player' form_fields = ['aporte'] class StagePruebacalculation(WaitPage): after_all_players_arrive = S1calculation class StagePruebaresults(Page): form_model = 'player' page_sequence = [MyWaitPage, EjercicioenGrupo12, StagePruebacalculation, StagePruebaresults]