from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = '' class Constants(BaseConstants): name_in_url = 't_welcome_essay' players_per_group = 6 num_rounds = 1 piece_rate_high = c(0.16) piece_rate_low = c(0.14) class Subsession(BaseSubsession): pass class Group(BaseGroup): def method733453(self): from statistics import median # group players into high payrate and low payrate group print('in after_all_players_arrive') tmplist = [] toggle = False for player in self.get_players(): player.essay_amount_r = player.essay.count('r') print("Anzahl r im Essay:", player.essay_amount_r) tmplist.append(player.essay_amount_r) for player in self.get_players(): if median(tmplist) < player.essay_amount_r: player.participant.vars['group_high'] = True if median(tmplist) > player.essay_amount_r: player.participant.vars['group_high'] = False if median(tmplist) == player.essay_amount_r: player.participant.vars['group_high'] = toggle toggle = not toggle if player.participant.vars['group_high'] == True: player.participant.vars['payrate'] = Constants.piece_rate_high else: player.participant.vars['payrate'] = Constants.piece_rate_low #print("Spieler in high payrate group?", player.participant.vars['group_high']) def method327982(self): import time # Each player gets 10 minutes (expiry time is saved) for p in self.get_players(): p.participant.vars['expiry'] = time.time() + 10*60 class Player(BasePlayer): essay = models.LongStringField() essay_amount_r = models.IntegerField()