def test_is_learned_based_on_exercise_outcomes(self): random_bookmarks = [BookmarkRule(self.user).bookmark for _ in range(0, 4)] # Empty exercise_log should lead to a False return learned = is_learned_based_on_exercise_outcomes( SortedExerciseLog(random_bookmarks[0]) ) assert not learned # An exercise with Outcome equal to TOO EASY results in True, and time of last exercise random_exercise = ExerciseRule().exercise random_exercise.outcome = OutcomeRule().too_easy random_bookmarks[1].add_new_exercise(random_exercise) learned = is_learned_based_on_exercise_outcomes( SortedExerciseLog(random_bookmarks[1]) ) result_time = SortedExerciseLog(random_bookmarks[1]).last_exercise_time() assert learned and result_time == random_exercise.time # Same test as above, but without a second return value learned = is_learned_based_on_exercise_outcomes( SortedExerciseLog(random_bookmarks[1]) ) assert learned # A bookmark with CORRECTS_IN_A_ROW_FOR_LEARNED correct exercises in a row # returns true and the time of the last exercise correct_bookmark = random_bookmarks[2] exercises = 0 distinct_dates = set() while not ( exercises >= CORRECTS_IN_A_ROW_FOR_LEARNED and len(distinct_dates) >= CORRECTS_IN_DISTINCT_DAYS_FOR_LEARNED ): correct_exercise = ExerciseRule().exercise correct_exercise.outcome = OutcomeRule().correct correct_bookmark.add_new_exercise(correct_exercise) exercises += 1 distinct_dates.add(correct_exercise.time.date()) correct_bookmark.update_learned_status(self.db.session) log = SortedExerciseLog(correct_bookmark) learned = is_learned_based_on_exercise_outcomes(log) result_time = log.last_exercise_time() assert learned log = SortedExerciseLog(correct_bookmark) learned_time_from_log = log.last_exercise_time() assert result_time == learned_time_from_log # A bookmark with no TOO EASY outcome or less than 5 correct exercises in a row returns False, None wrong_exercise = ExerciseRule().exercise wrong_exercise.outcome = OutcomeRule().wrong random_bookmarks[3].add_new_exercise(wrong_exercise) log = SortedExerciseLog(random_bookmarks[3]) learned = is_learned_based_on_exercise_outcomes(log) assert not learned
def fit_for_study(bookmark): exercise_log = SortedExerciseLog(bookmark) return ((quality_bookmark(bookmark) or bookmark.starred) and not is_learned_based_on_exercise_outcomes(exercise_log) and not feedback_prevents_further_study(exercise_log))
def update_learned_status(self, session): """ To call when something happened to the bookmark, that requires it's "learned" status to be updated. :param session: :return: """ log = SortedExerciseLog(self) is_learned = is_learned_based_on_exercise_outcomes(log) if is_learned: zeeguu_core.log(f"Log: {log.summary()}: bookmark {self.id} learned!") self.learned_time = log.last_exercise_time() self.learned = True session.add(self) else: zeeguu_core.log(f"Log: {log.summary()}: bookmark {self.id} not learned yet.")
def print_bookmarks_that_are_wrongly_learned(bookmarks): i = 0 for bookmark in bookmarks: if not bookmark.learned_time: continue algo_result = is_learned_based_on_exercise_outcomes(bookmark) if bookmark.learned != algo_result: print( f"){i}) mismatch: {bookmark} DB={bookmark.learned} ALGO={algo_result}" ) print(bookmark.compact_sorted_exercise_log()) print(" ") i += 1 bookmark.learned = algo_result db.session.add(bookmark) print("committing all the changes to the DB") db.session.commit()