コード例 #1
0
        public Card Generate(Card card)
        {
            card.Id           = TimeGenerator.RandomId(CardIds);
            card.LastModified = Math.Max(card.Id, TimeGenerator.RandomTime());

            bool          lapsing;
            PracticeState state;

            ComputeNextCardType(out state, out lapsing);

            switch (state)
            {
            case PracticeState.Due:
                DueCount--;
                return(SetupDueCard(card, lapsing));

            case PracticeState.Learning:
                LearnCount--;
                return(SetupLearningCard(card, lapsing));

            case PracticeState.New:
                NewCount--;
                return(SetupNewCard(card));
            }

            throw new InvalidOperationException();
        }
コード例 #2
0
        private Card SetupLearningCard(Card card, bool lapsing)
        {
            card.PracticeState = PracticeState.Learning;
            card.Due           = TimeGenerator.RandomTime(card.LearningOrLapsingSteps.Last());

            if (lapsing)
            {
                SetupLapse(card);
                SetupSpacedRepetitionDatas(card);
            }

            return(card);
        }
コード例 #3
0
        private Card SetupDueCard(Card card, bool lapsing)
        {
            card.PracticeState = PracticeState.Due;
            card.Due           = Math.Max(card.Id, TimeGenerator.RandomTime());

            if (lapsing)
            {
                SetupLapse(card);
            }

            SetupSpacedRepetitionDatas(card);

            return(card);
        }
コード例 #4
0
        //
        // Constructor

        public CardGenerator(TimeGenerator timeGenerator, CollectionConfig config, int count = 100, float newRatio = 3, float learnRatio = 2, float dueRatio = 5, float lapsePercent = 10)
        {
            TimeGenerator = timeGenerator;
            Config        = config;

            float totalRatio = newRatio + learnRatio + dueRatio;

            NewCount   = (int)(newRatio / totalRatio * count);
            LearnCount = (int)(learnRatio / totalRatio * count);
            DueCount   = count - NewCount - LearnCount;
            LapseCount = (int)Math.Min(
                lapsePercent / 100.0f * (DueCount + LearnCount),
                DueCount + LearnCount);

            CardIds = new HashSet <int>();
        }