Esempio n. 1
0
def report_exercise_outcome(exercise_outcome, exercise_source,
                            exercise_solving_speed, bookmark_id):
    """
    In the model parlance, an exercise is an entry in a table that
    logs the performance of an exercise. Every such performance, has a source, and an outcome.

    :param exercise_outcome: One of: Correct, Retry, Wrong, Typo, Too easy...
    :param exercise_source: has been assigned to your app by zeeguu
    :param exercise_solving_speed: in milliseconds
    :param bookmark_id: the bookmark for which the data is reported
    :return:
    """

    if not exercise_solving_speed.isdigit():
        exercise_solving_speed = 0

    try:
        bookmark = Bookmark.find(bookmark_id)
        bookmark.report_exercise_outcome(exercise_source, exercise_outcome,
                                         exercise_solving_speed, db_session)

        return "OK"
    except:
        traceback.print_exc()
        return "FAIL"
Esempio n. 2
0
def delete_bookmark(bookmark_id):
    try:
        bookmark = Bookmark.find(bookmark_id)
        db_session.delete(bookmark)
        db_session.commit()
    except NoResultFound:
        return "Inexistent"

    return "OK"
Esempio n. 3
0
def report_learned_bookmark(bookmark_id):
    bookmark = Bookmark.find(bookmark_id)
    bookmark.report_exercise_outcome(
        ExerciseSource.TOP_BOOKMARKS_MINI_EXERCISE,
        ExerciseOutcome.CORRECT,
        -1,
        db_session,
    )

    return "OK"
Esempio n. 4
0
def report_exercise_outcome(exercise_outcome, exercise_source,
                            exercise_solving_speed, bookmark_id):
    """
    In the model parlance, an exercise is an entry in a table that
    logs the performance of an exercise. Every such performance, has a source, and an outcome.

    :param exercise_outcome: One of: Correct, Retry, Wrong, Typo, Too easy
    :param exercise_source: has been assigned to your app by zeeguu
    :param exercise_solving_speed: in milliseconds
    :param bookmark_id: the bookmark for which the data is reported
    :return:
    """

    try:
        bookmark = Bookmark.find(bookmark_id)
        new_source = ExerciseSource.find(exercise_source)
        new_outcome = ExerciseOutcome.find_or_create(db_session,
                                                     exercise_outcome)

        if not bookmark:
            return "could not find bookmark"

        if not new_source:
            return "could not find source"

        if not new_outcome:
            return "could not find outcome"

        exercise = Exercise(new_outcome, new_source, exercise_solving_speed,
                            datetime.now())
        bookmark.add_new_exercise(exercise)
        bookmark.update_fit_for_study(db_session)
        bookmark.update_learned_status(db_session)
        db_session.add(exercise)
        db_session.commit()

        # Update the exercise session
        from zeeguu_core.model import UserExerciseSession
        UserExerciseSession.update_exercise_session(exercise, db_session)

        zeeguu_core.log("recomputting bookmark priorities")
        BookmarkPriorityUpdater.update_bookmark_priority(
            zeeguu_core.db, flask.g.user)

        return "OK"
    except:
        traceback.print_exc()
        return "FAIL"
Esempio n. 5
0
def report_exercise_outcome(exercise_outcome, exercise_source, exercise_solving_speed, bookmark_id):
    """
    In the model parlance, an exercise is an entry in a table that
    logs the performance of an exercise. Every such performance, has a source, and an outcome.

    :param exercise_outcome: One of: Correct, Retry, Wrong, Typo, Too easy
    :param exercise_source: has been assigned to your app by zeeguu
    :param exercise_solving_speed: in milliseconds
    :param bookmark_id: the bookmark for which the data is reported
    :return:
    """

    try:
        bookmark = Bookmark.find(bookmark_id)
        new_source = ExerciseSource.find(exercise_source)
        new_outcome = ExerciseOutcome.find_or_create(db_session, exercise_outcome)

        if not bookmark:
            return "could not find bookmark"

        if not new_source:
            return "could not find source"

        if not new_outcome:
            return "could not find outcome"

        exercise = Exercise(new_outcome, new_source, exercise_solving_speed, datetime.now())
        bookmark.add_new_exercise(exercise)
        bookmark.update_fit_for_study(db_session)
        bookmark.update_learned_status(db_session)
        db_session.add(exercise)
        db_session.commit()

        # Update the exercise session
        from zeeguu_core.model import UserExerciseSession
        UserExerciseSession.update_exercise_session(exercise, db_session)

        zeeguu_core.log("recomputting bookmark priorities")
        BookmarkPriorityUpdater.update_bookmark_priority(zeeguu_core.db, flask.g.user)

        return "OK"
    except:
        traceback.print_exc()
        return "FAIL"
Esempio n. 6
0
    def test_find(self):
        bookmark_should_be = self.user.all_bookmarks()[0]
        bookmark_to_check = Bookmark.find(bookmark_should_be.id)

        assert bookmark_to_check == bookmark_should_be
Esempio n. 7
0
def unstar_bookmark(bookmark_id):
    bookmark = Bookmark.find(bookmark_id)
    bookmark.starred = False
    bookmark.update_fit_for_study()
    db_session.commit()
    return "OK"
def unstar_bookmark(bookmark_id):
    bookmark = Bookmark.find(bookmark_id)
    bookmark.starred = False
    bookmark.update_fit_for_study()
    db_session.commit()
    return "OK"
def report_learned_bookmark(bookmark_id):
    bookmark = Bookmark.find(bookmark_id)
    bookmark.learned = True
    bookmark.learned_time = datetime.datetime.now()
    db_session.commit()
    return "OK"
def delete_bookmark(bookmark_id):
    bookmark = Bookmark.find(bookmark_id)
    db_session.delete(bookmark)
    db_session.commit()
    return "OK"
Esempio n. 11
0
def similar_words_api(bookmark_id):

    bookmark = Bookmark.find(bookmark_id)
    return json_result(similar_words(bookmark, flask.g.user))