Exemple #1
0
def judge(db_conn, unit, user):
    """
    Given a unit and a user, pass judgement on which bucket to file it under.
    """

    response = get_latest_response(user['id'], unit['entity_id'], db_conn)
    if response:
        learned = response['learned']
        now = time()
        time_delta = now - (int(response['created'].strftime("%s"))
                            if response else now)
        belief = calculate_belief(learned, time_delta)
    else:
        learned = 0
        belief = 0

    if learned >= max_learned:
        if belief > max_belief:
            return "done"

        if belief <= max_belief:
            return "review"

    if belief > diag_belief:
        return "learn"

    return "diagnose"
Exemple #2
0
def judge(db_conn, unit, user):
    """
    Given a unit and a user, pass judgement on which bucket to file it under.
    """

    response = Response.get_latest(
        db_conn,
        user_id=user['id'],
        unit_id=unit['entity_id']
    )
    if response:
        learned = response['learned']
        now = time()
        time_delta = now - (int(response['created'].strftime("%s"))
                            if response else now)
        belief = calculate_belief(learned, time_delta)
    else:
        learned = 0
        belief = 0

    if learned >= max_learned:
        if belief > max_belief:
            return "done"

        if belief <= max_belief:
            return "review"

    if belief > diag_belief:
        return "learn"

    return "diagnose"
Exemple #3
0
def test_calculate_belief():
    assert calculate_belief(0.5, 60) > 0.99
    assert calculate_belief(0.5, 60 * 60) > 0.99
    assert calculate_belief(0.5, 60 * 60 * 24) > 0.94
    assert calculate_belief(0.5, 60 * 60 * 24 * 7) > 0.65
    assert calculate_belief(0.9, 60 * 60 * 24 * 7) > 0.91
    assert calculate_belief(0.99, 60 * 60 * 24 * 7) > 0.99
    assert calculate_belief(0.5, 60 * 60 * 24 * 365) < 0.01