from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import csv import random author = 'Luca' doc = """ Ceci n'est pas une excuse - today's tasks """ class Constants(BaseConstants): name_in_url = 'tasks_today' players_per_group = None num_rounds = 50 required_tasks = 10 def create_matrix_database(): with open('_static/elicitation/matrix.csv', mode='r') as file: reader = csv.reader(file) return {int(rows[0]): int(rows[1]) for rows in reader} # https://stackoverflow.com/questions/6740918/creating-a-dictionary-from-a-csv-file Matrix = create_matrix_database() class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): p.matrix_id_in_round = random.choice(range(1, 200)) class Group(BaseGroup): pass class Player(BasePlayer): answer = models.IntegerField() # if blank=True then can be left blank answer_correct = models.BooleanField() matrix_id_in_round = models.IntegerField()