from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from itertools import product from string import ascii_uppercase from csv import reader as csvreader from random import shuffle, getrandbits from os import listdir from copy import deepcopy author = 'Tillmann Nett' doc = """ Simple Decision matrix app """ path = "Training" # Read trial definitions with open(path + "/Trials.csv") as trialfile: trials = [l for l in csvreader(trialfile)] trials = [dict(z for z in zip(trials[0],t)) for i,t in enumerate(trials) if i > 0] # Generate product and tester names names = [''.join(i) for i in product("AEIOUY", repeat = 4)] class Constants(BaseConstants): name_in_url = 'Training' players_per_group = None repeats = 1 num_rounds = len(trials) * repeats class Subsession(BaseSubsession): def before_session_starts(self): for p in self.get_players(): if "trials_training" not in p.participant.vars: trs = [i for i,_ in enumerate(trials)] * Constants.repeats shuffle(trs) p.participant.vars["trials_training"] = trs if "names_training" not in p.participant.vars: ns = [i for i,_ in enumerate(names)] shuffle(ns) ns = ns[ :(8*Constants.num_rounds + 1) ] p.participant.vars["names_training"] = ns # Number of the current trial encoded in participant.vars tn = p.participant.vars["trials_training"][p.round_number - 1] t = trials[int(tn)] # Number of name for product 1 and 2 in participant.vars pn1 = p.participant.vars["names_training"][(p.round_number-1) * 8] pn2 = p.participant.vars["names_training"][(p.round_number-1) * 8 + 1] pr1 = names[int(pn1)] pr2 = names[int(pn2)] p.option1name = pr1 p.option2name = pr2 # Number of name for tester 1-6 cn1 = p.participant.vars["names_training"][(p.round_number-1) * 8 + 2] cn2 = p.participant.vars["names_training"][(p.round_number-1) * 8 + 3] cn3 = p.participant.vars["names_training"][(p.round_number-1) * 8 + 4] cn4 = p.participant.vars["names_training"][(p.round_number-1) * 8 + 5] cn5 = p.participant.vars["names_training"][(p.round_number-1) * 8 + 6] cn6 = p.participant.vars["names_training"][(p.round_number-1) * 8 + 7] tn1 = names[int(cn1)] tn2 = names[int(cn2)] tn3 = names[int(cn3)] tn4 = names[int(cn4)] tn5 = names[int(cn5)] tn6 = names[int(cn6)] p.cue1name = tn1 p.cue2name = tn2 p.cue3name = tn3 p.cue4name = tn4 p.cue5name = tn5 p.cue6name = tn6 # Trial definition (from CSV): # "taskNo","val1","val2","val3","val4","val5","val6","Acue1","Acue2","Acue3","Acue4","Acue5","Acue6","Bcue1","Bcue2","Bcue3","Bcue4","Bcue5","Bcue6","NaiveBayes" p.taskNo = t["taskNo"] p.val1 = t["val1"] p.val2 = t["val2"] p.val3 = t["val3"] p.val4 = t["val4"] p.val5 = t["val5"] p.val6 = t["val6"] p.Acue1 = t["Acue1"] p.Acue2 = t["Acue2"] p.Acue3 = t["Acue3"] p.Acue4 = t["Acue4"] p.Acue5 = t["Acue5"] p.Acue6 = t["Acue6"] p.Bcue1 = t["Bcue1"] p.Bcue2 = t["Bcue2"] p.Bcue3 = t["Bcue3"] p.Bcue4 = t["Bcue4"] p.Bcue5 = t["Bcue5"] p.Bcue6 = t["Bcue6"] p.NaiveBayes = t["NaiveBayes"] # Random order for options p.optionorder = getrandbits(1) # cueorder = [1,2,3,4,5,6] # shuffle(cueorder) # # Random order for cues # p.cue1order = cueorder[0] # p.cue2order = cueorder[1] # p.cue3order = cueorder[2] # p.cue4order = cueorder[3] # p.cue5order = cueorder[4] # p.cue6order = cueorder[5] class Group(BaseGroup): pass class Player(BasePlayer): taskNo = models.IntegerField() val1 = models.DecimalField(max_digits=2, decimal_places=2) val2 = models.DecimalField(max_digits=2, decimal_places=2) val3 = models.DecimalField(max_digits=2, decimal_places=2) val4 = models.DecimalField(max_digits=2, decimal_places=2) val5 = models.DecimalField(max_digits=2, decimal_places=2) val6 = models.DecimalField(max_digits=2, decimal_places=2) Acue1 = models.IntegerField() Acue2 = models.IntegerField() Acue3 = models.IntegerField() Acue4 = models.IntegerField() Acue5 = models.IntegerField() Acue6 = models.IntegerField() Bcue1 = models.IntegerField() Bcue2 = models.IntegerField() Bcue3 = models.IntegerField() Bcue4 = models.IntegerField() Bcue5 = models.IntegerField() Bcue6 = models.IntegerField() NaiveBayes = models.IntegerField() option1name = models.CharField(max_length=4) option2name = models.CharField(max_length=4) cue1name = models.CharField(max_length=4) cue2name = models.CharField(max_length=4) cue3name = models.CharField(max_length=4) cue4name = models.CharField(max_length=4) cue5name = models.CharField(max_length=4) cue6name = models.CharField(max_length=4) optionorder = models.IntegerField() # cue1order = models.IntegerField() # cue2order = models.IntegerField() # cue3order = models.IntegerField() # cue4order = models.IntegerField() # cue5order = models.IntegerField() # cue6order = models.IntegerField() choice = models.IntegerField() Acc = models.IntegerField() # Accuracy certainty = models.IntegerField(min=-100, max=100, widget=widgets.SliderInput(attrs={'step': '1'}, show_value=False)) decisionStart = models.BigIntegerField() decisionEnd = models.BigIntegerField() certaintyEnd = models.BigIntegerField() decisionRT = models.IntegerField() certaintyRT = models.IntegerField()