예제 #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:
    """

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

        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)
        zeeguu.db.session.add(exercise)
        zeeguu.db.session.commit()

        from zeeguu.language.knowledge_estimator import update_probabilities_for_word
        update_probabilities_for_word(bookmark.origin)
        return "OK"
    except :
        traceback.print_exc()
        return "FAIL"
예제 #2
0
def create_new_exercise(exercise_outcome, exercise_source,
                        exercise_solving_speed, bookmark_id):
    """
    OBSOLETE!
    Use the /report_exercise_outcome/... API endpoint

    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:
    :param exercise_source:
    :param exercise_solving_speed:
    :param bookmark_id:
    :return:
    """

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

        if not new_source or not new_outcome:
            return "FAIL"

        exercise = Exercise(new_outcome, new_source, exercise_solving_speed,
                            datetime.datetime.now())
        bookmark.add_new_exercise(exercise)
        zeeguu.db.session.add(exercise)
        zeeguu.db.session.commit()

        update_probabilities_for_word(bookmark.origin)
        return "OK"
    except:
        return "FAIL"
예제 #3
0
def create_minimal_test_db(db):
    drop_current_tables(db)

    # Some common test fixtures
    de = Language("de", "German")
    en = Language("en", "English")
    nl = Language("nl", "Dutch")
    es = Language("es", "Spanish")
    fr = Language("fr", "French")

    db.session.add_all([en, de, nl, es, fr])

    mir = User(TEST_EMAIL, "Mircea", TEST_PASS, de, en)

    db.session.add(mir)

    show_solution = ExerciseOutcome("Show solution")
    retry = ExerciseOutcome("Retry")
    correct = ExerciseOutcome("Correct")
    wrong = ExerciseOutcome("Wrong")
    typo = ExerciseOutcome("Typo")
    too_easy = ExerciseOutcome("Too easy")

    outcomes = [show_solution, retry, correct, wrong, typo, too_easy]

    db.session.add_all(outcomes)

    recognize = ExerciseSource("Recognize")
    translate = ExerciseSource("Translate")

    sources = [recognize, translate]

    db.session.add_all(sources)

    b1 = add_bookmark(db, mir, de, "Schaf", en, "sheep",
                      datetime.datetime(2011, 1, 1, 1, 1,
                                        1), "Bitte... zeichne mir ein Schaf!",
                      "http://www.derkleineprinz-online.de/text/2-kapitel/",
                      "Der Kleine Prinz - Kapitel 2")

    b2 = add_bookmark(db, mir, de, "sprang", en, "jumped",
                      datetime.datetime(2011, 1, 1, 1, 1,
                                        1), "Ich sprang auf die Fusse.",
                      "http://www.derkleineprinz-online.de/text/2-kapitel/",
                      "Der Kleine Prinz - Kapitel 2")

    bookmarks = [b1, b2]

    for i in range(0, 5):
        random_source = sources[random.randint(0, len(sources) - 1)]
        random_outcome = outcomes[random.randint(0, len(outcomes) - 1)]
        random_solving_speed = random.randint(500, 5000)
        exercise = Exercise(random_outcome, random_source,
                            random_solving_speed, datetime.datetime.now())
        random_bookmark = bookmarks[random.randint(0, len(bookmarks) - 1)]
        random_bookmark.add_new_exercise(exercise)

    global TEST_BOOKMARKS_COUNT
    TEST_BOOKMARKS_COUNT = 2
    db.session.commit()
예제 #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_by_source(exercise_source)
        new_outcome = ExerciseOutcome.find(exercise_outcome)

        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)
        zeeguu.db.session.add(exercise)
        zeeguu.db.session.commit()

        from zeeguu.language.knowledge_estimator import update_probabilities_for_word
        update_probabilities_for_word(bookmark.origin)
        return "OK"
    except:
        traceback.print_exc()
        return "FAIL"
예제 #5
0
    def __create_new_outcome(cls, outcome):
        new_outcome = ExerciseOutcome(outcome)

        cls.save(new_outcome)

        return new_outcome
예제 #6
0
 def __get_or_create_outcome(cls, outcome):
     try:
         return ExerciseOutcome.find(outcome)
     except NoResultFound:
         return cls.__create_new_outcome(outcome)
예제 #7
0
def create_test_db(db):
    drop_current_tables(db)

    de = Language("de", "German")
    da = Language("da", "Danish")
    en = Language("en", "English")
    es = Language("es", "Spanish")
    fr = Language("fr", "French")
    it = Language("it", "Italian")
    no = Language("no", "Norwegian")
    nl = Language("nl", "Dutch")
    pt = Language("pt", "Portughese")
    ro = Language("ro", "Romanian")

    db.session.add(de)
    db.session.add(da)
    db.session.add(en)
    db.session.add(es)
    db.session.add(fr)
    db.session.add(it)
    db.session.add(no)
    db.session.add(nl)
    db.session.add(pt)
    db.session.add(ro)
    db.session.commit()

    show_solution = ExerciseOutcome("Show solution")
    retry = ExerciseOutcome("Retry")
    correct = ExerciseOutcome("Correct")
    wrong = ExerciseOutcome("Wrong")
    typo = ExerciseOutcome("Typo")
    too_easy = ExerciseOutcome("Too easy")

    recognize = ExerciseSource("Recognize")
    translate = ExerciseSource("Translate")
    zeekoe = ExerciseSource("ZeeKoe")

    db.session.add(show_solution)
    db.session.add(retry)
    db.session.add(correct)
    db.session.add(wrong)
    db.session.add(typo)
    db.session.add(too_easy)

    db.session.add(recognize)
    db.session.add(translate)
    db.session.add(zeekoe)

    user = User(TEST_EMAIL, "Mircea", TEST_PASS, de, ro)
    user2 = User("*****@*****.**", "Ada", "pass", fr)

    db.session.add(user)
    db.session.add(user2)

    jan111 = datetime.datetime(2011, 0o1, 0o1, 0o1, 0o1, 0o1)
    ian101 = datetime.datetime(2001, 0o1, 0o1, 0o1, 0o1, 0o1)
    jan14 = datetime.datetime(2014, 1, 14, 0o1, 0o1, 0o1)

    today_dict = {
        'sogar': 'actually',
        'sperren': 'to lock, to close',
        'Gitter': 'grates',
        'erfahren': 'to experience',
        'treffen': 'hit',
        'jeweils': 'always',
        'Darstellung': 'presentation',
        'Vertreter': 'representative',
        'Knecht': 'servant',
        'der': 'the'
    }

    dict = {
        'Spaß': 'fun',
        'solche': 'suchlike',
        'ehemaliger': 'ex',
        'betroffen': 'affected',
        'Ufer': 'shore',
        'höchstens': 'at most'
    }

    french_dict = {'jambes': 'legs', 'de': 'of', 'et': 'and'}

    story_url = 'http://www.gutenberg.org/files/23393/23393-h/23393-h.htm'
    japanese_story = [
        # ['recht', 'right', 'Du hast recht', story_url],
        [
            'Holzhauer', 'wood choppers',
            'Da waren einmal zwei Holzhauer können', story_url
        ],
        ['Da', 'there', 'Da waren einmal zwei Holzhauer können', story_url],
        ['zwei', 'two', 'Da waren einmal zwei Holzhauer können', story_url],
        [
            'Wald', 'to arrive',
            'Um in den Walden zu gelangen, mußten sie einen großen Fluß passieren. Um in den Walden zu gelangen, mußten sie einen großen Fluß passieren. Um in den Walden zu gelangen, mußten sie einen großen Fluß passieren. Um in den Walden zu gelangen, mußten sie einen großen Fluß passieren',
            story_url
        ],
        [
            'eingerichtet', 'established',
            'Um in den Wald zu gelangen, mußten sie einen großen Fluß passieren, über den eine Fähre eingerichtet war',
            story_url
        ],
        [
            'vorläufig', 'temporary',
            'von der er des rasenden Sturmes wegen vorläufig nicht zurück konnte',
            story_url
        ],
        [
            'werfen', 'to throw',
            'Im Hause angekommen, warfen sie sich zur Erde,', story_url
        ],
        [
            'Tosen', 'roar',
            'sie Tür und Fenster wohl verwahrt hatten und lauschten dem Tosen des Sturmes.sie Tür und Fenster wohl verwahrt hatten und lauschten dem Tosen des Sturmes.sie Tür und Fenster wohl verwahrt hatten und lauschten dem Tosen des Sturmes',
            story_url
        ],
        [
            'Entsetzen', 'horror', 'Entsetzt starrte Teramichi auf die Wolke',
            story_url
        ]
    ]

    for key in today_dict:
        add_bookmark(
            db, user, de, key, en, today_dict[key], jan111,
            "Keine bank durfe auf immunitat pochen, nur weil sie eine besonders herausgehobene bedeutung fur das finanzsystem habe, sagte holder, ohne namen von banken zu nennen",
            "http://url2", "title of url2")

    for key in dict:
        add_bookmark(
            db, user, de, key, en, dict[key], ian101,
            "Deutlich uber dem medianlohn liegen beispielsweise forschung und entwicklung, tabakverarbeitung, pharma oder bankenwesen, am unteren ende der skala liegen die tieflohnbranchen detailhandel, gastronomie oder personliche dienstleistungen. ",
            "http://url1", "title of url1")

    for key in french_dict:
        add_bookmark(
            db, user, de, key, en, french_dict[key], ian101,
            "Deutlich uber dem medianlohn liegen beispielsweise forschung und entwicklung, tabakverarbeitung, pharma oder bankenwesen, am unteren ende der skala liegen die tieflohnbranchen detailhandel, gastronomie oder personliche dienstleistungen. ",
            "http://url1", "title of url1")
    for w in japanese_story:
        add_bookmark(db, user, de, w[0], en, w[1], jan14, w[2], w[3],
                     "japanese story")

    db.session.commit()