import pathlib from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'news_prosumers_2' PLAYERS_PER_GROUP = None NUM_ROUNDS = 40 RET_price = cu(0.30) class Subsession(BaseSubsession): pass class Coins(ExtraModel): tasks = models.IntegerField() table = models.StringField() coin = models.StringField() value = models.FloatField() country = models.StringField() def creating_session(subsession: Subsession): rows = read_csv(__name__ + '/cointask_list1_trial.csv', Coins) number_tasks = len(rows) tasks = [] tables = [] coins = [] values = [] countries = [] for i in range(0, number_tasks): tasks.append(rows[i]['tasks']) tables.append(rows[i]['table']) coins.append(rows[i]['coin']) values.append(rows[i]['value']) countries.append(rows[i]['country']) for p in subsession.get_players(): p.participant.tasks_1 = tasks p.participant.tables_1 = tables p.participant.coins_1 = coins p.participant.RET_trial_value = values p.participant.RET_trial_country = countries class Group(BaseGroup): pass class Player(BasePlayer): country = models.StringField( widget=widgets.RadioSelect, choices=[ 'Andorra', 'Austria', 'Belgium', 'Cyprus', 'Estonia', 'Finland', 'France', 'Germany', 'Greece', 'Ireland', 'Italy', 'Latvia', 'Lithuania', 'Luxembourg', 'Malta', 'Monaco', 'Netherlands', 'Portugal', 'San Marino', 'Slovakia', 'Slovenia', 'Spain', 'Vatican City' ], label='Country' ) value_coin = models.FloatField( widget=widgets.RadioSelect, choices=[0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2], label="Value" ) RET_correct_individual_attempt_trial = models.IntegerField() RET_trial_correct = models.IntegerField() RET_trial_attempt = models.IntegerField() leavescreen_8 = models.IntegerField(blank=True) leavescreen_9 = models.IntegerField(blank=True) def get_timeout_seconds(player): participant = player.participant import time return participant.expiry_1 - time.time() # PAGES class Task_1(Page): get_timeout_seconds = get_timeout_seconds timer_text = 'Residual time' @staticmethod def is_displayed(player): return get_timeout_seconds(player) > 0 form_model = 'player' form_fields = ['country', 'value_coin', 'leavescreen_8'] @staticmethod def vars_for_template(player: Player): return dict(image_path_coin='news_prosumers/{}'.format(player.participant.coins_1[player.round_number-1]), image_path_table='news_prosumers/{}'.format(player.participant.tables_1[player.round_number-1])) @staticmethod def before_next_page(player: Player, timeout_happened): player_country_guess = player.country player_country_guess_processed = player_country_guess.replace(" ", "").lower() if player.participant.RET_trial_value[player.round_number-1] == player.value_coin and player.participant.RET_trial_country[player.round_number-1] == player_country_guess_processed: player.RET_correct_individual_attempt_trial = 1 else: player.RET_correct_individual_attempt_trial = 0 class Pre_task(Page): # timeout_seconds = 10 # timeout_seconds = 10 form_model = 'player' form_fields = ['leavescreen_9'] @staticmethod def is_displayed(player: Player): return player.round_number == C.NUM_ROUNDS @staticmethod def before_next_page(player: Player, timeout_happened): coins = [] countries = [] for p in player.in_all_rounds(): coins.append(p.field_maybe_none('value_coin')) countries.append(p.field_maybe_none('country')) correct = 0 for i in range(0, C.NUM_ROUNDS - 1): if coins[i] == player.participant.RET_trial_value[i] and countries[i].replace(" ", "").lower() == player.participant.RET_trial_country[i]: correct += 1 player.RET_trial_correct = correct player.RET_trial_attempt = len(countries) - countries.count(None) - countries.count('') import time player.participant.expiry_2 = time.time() + 2 * 60 page_sequence = [ Task_1, Pre_task ]