from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import jellyfish class Task_Intro(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return{ 'min_tasks': self.session.config['min_tasks'], 'max_tasks': self.session.config['max_tasks'], 'image_path': 'transcription_pics/{}'.format(self.session.vars['example_task_path']), 'num_Examples': self.session.config['practice_rounds'], 'example_sol': self.session.vars['example_key'], 'reward_tasks': self.session.config['workreward_tasks'], } class TaskTrials(Page): form_model = 'player' form_fields = ['tran_submitted_answer'] def vars_for_template(self): player_in_all_rounds = self.player.in_all_rounds() return { 'image_path': 'transcription_pics/{}'.format(self.player.tran_path), 'player_in_all_rounds': player_in_all_rounds, 'sample_number_correct': sum([p.is_correct for p in player_in_all_rounds]), 'sample_target': self.session.config['practice_rounds'], 'sample_attempts': self.player.sample_tries, 'sample_task': self.player.transcription(), 'sample_correct_answer': self.player.tran_key, 'noise_timer_min': 180, 'noise_timer_max': 180, } def before_next_page(self): self.player.check_correct() def error_message(self, values): correct = jellyfish.levenshtein_distance(values['tran_submitted_answer'], self.player.tran_key)<7 if (self.player.sample_tries < 3): if not correct: self.player.sample_tries += 1 return "Incorrect, please try again." def is_displayed(self): player_in_all_rounds = self.player.in_all_rounds() bool_sample = sum([p.is_correct for p in player_in_all_rounds]) < self.session.config['practice_rounds'] return bool_sample page_sequence = [ Task_Intro, TaskTrials ]