def give_quiz(self, questions): """ Give the quiz to the student, update the question_back and score for that student :param questions: questions that are going to be given. :return: new question_bank, new score """ temp = {} total_score = [] for i in questions: # for manual input ans # ans = input('Answer Question ' + str(i) + ': ') # conf = input('Pick a self reported confidence score ranging [0, 2]: ') # to use answer_question method from Student class ans = self.student.answer_question(self.questions[i]) print('Answer Question ' + str(i) + ': ' + str(ans)) # randomly pick a confidence score for experimentation purposes conf = random.randint(0, 2) print('Pick a self reported confidence score ranging [0, 2]: ' + str(conf)) # calculate the score using Scorer class s = Scorer(i, self.questions[i], ans, conf) evaluation = s.calculate_confidence() score = s.calculate_score() temp[i] = evaluation total_score.append(score) evaluations, student_score, schedule, intervals, easiness = \ self.update_student_history(new_evaluation=temp, new_score=np.mean(total_score)) print('for student' + str(self.student_name) + '\n' + 'Student Score:' + str(student_score)) # update student question_bank and mastered questions self.student.question_bank = evaluations self.student.update_mastered() self.student.intervals = intervals self.student.easiness = easiness # print for visualization self.print_evaluation(evaluations) self.print_schedule(schedule) # Save connection = psycopg2.connect(user="******", password="******", host="127.0.0.1", port="5432", database="sm2") cursor = connection.cursor() str_dict, str_score, str_schedule, str_mastered, str_intervals, str_easiness = \ json.dumps(evaluations), json.dumps(self.student.score), json.dumps(schedule), \ json.dumps(list(self.student.mastered)), json.dumps(intervals), json.dumps(easiness) insert_table_query = f''' INSERT INTO PUBLIC.STUDENT (STUDENT_NAME, QUESTION_BANK, SCORE, SCHEDULE, MASTERED, INTERVALS, EASINESS) VALUES ('{self.student.student_name}','{str_dict}', '{str_score}', '{str_schedule}', '{str_mastered}','{str_intervals}','{str_easiness}') ON CONFLICT (STUDENT_NAME) DO UPDATE SET QUESTION_BANK = '{str_dict}', SCORE = '{str_score}', SCHEDULE = '{str_schedule}', MASTERED = '{str_mastered}', INTERVALS = '{str_intervals}', EASINESS = '{str_easiness}'; ''' cursor.execute(insert_table_query) connection.commit() connection.close() return temp, np.mean(total_score)