from otree.api import * from time import time doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'csr_intro' players_per_group = None num_rounds = 1 conversion = 300 donation_percentage = "10" data_attitude_file = '_static/global/data/data_attitude.csv' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): attitude = models.StringField() # FUNCTIONS def read_csv(file): from csv import DictReader f = open(file, encoding='utf8') rows = list(DictReader(f)) file_as_dict = {list(r.values())[0]: list(r.values())[1] for r in rows} return file_as_dict def set_participant_attitude(player: Player, const: Constants): participant = player.participant data_attitude = read_csv(const.data_attitude_file) attitude = data_attitude[participant.label] participant.attitude = attitude player.attitude = attitude # PAGES class Consent(Page): @staticmethod def before_next_page(player: Player, timeout_happened): set_participant_attitude(player, Constants) class Intro(Page): pass class Overview(Page): pass class Sustainable(Page): pass class YourTask(Page): @staticmethod def before_next_page(player: Player, timeout_happened): player.participant.grouping_page_arrival = time() page_sequence = [Consent, Intro, Overview, Sustainable, YourTask]