Example #1
0
def impression(request):
    """Logs that the user had an impression of a card.
    This is called frequently by the studyui.
    Turns user action into an Impression object.
    """

    # For testing slow/unreliable server...
    #time.sleep(3)

    # put this into a database table...
    i = Impression()
    #print request.POST
    i.answer = request.POST['answer']
    i.concept_id = long(request.POST['id'])
    i.user = request.user
    i.timer_show = request.POST.get('showtimer')
    i.timer_submit = request.POST.get('submittimer')
    i.save()

    #print "times: %s,%s ms" % (request.POST['showtime'], request.POST['submittime'])

    # tell the learning model about the impression
    model = get_model(request)
    concept = model.log_impression(i)
    save_model(request, model)

    # return a simple HTTP response
    return HttpResponse("OK", mimetype='text/plain')
Example #2
0
def impression(request):
    """Logs that the user had an impression of a card.
    This is called frequently by the studyui.
    Turns user action into an Impression object.
    """

    # For testing slow/unreliable server...
    #time.sleep(3)

    # put this into a database table...
    i = Impression()
    #print request.POST
    i.answer = request.POST['answer']
    i.concept_id = long(request.POST['id'])
    i.user = request.user
    i.timer_show = request.POST.get('showtimer')
    i.timer_submit = request.POST.get('submittimer')
    i.save()

    #print "times: %s,%s ms" % (request.POST['showtime'], request.POST['submittime'])

    # tell the learning model about the impression
    model = get_model(request)
    concept = model.log_impression(i)
    save_model(request, model)

    # return a simple HTTP response
    return HttpResponse("OK", mimetype='text/plain')
Example #3
0
def resetdeck(request):
    """Creates a new model object and saves it.
    This wipes out anything in the previous model.
    """
    # This is the single method which determines what kind of model will be used.

    #TODO: make this configurable
    #model = RandomLearningModel()
    #model = BetterDeckModel()
    #model = HistoryModel()
    model = ActiveModel()
    save_model(request, model)
    return HttpResponseRedirect("/")
Example #4
0
def setlesson(request,lesson_id):
    """Adds this lesson to the active deck.
    """

    # put this lesson into the model
    model = get_model(request)
    if model is None:
        resetdeck(request)
        model = get_model(request)
    model.set_active_lesson(lesson_id)
    save_model(request, model)

    # send them off to study
    return HttpResponseRedirect("/study/")
Example #5
0
def setlesson(request, lesson_id):
    """Adds this lesson to the active deck.
    """

    # put this lesson into the model
    model = get_model(request)
    if model is None:
        resetdeck(request)
        model = get_model(request)
    model.set_active_lesson(lesson_id)
    save_model(request, model)

    # send them off to study
    return HttpResponseRedirect("/study/")
Example #6
0
def create_review_deck(request):
    """ Creates a deck forreviewing old material.
    Wipes out the current deck 
    """

    # start over with a new model
    resetdeck(request)
    model = get_model(request)

    # Fetch a bunch of impressions
    all_no = Impression.objects.filter(user=request.user, answer="No")
    all_kinda = Impression.objects.filter(user=request.user, answer="Kinda")

    # add up the bad impressions
    bad_total = {}
    for impression in all_kinda:
        id = impression.concept_id
        # TUNE: 1 point per kinda
        if id not in bad_total:
            bad_total[ impression.concept_id ] = 1
        else:
            bad_total[ impression.concept_id ] += 1
    for impression in all_no:
        id = impression.concept_id
        # TUNE: 3 points per no
        if id not in bad_total:
            bad_total[ impression.concept_id ] = 3
        else:
            bad_total[ impression.concept_id ] += 3

    # invert the map so it maps # bad points to concepts.
    # Note there could be collisions here, so build a list for each num pts
    inverted_bad_total = {}
    for id, pts in bad_total.items():
        # TUNE: Minimum threshhold for something to be reviewable
        if pts > 2:
            if pts not in inverted_bad_total:
                inverted_bad_total[pts]=[id]
            else:
                inverted_bad_total[pts].append(id)
    
    # Prepare results list
    review_cards = []

    # Now we put together our list of cards, in order of badness
    #print "ibt: %s" % inverted_bad_total
    pts_order_desc = inverted_bad_total.keys()
    pts_order_desc.reverse()
    #print "pod: %s" % pts_order_desc
    for pts in pts_order_desc:
        for card in inverted_bad_total[pts]:
            review_cards.append(card)
        
    # Now put them all into the model
    model.add_new_cards("Review of difficult cards", review_cards)

    # Write the model back
    save_model(request,model)

    # redirect to a standard deck view
    return HttpResponseRedirect("/deck/")