Example #1
0
def jsoncard(request, card_id):
    """Renders JSON for a single card
    TODO: HTTP-cache these, since they're immutable
    (This is not actually used...)
    """

    model = get_model(request)
    card = Card.lookup_card(card_id)
    data = card.json()
    return HttpResponse(json.dumps(data), mimetype='text/plain')
Example #2
0
    def get_cards_for_lesson(self, lesson, model):
        """This is a mess.  
        """

        cards = []
        for concept in lesson.concepts.all():
            card = Card.lookup_card(concept.id)
            cards.append(card)

        return cards
Example #3
0
    def get_cards_for_lesson(self,lesson,model):
        """This is a mess.  
        """

        cards = []
        for concept in lesson.concepts.all():
            card = Card.lookup_card(concept.id)
            cards.append(card)
            
        return cards
Example #4
0
def jsoncard(request, card_id):
    """Renders JSON for a single card
    TODO: HTTP-cache these, since they're immutable
    (This is not actually used...)
    """

    model = get_model(request)
    card = Card.lookup_card(card_id)
    data = card.json()
    return HttpResponse(
                    json.dumps(data),
                    mimetype='text/plain'
                    )
Example #5
0
    def log_impression(self,impression):
        logging.debug("Logging impression %s" % impression)

        self.seq_tick()
        # updates model_seq - must do this now since this is when the model gets persisted
        #TODO: fix encapsulation of seq_tick.  this is handled in base class.

        card = Card.lookup_card(impression.concept_id)
        next_status = self.get_next_card_status(card,impression.answer)
        logging.debug("Moving card to %s", next_status)
        self.move_card_to_pile(card,next_status)
        self.calculate_soonest(card)
    
        card.log_impression(impression)
Example #6
0
def debug_card(request,card_id):
    card = Card.lookup_card(card_id)
    model = get_model(request)
    history = card.history()
    params = {}
    params['pile'] = model.which_pile(card)
    params['ert'] = safe_timedelta(seconds = model.get_ert(card))
    params['estimated_ert'] = safe_timedelta(model._estimate_ert(card))
    params['longest_yes'] = history.delay_on_longest_yes()
    params['most_recent_yes'] = history.delay_on_most_recent_yes()[0]
    params['how_far_back_most_recent_yes'] = history.delay_on_most_recent_yes()[1]
    params['next_exposure'] = model.next_exposure_date(card)
    params['last_exposure'] = history.lookup_last_impression()
    params['answer_history'] = history.full_impression_history(20)

    return render_to_response("deck/debug_card.html", params, 
            context_instance=RequestContext(request))
Example #7
0
    def log_impression(self, impression):
        LearningModelBase.log_impression(self, impression)

        # print u"better decklogging %s" % impression
        card = Card.lookup_card(impression.concept_id)

        # if they got it right, do nothing
        if impression.answer == "Yes":
            # TODO: if impression time was long, move it up some
            return

        if impression.answer == "Discard":
            self.move_card_to_pile(card, "Discard")
            return

        if impression.answer == "No":
            # if they got it wrong, move that card near the front of the deck
            self.move_card_to_pile(card, "Active", self.how_far_back_when_wrong())
Example #8
0
    def log_impression(self, impression):
        LearningModelBase.log_impression(self, impression)

        #print u"better decklogging %s" % impression
        card = Card.lookup_card(impression.concept_id)

        # if they got it right, do nothing
        if impression.answer == "Yes":
            #TODO: if impression time was long, move it up some
            return

        if impression.answer == "Discard":
            self.move_card_to_pile(card, 'Discard')
            return

        if impression.answer == "No":
            # if they got it wrong, move that card near the front of the deck
            self.move_card_to_pile(card, 'Active',
                                   self.how_far_back_when_wrong())
Example #9
0
    def add_new_cards(self, describe_new_cards, card_id_list, pile=None):
        """Add a whole list of cards to the pile.
        Defaults to the get_default_new_pile() pile.
        Also requires a string describing the new cards.
        """

        # add to the description if there is one
        if self.description != "":
            self.description += ", "
            self.description += describe_new_cards
        else:
            self.description = describe_new_cards

        # figure out which pile to put them in
        if pile is None:
            pile = self.get_default_new_pile()

        # put them into the pile
        for id in card_id_list:
            card = Card.lookup_card(id)
            self._add_new_card(card, pile)
Example #10
0
    def log_impression(self,impression):
        logging.debug(u"Logging impression %s" % impression)

        card = Card.lookup_card(impression.concept_id)
        card.log_impression(impression)
        self.seq_tick()

        history = card.history()
        previous_impression = history.lookup_earlier_impression(1)
        # If they don't differ we need to muck with the code.
        if previous_impression:
            current_delay = td_to_seconds(impression.answered_date - previous_impression.answered_date)
        else:
            current_delay = None
        logging.debug(u"Current delay is %s" % current_delay) # This might not work.
        current_answer = impression.answer
        if impression.answer == 'Discard':
            self.move_card_to_pile(card,'Discard')
        else:
            self.evaluate_card(card,current_delay,impression.answer)
            self.move_card_to_pile(card,'Learning')  # We're always learning all these.
Example #11
0
    def add_new_cards(self, describe_new_cards, card_id_list, pile=None):
        """Add a whole list of cards to the pile.
        Defaults to the get_default_new_pile() pile.
        Also requires a string describing the new cards.
        """

        # add to the description if there is one
        if self.description != "":
            self.description += ", "
            self.description += describe_new_cards
        else:
            self.description = describe_new_cards

        # figure out which pile to put them in
        if pile is None:
            pile = self.get_default_new_pile()

        # put them into the pile
        for id in card_id_list:
            card = Card.lookup_card(id)
            self._add_new_card(card, pile)
Example #12
0
def show_meta(request):
    # first, fetch the recent impressions
    recent_impressions = Impression.objects.order_by('-answered_date').filter(user=request.user)
    # limit to last 30 impressions
    recent_impressions = recent_impressions[0:29]

    # now build a list of card Q's, with the pile for each card. 
    # don't eliminate duplicate cards
    model = get_model(request)
    recent_cards = []
    for impression in recent_impressions:
        #print "id %s" % impression.concept.id
        card = Card.lookup_card(impression.concept.id)

        pile = model.which_pile(card)
        ert = model._get_card_metadata(card,'ert')  #TODO: Not portable!
        logging.debug("ert for %s is %s" % (card,ert))
        if ert:
            next_exposure = impression.answered_date + datetime.timedelta(seconds = ert)
        else:
            next_exposure = None
        recent_cards.append( (card.question(), pile, card, ert, next_exposure) )

    #
    # fetch counts for each pile
    #
    pilecount = []
    for pile in model.supported_piles():
        pilecount.append( (pile, len( model.cards_in_pile(pile) ) ) )

    # and the description
    description = model.description

    templatevars = {
        'recent_cards': recent_cards,
        'pilecount': pilecount,
        'description': description,
        }

    return render_to_response("deck/show_meta.html", templatevars)
Example #13
0
def deckview(request):
    """Shows you a list of recent cards.
    """

    # first, fetch the recent impressions
    recent_impressions = Impression.objects.order_by('-answered_date').filter(user=request.user)
    # limit to last 30 impressions
    recent_impressions = recent_impressions[0:29]

    # now build a list of card Q's, with the pile for each card. 
    # don't eliminate duplicate cards
    model = get_model(request)
    recent_cards = []
    for impression in recent_impressions:
        #print "id %s" % impression.concept.id
        card = Card.lookup_card(impression.concept.id)

        pile = model.which_pile(card)
        recent_cards.append( (card.question(), pile, card) )

    #
    # fetch counts for each pile
    #
    pilecount = []
    for pile in model.supported_piles():
        pilecount.append( (pile, len( model.cards_in_pile(pile) ) ) )

    # and the description
    description = model.description

    templatevars = {
        'recent_cards': recent_cards,
        'pilecount': pilecount,
        'description': description,
        }

    return render_to_response("deck/deckview.html", templatevars)
Example #14
0
    def log_impression(self, impression):
        logging.debug(u"Logging impression %s" % impression)

        card = Card.lookup_card(impression.concept_id)
        card.log_impression(impression)
        self.seq_tick()

        history = card.history()
        previous_impression = history.lookup_earlier_impression(1)
        # If they don't differ we need to muck with the code.
        if previous_impression:
            current_delay = td_to_seconds(impression.answered_date -
                                          previous_impression.answered_date)
        else:
            current_delay = None
        logging.debug(u"Current delay is %s" %
                      current_delay)  # This might not work.
        current_answer = impression.answer
        if impression.answer == 'Discard':
            self.move_card_to_pile(card, 'Discard')
        else:
            self.evaluate_card(card, current_delay, impression.answer)
            self.move_card_to_pile(
                card, 'Learning')  # We're always learning all these.
Example #15
0
    def log_impression(self, impression):
        LearningModelBase.log_impression(self, impression)

        # here we need to actually rotate the card to the back.
        card = Card.lookup_card(impression.concept_id)
        self.move_card_to_pile(card, 'Active')
Example #16
0
    def log_impression(self, impression):
        LearningModelBase.log_impression(self, impression)

        # here we need to actually rotate the card to the back.
        card = Card.lookup_card(impression.concept_id)
        self.move_card_to_pile(card, "Active")