from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random doc = """ This is a task that requires real effort from participants. Subjects are shown two images of incomprehensible text. Subjects are required to transcribe (copy) the text into a text entry field. The quality of a subject's transcription is measured by the Levenshtein distance. """ def levenshtein(a, b): """Calculates the Levenshtein distance between a and b.""" n, m = len(a), len(b) if n > m: # Make sure n <= m, to use O(min(n,m)) space a, b = b, a n, m = m, n current = range(n + 1) for i in range(1, m + 1): previous, current = current, [i] + [0] * n for j in range(1, n + 1): add, delete = previous[j] + 1, current[j - 1] + 1 change = previous[j - 1] if a[j - 1] != b[i - 1]: change = change + 1 current[j] = min(add, delete, change) return current[n] def distance_and_ok(transcribed_text, reference_text, max_error_rate): error_threshold = len(reference_text) * max_error_rate distance = levenshtein(transcribed_text, reference_text) ok = distance <= error_threshold return distance, ok class Constants(BaseConstants): name_in_url = 'real_effort' players_per_group = None # payoff if player's transcribtion is correct""", gt_payoff = c(0.05) reference_texts = [ "Revealed preference", "Nel mezzo del cammin di nostra vita mi ritrovai per una selva oscura che la diritta via era smarrita", ] num_rounds = len(reference_texts) allowed_error_rates = [0.1, 0.5] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): prolific_id = models.StringField() age = models.IntegerField( label='What is your age?', min=13, max=125) gender = models.StringField( choices=['Male', 'Female'], label='What is your gender?', widget=widgets.RadioSelectHorizontal) statedcomplexity = models.IntegerField( label='What do you think is the level of complexity of the previous task on a 0 - 10 scale?".', choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], widget=widgets.RadioSelectHorizontal) transcribed_text = models.LongStringField() levenshtein_distance = models.IntegerField() is_correct = models.BooleanField() def current_question(self): return self.session.vars['questions'][self.round_number - 1] def check_correct(self): self.is_correct = (self.submitted_answer == self.solution)