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 - elicitation """ class Constants(BaseConstants): name_in_url = 'elicitation' players_per_group = None num_rounds = 20 num_correct_needed = 5 required_tasks = 10 decisions = [1, 2, 3] w = int(20) p1 = c(0.5) p2 = c(0.25) dw = 5 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)) # decision_rounds = list(range(0,len(Constants.decisions))) # random.shuffle(decision_rounds) decision_rounds = list(range(1, len(Constants.decisions))) random.shuffle(decision_rounds) decision_rounds.insert(0,0) p.participant.vars['decision_rounds'] = dict(zip(Constants.decisions, decision_rounds)) # https://github.com/oTree-org/otree-snippets/blob/master/random_page_order/models.py # TODO: this way it generates matrix id for all not played rounds, as well 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() w1_certain = models.IntegerField( choices=range(0, Constants.w + 1, 1) ) w1_risky_today = models.IntegerField( choices=range(0, Constants.w + 1, 1) ) w1_risky_tomorrow = models.IntegerField( choices=range(0, Constants.w + 1, 1) ) rand1 = models.IntegerField() w1_rewarded = models.IntegerField() w2_rewarded = models.IntegerField()