from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import jellyfish class Task_Intro2(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return { 'image_path': 'transcription_pics/{}'.format(self.session.vars['example_task_path']), 'example_sol': self.session.vars['example_key'], 'numTasks_todo': self.participant.vars['tasks_chosen'], 'wage_realized': self.participant.vars['wage_final'], 'show_up_fee': self.session.config['participation_fee'], 'total_earnings': self.participant.payoff_plus_participation_fee(), 'potential_wage_low': self.participant.vars['wage_potential_l'], 'potential_wage_high': self.participant.vars['wage_potential_h'], 'fixed_possible': self.participant.vars['fixed_chosen'], 'num_mandatory': self.session.config['mandatory_rounds'] } class Mandatory_Tasks_Click(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, 'mandatory_number_correct': sum([p.is_correct for p in player_in_all_rounds]), 'mandatory_target': self.session.config['mandatory_rounds'], 'mandatory_attempts': self.player.tries, 'mandatory_task': self.player.transcription(), 'mandatory_correct_answer': self.player.tran_key, 'noise_timer_min': 5, 'noise_timer_max': 15, } 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.tries < 3): if not correct: self.player.tries += 1 return "Incorrect, please try again." def is_displayed(self): player_in_all_rounds = self.player.in_all_rounds() bool0 = sum([p.is_correct for p in player_in_all_rounds]) < self.session.config['mandatory_rounds'] return bool0 page_sequence = [ Task_Intro2, Mandatory_Tasks_Click, ]