Ejemplo n.º 1
0
        private ReviewCollectionAsyncBase GetNextCardSource()
        {
            int newReviewCount   = ReviewCollectionNew.ReviewCount();
            int learnReviewCount = ReviewCollectionLearn.ReviewCount();
            int dueReviewCount   = ReviewCollectionDue.ReviewCount();

            int totalReviewCount = newReviewCount + learnReviewCount + dueReviewCount;

            int rnd = _random.Next(0, totalReviewCount);

            if (rnd < newReviewCount)
            {
                return(ReviewCollectionNew);
            }

            if (rnd < newReviewCount + learnReviewCount)
            {
                return(ReviewCollectionLearn);
            }

            if (rnd < newReviewCount + learnReviewCount + dueReviewCount)
            {
                return(ReviewCollectionDue);
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>State-dependent counts of cards to be reviewed.</summary>
        /// <param name="state">The state.</param>
        /// <returns>State-dependent card count.</returns>
        public int CountByState(CardPracticeStateFilterFlag state)
        {
            int ret = 0;

            if ((state & CardPracticeStateFilterFlag.Due) == CardPracticeStateFilterFlag.Due)
            {
                ret += ReviewCollectionDue.ReviewCount();
            }

            if ((state & CardPracticeStateFilterFlag.Learning) == CardPracticeStateFilterFlag.Learning)
            {
                ret += ReviewCollectionLearn.ReviewCount();
            }

            if ((state & CardPracticeStateFilterFlag.New) == CardPracticeStateFilterFlag.New)
            {
                ret += ReviewCollectionNew.ReviewCount();
            }

            return(ret);
        }
Ejemplo n.º 3
0
        /// <summary>Answer current card and fetch next one.</summary>
        /// <param name="grade">Answer grade</param>
        /// <returns>Whether any cards are available</returns>
        /// <exception cref="System.InvalidOperationException">No card available (Current is null).</exception>
        public Task <bool> AnswerAsync(Grade grade)
        {
            // Card sanity check
            Card card = Current;

            if (card == null)
            {
                throw new InvalidOperationException("Card unavailable");
            }

            // Compute evaluation time & create review log
            ReviewLog log = CreateLog(card);

            // Answer
            NextAction[CurrentList] = () => CurrentList.MoveNextAsync();
            CurrentList             = null;

            CardAction cardAction = card.Answer(grade);

            // Complete log with updated values
            CompleteLog(log, card, grade);

            // If this was a new card, add to learning list
            if (log.LastState == PracticeState.New)
            {
                ReviewCollectionLearn.AddManual(card);
            }

#pragma warning disable 4014
            // Save changes to Database
            UpdateCardAsync(log, card, cardAction);
#pragma warning restore 4014

            ReviewCollectionNew.DismissSiblings(card);
            ReviewCollectionLearn.DismissSiblings(card);
            ReviewCollectionDue.DismissSiblings(card);

            return(DoNextAsync());
        }
Ejemplo n.º 4
0
        private async Task <bool> InitializeAsync(CollectionConfig config)
        {
            _cardTableName =
                (await _db.GetTableMappingAsync <Card>().ConfigureAwait(false)).GetTableName();

            ReviewSession reviewSession =
                await ReviewSession.ComputeSessionAsync(_db, config).ConfigureAwait(false);

            ReviewCollectionNew   = new ReviewCollectionNew(_db, config, reviewSession.New);
            ReviewCollectionLearn = new ReviewCollectionLearn(_db);
            ReviewCollectionDue   = new ReviewCollectionDue(_db, reviewSession.Due);

            NextAction[ReviewCollectionNew]   = () => ReviewCollectionNew.MoveNextAsync();
            NextAction[ReviewCollectionLearn] = () => ReviewCollectionLearn.MoveNextAsync();
            NextAction[ReviewCollectionDue]   = () => ReviewCollectionDue.MoveNextAsync();

            await
            Task.WhenAll(
                ReviewCollectionNew.IsInitializedAsync(), ReviewCollectionLearn.IsInitializedAsync(),
                ReviewCollectionDue.IsInitializedAsync()).ConfigureAwait(false);

            return(await DoNextAsync().ConfigureAwait(false));
        }