from otree.api import * import random # import numpy as np doc = """ Your app description """ with open('houses_ratings/randomization_list.csv', 'r+') as fp: # read an store all lines into list lines = fp.readlines() # move file pointer to the beginning of a file fp.seek(0) # truncate the file fp.truncate() # start writing lines except the first line # lines[1:] from line 2 to last line fp.writelines(lines[1:]) fp.close() image_names = lines[0] image_names = image_names.split(",") all_names = [] for i in range(0, 5): shuffled_list = random.sample(image_names, len(image_names)) all_names.append(shuffled_list) dims = [[1, 5], [6, 10], [11, 15], [16, 20], [21, 25]] shuffled_dims = random.sample(dims, len(dims)) dims_intervals = shuffled_dims class C(BaseConstants): NAME_IN_URL = 'houses_ratings' PLAYERS_PER_GROUP = None NUM_ROUNDS = 25#500 csv_file = "houses_ratings/randomization_list.csv" csv_data = all_names class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): answer_hominess = models.FloatField() answer_safety = models.FloatField() answer_price = models.FloatField() answer_inviting = models.FloatField() answer_restoration = models.FloatField() #image_name = models.StringField() # PAGES class Introduction1(Page): form_model = "player" @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Introduction2(Page): form_model = "player" @staticmethod def is_displayed(player: Player): return player.round_number == 1 class ShowImage(Page): form_model = "player" timeout_seconds = 1 #@staticmethod #def vars_for_template(player: Player): # player.image_name = all_names[player.round_number - 1] class RatingsHominess(Page): form_model = "player" form_fields = ["answer_hominess"] @staticmethod def is_displayed(player: Player): return dims_intervals[0][0] <= player.round_number <= dims_intervals[0][1] class RatingsSafety(Page): form_model = "player" form_fields = ["answer_safety"] @staticmethod def is_displayed(player: Player): return dims_intervals[1][0] <= player.round_number <= dims_intervals[1][1] class RatingsPrice(Page): form_model = "player" form_fields = ["answer_price"] @staticmethod def is_displayed(player: Player): return dims_intervals[2][0] <= player.round_number <= dims_intervals[2][1] class RatingsInviting(Page): form_model = "player" form_fields = ["answer_inviting"] @staticmethod def is_displayed(player: Player): return dims_intervals[3][0] <= player.round_number <= dims_intervals[3][1] class RatingsRestoration(Page): form_model = "player" form_fields = ["answer_restoration"] @staticmethod def is_displayed(player: Player): return dims_intervals[4][0] <= player.round_number <= dims_intervals[4][1] page_sequence = [Introduction1, Introduction2, ShowImage, RatingsHominess, RatingsSafety, RatingsPrice, RatingsInviting, RatingsRestoration]