from otree.api import Currency as c, currency_range, safe_json from ._builtin import WaitPage, Page as oTreePage from .models import Constants import numpy as np import random import string import re import json total_page_count = 59 final_round = 6 all_rounds =[1,2,3,4,5,6] task_order = [24, 30, 19, 45, 14, 40, 17, 50, 36, 14] #references = [28, 25, 17, 40, 17, 42, 15, 47, 34, 16] #correct_answers = ["less", "more", "more", "more", "less", "less", "more", "more", "more", "less"] class Page(oTreePage): def get_progress(self): totpages = self.participant._max_page_index curpage = self.participant._index_in_pages return f"{curpage / totpages * 100:.0f}" class Introduction_Quiz(Page): def is_displayed(self): return (self.player.round_number == 1) def before_next_page(self): for r in all_rounds: self.player.in_round(r).progress = np.int(100*self.participant._index_in_pages / self.participant._max_page_index) self.participant.vars['page_count'] = self.participant.vars['page_count'] + 1 def vars_for_template(self): return {'progress': np.int(100*(self.participant.vars['page_count'] / total_page_count))} class Comprehension_Quiz(Page): form_model = 'player' form_fields = ['comprehension_tries_quiz_1', 'comprehension_tries_quiz_2','comprehension_tries_quiz_3'] def is_displayed(self): return (self.player.round_number == 1) def before_next_page(self): for r in all_rounds: self.player.in_round(r).progress = np.int(100*self.participant._index_in_pages / self.participant._max_page_index) self.participant.vars['page_count'] = self.participant.vars['page_count'] + 1 def vars_for_template(self): return {'progress': np.int(100*(self.participant.vars['page_count'] / total_page_count))} class Ready(Page): def before_next_page(self): self.player.number_dots = task_order[self.player.round_number - 1] for r in all_rounds: self.player.in_round(r).progress = np.int(100*self.participant._index_in_pages / self.participant._max_page_index) self.participant.vars['page_count'] = self.participant.vars['page_count'] + 1 def vars_for_template(self): r = self.player.round_number if r == 1: r = 2 return {'progress': np.int(100*(self.participant.vars['page_count'] / total_page_count)), 'former_answer': self.player.in_round(r-1).answer} class Image(Page): timeout_seconds = 5 form_model = 'player' def before_next_page(self): for r in all_rounds: self.player.in_round(r).progress = np.int(100*self.participant._index_in_pages / self.participant._max_page_index) self.participant.vars['page_count'] = self.participant.vars['page_count'] + 1 def vars_for_template(self): index = self.player.round_number - 1 return {'progress': np.int(100*(self.participant.vars['page_count'] / total_page_count)), 'task': safe_json(task_order[index]),} class Answer(Page): timeout_seconds = 10 form_model = 'player' form_fields = ['answer'] def before_next_page(self): for r in all_rounds: self.player.in_round(r).progress = np.int(100*self.participant._index_in_pages / self.participant._max_page_index) self.participant.vars['page_count'] = self.participant.vars['page_count'] + 1 if self.player.round_number == 6: total_deviation = 0 for r in all_rounds: if self.player.answer - self.player.number_dots > 0: total_deviation = total_deviation + self.player.answer - self.player.number_dots if self.player.answer - self.player.number_dots < 0: total_deviation = total_deviation - self.player.answer + self.player.number_dots self.player.total_deviation = total_deviation def vars_for_template(self): return {'progress': np.int(100*(self.participant.vars['page_count'] / total_page_count)),} class Example(Page): timeout_seconds = 5 form_model = 'player' def is_displayed(self): return (self.player.round_number == 1) def before_next_page(self): for r in all_rounds: self.player.in_round(r).progress = np.int(100*self.participant._index_in_pages / self.participant._max_page_index) self.participant.vars['page_count'] = self.participant.vars['page_count'] + 1 def vars_for_template(self): index = self.player.round_number - 1 return {'progress': np.int(100*(self.participant.vars['page_count'] / total_page_count)), 'task': safe_json(task_order[index]),} class Answer_Example(Page): timeout_seconds = 10 form_model = 'player' form_fields = ['answer_example'] def is_displayed(self): return (self.player.round_number == 1) def before_next_page(self): for r in all_rounds: self.player.in_round(r).progress = np.int(100*self.participant._index_in_pages / self.participant._max_page_index) self.participant.vars['page_count'] = self.participant.vars['page_count'] + 1 def vars_for_template(self): return {'progress': np.int(100*(self.participant.vars['page_count'] / total_page_count)),} class Ready_Example(Page): def is_displayed(self): return (self.player.round_number == 1) def before_next_page(self): for r in all_rounds: self.player.in_round(r).progress = np.int(100*self.participant._index_in_pages / self.participant._max_page_index) self.participant.vars['page_count'] = self.participant.vars['page_count'] + 1 self.player.number_dots = 21 def vars_for_template(self): return {'progress': np.int(100*(self.participant.vars['page_count'] / total_page_count)),} class Done_Example(Page): def is_displayed(self): return (self.player.round_number == 1) def before_next_page(self): for r in all_rounds: self.player.in_round(r).progress = np.int(100*self.participant._index_in_pages / self.participant._max_page_index) self.participant.vars['page_count'] = self.participant.vars['page_count'] + 1 def vars_for_template(self): return {'progress': np.int(100*(self.participant.vars['page_count'] / total_page_count)), 'former_answer': self.player.answer_example} page_sequence = [Introduction_Quiz, Comprehension_Quiz, Ready_Example, Example, Answer_Example, Done_Example, Ready, Image, Answer]