Example #1
0
 def due(self, review_time=None, order_by=None):
     # TODO: Include buried facts by default.
     due_cards = self.filter(
         due_at__isnull=False,
         due_at__lte=(review_time or datetime.utcnow()),
     )
     return with_siblings_buried(due_cards, order_by=order_by)
Example #2
0
    def _next_new_cards(
        self,
        user,
        initial_query,
        count,
        review_time,
        buried_facts,
        include_new_buried_siblings=False,
        learn_more=False,  # DEPRECATED?
        new_cards_limit=None,
        **kwargs
    ):
        from manabi.apps.flashcards.models.cards import CARD_TEMPLATE_CHOICES
        from manabi.apps.flashcards.models.facts import Fact

        count = min(count, new_cards_limit)

        if not count:
            return []

        cards = initial_query.filter(due_at__isnull=True)
        cards = cards.exclude(fact__in=buried_facts)
        cards = with_siblings_buried(cards, 'new_card_ordinal')
        cards = list(cards[:count])

        # Add spaced cards if in early review/learn more mode and we haven't
        # supplied enough.
        if (include_new_buried_siblings or learn_more) and len(cards) < count:
            buried_cards = initial_query.filter(due_at__isnull=True)
            buried_cards = buried_cards.exclude(pk__in=cards)
            buried_cards = buried_cards.order_by('new_card_ordinal')
            cards.extend(list(buried_cards[:count - len(cards)]))

        return cards
Example #3
0
    def _next_new_cards(
            self,
            initial_query,
            count,
            review_time,
            buried_facts,
            include_new_buried_siblings=False,
            learn_more=False,  # DEPRECATED?
            new_cards_limit=None,
            **kwargs):
        from manabi.apps.flashcards.models.cards import CARD_TEMPLATE_CHOICES
        from manabi.apps.flashcards.models.facts import Fact

        count = min(count, new_cards_limit)

        if not count:
            return []

        cards = initial_query.filter(due_at__isnull=True)
        cards = cards.exclude(fact__in=buried_facts)
        cards = with_siblings_buried(cards, 'new_card_ordinal')
        cards = list(cards[:count])

        # Add spaced cards if in early review/learn more mode and we haven't
        # supplied enough.
        if (include_new_buried_siblings or learn_more) and len(cards) < count:
            buried_cards = initial_query.filter(due_at__isnull=True)
            buried_cards = buried_cards.exclude(pk__in=cards)
            buried_cards = buried_cards.order_by('new_card_ordinal')
            cards.extend(list(buried_cards[:count - len(cards)]))

        return cards
Example #4
0
 def due(self, review_time=None, order_by=None):
     # TODO: Include buried facts by default.
     due_cards = self.filter(
         due_at__isnull=False,
         due_at__lte=(review_time or datetime.utcnow()),
     )
     return with_siblings_buried(due_cards, order_by=order_by)
Example #5
0
 def new_count(self, user, including_buried=True):
     '''
     Use this rather than `new(user).count()` for future-proofing.
     '''
     new_cards = self.new(user)
     if not including_buried:
         new_cards = with_siblings_buried(new_cards)
     return new_cards.count()
Example #6
0
 def new_count(self, user, including_buried=True, buried_fact_ids=None):
     '''
     Use this rather than `new(user).count()` for future-proofing.
     '''
     new_cards = self.new(user)
     if not including_buried:
         new_cards = with_siblings_buried(new_cards)
         if buried_fact_ids is None:
             buried_fact_ids = Fact.objects.buried(
                 self.user,
                 excluded_card_ids=self.excluded_card_ids,
             ).values_list('id', flat=True)
         new_cards = new_cards.exclude(fact_id__in=buried_fact_ids)
     return new_cards.count()
Example #7
0
    def new_count(self, user, including_buried=True, buried_fact_ids=None):
        '''
        Use this rather than `new(user).count()` for future-proofing.
        '''
        from manabi.apps.flashcards.models.facts import Fact

        new_cards = self.new(user)
        if not including_buried:
            new_cards = with_siblings_buried(new_cards)
            if buried_fact_ids is None:
                buried_fact_ids = Fact.objects.buried(
                    self.user, excluded_card_ids=self.excluded_card_ids,
                ).values_list('id', flat=True)
            new_cards = new_cards.exclude(fact_id__in=buried_fact_ids)
        return new_cards.count()
Example #8
0
    def _next_failed_not_due_cards(self, initial_query, count, review_time,
                                   buried_facts, **kwargs):
        '''
        Disregards fact burial status.
        '''
        if not count:
            return []

        #TODO-OLD prioritize certain failed cards, not just by due date
        # We'll show failed cards even if they've been reviewed recently.
        # This is because failed cards are set to be shown 'soon' and not
        # just in 10 minutes. Special rules.
        #TODO-OLD we shouldn't show mature failed cards so soon though!
        #TODO-OLD randomize the order (once we fix the Undo)

        cards = initial_query.failed().not_due(review_time=review_time)
        # FIXME: This is excluding the card itself. Scenario: one card in the fact; fail this card; now this card doesn't show up here due to being counted as a sibling of itself having been reviewed recently! HMMMM....
        # Maybe to fix this, add a failed-and-buried card func? I think that works.
        # For now, I'm going to ignore buried facts here instead.
        cards = with_siblings_buried(cards, 'due_at')

        return cards[:count]
Example #9
0
    def _next_failed_not_due_cards(
        self, user, initial_query, count, review_time, buried_facts,
        **kwargs
    ):
        '''
        Disregards fact burial status.
        '''
        if not count:
            return []

        #TODO-OLD prioritize certain failed cards, not just by due date
        # We'll show failed cards even if they've been reviewed recently.
        # This is because failed cards are set to be shown 'soon' and not
        # just in 10 minutes. Special rules.
        #TODO-OLD we shouldn't show mature failed cards so soon though!
        #TODO-OLD randomize the order (once we fix the Undo)

        cards = initial_query.failed().not_due(review_time=review_time)
        # FIXME: This is excluding the card itself. Scenario: one card in the fact; fail this card; now this card doesn't show up here due to being counted as a sibling of itself having been reviewed recently! HMMMM....
        # Maybe to fix this, add a failed-and-buried card func? I think that works.
        # For now, I'm going to ignore buried facts here instead.
        cards = with_siblings_buried(cards, 'due_at')

        return cards[:count]