from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from selective_learning_quiz.slQuiz import PayoffQuiz import random import math class InstructionPage(Page): def is_displayed(self): return (self.round_number == 1) or (self.player.participant.vars["poor_performance"] == True) def before_next_page(self): self.player.participant.vars.update(PayoffQuiz.CellQuestion(self)) self.player.participant.vars.update(PayoffQuiz.AverageQuestion(self)) random_questions = [0]*(Constants.tot_no_of_q) random_answers = [0]*(Constants.tot_no_of_q) question_types = [0]*(Constants.tot_no_of_q) random_question = 0 random_answer = 0 question_type = 0 correct_answer = False tot_correct_answer = 0 self.player.participant.vars["random_questions"] = random_questions self.player.participant.vars["random_answers"] = random_answers self.player.participant.vars["question_types"] = question_types self.player.participant.vars["random_question"] = random_question self.player.participant.vars["random_answer"] = random_answer self.player.participant.vars["question_type"] = question_type self.player.participant.vars["correct_answer"] = correct_answer self.player.participant.vars["tot_correct_answer"] = tot_correct_answer random_index = [i for i in range(Constants.tot_no_of_q)] random.shuffle(random_index) self.player.quiz_counter = 0 all_questions = self.player.participant.vars["cell_questions"] + self.player.participant.vars["avg_questions"] all_answers = self.player.participant.vars["correct_payoff"] + self.player.participant.vars["true_num_list"] all_qtype = self.player.participant.vars["cutoff"] + [0]*(PayoffQuiz.no_of_avg_q) self.player.random_q_1 = all_questions[random_index[0]] self.player.random_a_1 = all_answers[random_index[0]] self.player.qtype_1 = all_qtype[random_index[0]] self.player.random_q_2 = all_questions[random_index[1]] self.player.random_a_2 = all_answers[random_index[1]] self.player.qtype_2 = all_qtype[random_index[1]] self.player.random_q_3 = all_questions[random_index[2]] self.player.random_a_3 = all_answers[random_index[2]] self.player.qtype_3 = all_qtype[random_index[2]] self.player.random_q_4 = all_questions[random_index[3]] self.player.random_a_4 = all_answers[random_index[3]] self.player.qtype_4 = all_qtype[random_index[3]] self.player.random_q_5 = all_questions[random_index[4]] self.player.random_a_5 = all_answers[random_index[4]] self.player.qtype_5 = all_qtype[random_index[4]] self.player.random_q_6 = all_questions[random_index[5]] self.player.random_a_6 = all_answers[random_index[5]] self.player.qtype_6 = all_qtype[random_index[5]] self.player.random_q_7 = all_questions[random_index[6]] self.player.random_a_7 = all_answers[random_index[6]] self.player.qtype_7 = all_qtype[random_index[6]] self.player.random_q_8 = all_questions[random_index[7]] self.player.random_a_8 = all_answers[random_index[7]] self.player.qtype_8 = all_qtype[random_index[7]] self.player.random_q_9 = all_questions[random_index[8]] self.player.random_a_9 = all_answers[random_index[8]] self.player.qtype_9 = all_qtype[random_index[8]] self.player.random_q_10 = all_questions[random_index[9]] self.player.random_a_10 = all_answers[random_index[9]] self.player.qtype_10 = all_qtype[random_index[9]] if self.round_number == 1: self.player.participant.vars["poor_performance"] = False class InstructionQuizPage(Page): def is_displayed(self): return (self.round_number == 1) or (self.player.participant.vars["poor_performance"] == True) class QuizPage(Page): form_model = 'player' form_fields = ['solution'] def is_displayed(self): return (self.round_number == 1) or ((self.player.participant.vars["poor_performance"] == True) and (self.player.quiz_counter <10)) def vars_for_template(self): if self.player.quiz_counter == 0: self.player.participant.vars["random_question"] = self.player.random_q_1 self.player.participant.vars["random_answer"] = self.player.random_a_1 self.player.participant.vars["question_type"] = self.player.qtype_1 if self.player.quiz_counter == 1: self.player.participant.vars["random_question"] = self.player.random_q_2 self.player.participant.vars["random_answer"] = self.player.random_a_2 self.player.participant.vars["question_type"] = self.player.qtype_2 if self.player.quiz_counter == 2: self.player.participant.vars["random_question"] = self.player.random_q_3 self.player.participant.vars["random_answer"] = self.player.random_a_3 self.player.participant.vars["question_type"] = self.player.qtype_3 if self.player.quiz_counter == 3: self.player.participant.vars["random_question"] = self.player.random_q_4 self.player.participant.vars["random_answer"] = self.player.random_a_4 self.player.participant.vars["question_type"] = self.player.qtype_4 if self.player.quiz_counter == 4: self.player.participant.vars["random_question"] = self.player.random_q_5 self.player.participant.vars["random_answer"] = self.player.random_a_5 self.player.participant.vars["question_type"] = self.player.qtype_5 if self.player.quiz_counter == 5: self.player.participant.vars["random_question"] = self.player.random_q_6 self.player.participant.vars["random_answer"] = self.player.random_a_6 self.player.participant.vars["question_type"] = self.player.qtype_6 if self.player.quiz_counter == 6: self.player.participant.vars["random_question"] = self.player.random_q_7 self.player.participant.vars["random_answer"] = self.player.random_a_7 self.player.participant.vars["question_type"] = self.player.qtype_7 if self.player.quiz_counter == 7: self.player.participant.vars["random_question"] = self.player.random_q_8 self.player.participant.vars["random_answer"] = self.player.random_a_8 self.player.participant.vars["question_type"] = self.player.qtype_8 if self.player.quiz_counter == 8: self.player.participant.vars["random_question"] = self.player.random_q_9 self.player.participant.vars["random_answer"] = self.player.random_a_9 self.player.participant.vars["question_type"] = self.player.qtype_9 if self.player.quiz_counter == 9: self.player.participant.vars["random_question"] = self.player.random_q_10 self.player.participant.vars["random_answer"] = self.player.random_a_10 self.player.participant.vars["question_type"] = self.player.qtype_10 return {"cell_questions": self.player.participant.vars["cell_questions"], "avg_questions": self.player.participant.vars["avg_questions"], "correct_payoff": self.player.participant.vars["correct_payoff"], "true_num_list": self.player.participant.vars["true_num_list"], "random_question": self.player.participant.vars["random_question"], "random_answer": self.player.participant.vars["random_answer"], "random_questions": self.player.participant.vars["random_questions"], "random_answers": self.player.participant.vars["random_answers"], "question_type": self.player.participant.vars["question_type"], "question_types": self.player.participant.vars["question_types"], "correct_answer" : self.player.participant.vars["correct_answer"], "random_payoff": self.player.participant.vars["random_payoff"]} class Results(Page): def is_displayed(self): return (self.round_number == 1) or ((self.player.participant.vars["poor_performance"] == True) and (self.player.quiz_counter <10)) def vars_for_template(self): if self.player.solution == self.player.participant.vars['random_answer']: self.player.participant.vars["correct_answer"] = True self.player.tot_correct_answer += 1 else: self.player.participant.vars["correct_answer"] = False return {"correct_answer": self.player.participant.vars["correct_answer"]} def before_next_page(self): self.player.quiz_counter += 1 self.player.total_score = self.player.tot_correct_answer if self.player.quiz_counter == 10: self.player.quiz_counter = self.player.quiz_counter - 10 if self.player.tot_correct_answer < 4: self.player.participant.vars["poor_performance"] = True self.player.tot_correct_answer = 0 else: self.player.participant.vars["poor_performance"] = False else: self.player.participant.vars["poor_performance"] == True quiz_page_sequence = [QuizPage, Results]*(Constants.tot_no_of_q) page_sequence = [InstructionPage, InstructionQuizPage ] + quiz_page_sequence