from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import numpy import random import csv import jellyfish author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'TaskTrials' players_per_group = None with open('TaskTrials/transcription_keys.csv') as key_file: transcription_key=list(csv.DictReader(key_file)) num_rounds = 10 class Subsession(BaseSubsession): def before_session_starts(self): for p in self.get_players(): if self.round_number==1: randomized_index = random.sample(Constants.transcription_key, len(Constants.transcription_key)) #this set will only be used for the samples, not for the main task p.participant.vars['sample_transcriptions'] = randomized_index #the rest are saved for the main task! #split the main task into the mandatory and then the main main p.participant.vars['mandatory_transcriptions'] = randomized_index[(Constants.num_rounds+2):((Constants.num_rounds+2)+Constants.num_rounds+1)] p.participant.vars['main_transcriptions'] = randomized_index[((Constants.num_rounds+2)+Constants.num_rounds+2):] self.session.vars['example_task_path'] = randomized_index[0]['file'] self.session.vars['example_key'] = randomized_index[0]['answer_key'] p.sample_tries = 1 transcription_data = p.transcription() p.tran_key = transcription_data['answer_key'] p.tran_path = transcription_data['file'] class Group(BaseGroup): pass class Player(BasePlayer): tran_id = models.PositiveIntegerField() tran_key = models.CharField() tran_path = models.CharField() tran_submitted_answer = models.CharField() sample_tries = models.PositiveIntegerField() is_correct = models.BooleanField(initial = 0) num_changes_req=models.PositiveIntegerField() def transcription(self): return self.participant.vars['sample_transcriptions'][self.round_number-1] def check_correct(self): self.is_correct=jellyfish.levenshtein_distance(self.tran_key,self.tran_submitted_answer)<7