Beispiel #1
0
        public void IncrementProgressOfOriginalWord_True()
        {
            //Arrange
            int    wordSuiteId  = 5;
            string originalWord = "test";

            Word _word = new Word()
            {
                Value = "test"
            };

            WordTranslation _wordTranslation = new WordTranslation()
            {
                OriginalWordId = 2,
                OriginalWord   = _word,
            };

            WordProgress _wordProgress = new WordProgress()
            {
                IsStudentWord     = false,
                WordTranslationId = 2,
                Progress          = 4,
                WordSuite         = null,
                WordSuiteId       = 5,
                WordTranslation   = _wordTranslation
            };
            IQueryable <WordProgress> _queryable = new List <WordProgress>
            {
                _wordProgress
            }.AsQueryable();

            _uow.Setup(u => u.WordProgressRepository).Returns(_progressRepository.Object);
            _progressRepository.Setup(p => p.GetAll()).Returns(_queryable);
            _progressRepository.Setup(p => p.AddOrUpdate(_wordProgress));
            _uow.Setup(u => u.Save()).Verifiable();

            //Act
            bool result = new WordProgressService(_factory.Object).IncrementProgressOfOriginalWord(wordSuiteId, originalWord);

            //Assert
            _factory.Verify(f => f.GetUnitOfWork(), Times.Once);
            _uow.Verify(u => u.WordProgressRepository, Times.Exactly(2));
            _progressRepository.Verify(p => p.GetAll(), Times.Exactly(1));
            _progressRepository.Verify(p => p.AddOrUpdate(_wordProgress), Times.Exactly(1));
            _uow.Verify(u => u.Save(), Times.Once);
            _uow.VerifyAll();
            Assert.IsTrue(result);
        }
Beispiel #2
0
    /**
     * Number of days later than scheduled.
     * only for reviewing, not just learned few minute ago
     */
    private int daysLate(WordProgress wordProgress)
    {
        int queue = wordProgress.queue;

        if (queue != CommonDefine.QUEUE_REVIEW)
        {
            return(0);
        }

        int due = wordProgress.due;
        int now = DateTimeHelper.getCurrentDateTimeInSeconds();            //have to get exactly date time in sec

        int diff_day = (int)(now - due) / CommonDefine.SECONDS_PERDAY;

        return(Mathf.Max(0, diff_day));
    }
Beispiel #3
0
 public bool IsStudentWord(WordProgress wordProgress)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         return(uow
                .WordProgressRepository.GetAll()
                .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId &&
                        wp.WordTranslationId == wordProgress.WordTranslationId).IsStudentWord);
     }
     //using (var context = new WorldOfWordsDatabaseContext())
     //{
     //    return context
     //            .WordProgresses
     //            .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId &&
     //                          wp.WordTranslationId == wordProgress.WordTranslationId).IsStudentWord;
     //}
 }
Beispiel #4
0
 public bool RemoveByStudent(WordProgress wordProgress)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         if (IsStudentWord(wordProgress))
         {
             uow
             .WordProgressRepository
             .Delete(uow
                     .WordProgressRepository.GetAll()
                     .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId &&
                             wp.WordTranslationId == wordProgress.WordTranslationId));
             uow.Save();
             return(true);
         }
         return(false);
     }
 }
Beispiel #5
0
 public bool RemoveByStudent(WordProgress wordProgress)
 {
     using (var context = new WorldOfWordsDatabaseContext())
     {
         if (IsStudentWord(wordProgress))
         {
             context
             .WordProgresses
             .Remove(context
                     .WordProgresses
                     .Single(wp => wp.WordSuiteId == wordProgress.WordSuiteId &&
                             wp.WordTranslationId == wordProgress.WordTranslationId));
             context.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
        // mfomitc
        public async Task <bool> CopyWordsuitesForTeacherByIdAsync(int teacherId, int wordSuiteId)
        {
            using (var uow = _unitOfWorkFactory.GetUnitOfWork())
            {
                WordSuite wordSuite = await uow.WordSuiteRepository.GetByIdAsync(wordSuiteId);

                if (wordSuite == null)
                {
                    throw new ArgumentException("Word Suite with id you are requesting does not exist");
                }
                User teacherWhoShare = await uow.UserRepository.GetByIdAsync(wordSuite.OwnerId);

                List <WordProgress> wordProgresses = await uow.WordProgressRepository.GetAll().Where(t => t.WordSuiteId == wordSuiteId).ToListAsync();

                WordSuite wordSuiteToCopy = new WordSuite
                {
                    Name             = wordSuite.Name + "_(Shared_by_" + teacherWhoShare.Name + ")",
                    LanguageId       = wordSuite.LanguageId,
                    Threshold        = wordSuite.Threshold,
                    QuizResponseTime = wordSuite.QuizResponseTime,
                    QuizStartTime    = wordSuite.QuizStartTime,
                    OwnerId          = teacherId,
                    PrototypeId      = null
                };
                List <WordTranslation> wordTranslationsToCopy = new List <WordTranslation>();
                foreach (var wordProgress in wordProgresses)
                {
                    wordTranslationsToCopy.Add(wordProgress.WordTranslation);
                }
                List <WordProgress> WordProgressList = new List <WordProgress>();
                foreach (var wordTranslation in wordTranslationsToCopy)
                {
                    WordProgress wordProgress = new WordProgress {
                        WordSuite = wordSuiteToCopy, WordTranslation = wordTranslation
                    };
                    WordProgressList.Add(wordProgress);
                }
                uow.WordSuiteRepository.Add(wordSuiteToCopy);
                uow.WordProgressRepository.Add(WordProgressList);
                await uow.SaveAsync();

                return(true);
            }
        }
        public void RemoveRange_True()
        {
            //Arrange
            var _wordProgressRange = new List <WordProgress>()
            {
                new WordProgress()
                {
                    WordSuiteId       = 7,
                    WordTranslationId = 8
                },
                new WordProgress()
                {
                    WordSuiteId       = 7,
                    WordTranslationId = 8
                }
            };
            var _wordProgress = new WordProgress()
            {
                WordSuiteId       = 7,
                WordTranslationId = 8
            };
            IQueryable <WordProgress> _queryable = new List <WordProgress>
            {
                _wordProgress
            }.AsQueryable();

            _uow.Setup(u => u.WordProgressRepository).Returns(_progressRepository.Object);
            _progressRepository.Setup(p => p.Delete(It.IsAny <WordProgress>()));
            _progressRepository.Setup(p => p.GetAll()).Returns(_queryable);
            _uow.Setup(u => u.Save());
            var _service = new WordProgressService(_factory.Object);

            //Act
            var result = _service.RemoveRange(_wordProgressRange);

            //Assert
            _factory.Verify(f => f.GetUnitOfWork(), Times.Once);
            _uow.Verify(u => u.WordProgressRepository, Times.Exactly(4));
            _progressRepository.Verify(p => p.Delete(It.IsAny <WordProgress>()), Times.Exactly(2));
            _progressRepository.Verify(p => p.GetAll(), Times.Exactly(2));
            _uow.Verify(u => u.Save(), Times.Once);
            Assert.IsTrue(result, "true");
        }
Beispiel #8
0
    /**
     * Whenever a Card is answered, call this function on Card.
     * Scheduler will update the following parameters into Card's instance:
     * <ul>
     * <li>due
     * <li>last_ivl
     * <li>queue
     * <li>e_factor
     * <li>rev_count
     * </ul>
     * After 'answerCard', the caller will check Card's data for further decisions
     * (update database or/and put it back to app's queue)
     */
    public void updateWordProgressWithEaseOption(ref WordProgress wordProgress, int easeOption)
    {
        int nextIvl = nextIntervalBySecondsWithEaseOption(wordProgress, easeOption);
        int current = DateTimeHelper.getCurrentDateTimeInSeconds();             //have to get exactly date time in seconds

        //Now we decrease for EASE_AGAIN only when it from review queue
        int queue   = wordProgress.queue;
        int eFactor = wordProgress.e_fact;

        if (queue == CommonDefine.QUEUE_REVIEW && easeOption == CommonDefine.OPTION_AGAIN)
        {
            eFactor             = wordProgress.e_fact - CommonDefine.FORGET_FINE;
            wordProgress.e_fact = eFactor;
        }
        else
        {
            eFactor             = Mathf.Max(CommonDefine.MIN_FACTOR, (wordProgress.e_fact + factorAdditionValue(easeOption)));
            wordProgress.e_fact = eFactor;
        }

        if (nextIvl < CommonDefine.SECONDS_PERDAY)
        {
            /*User forget card or just learn
             * We don't re-count 'due', because app will put it back to learned queue
             */
            wordProgress.queue = CommonDefine.QUEUE_AGAIN;

            //Reset last-interval to reduce next review
            wordProgress.last_ivl = 0;
        }
        else
        {
            wordProgress.queue    = CommonDefine.QUEUE_REVIEW;
            wordProgress.due      = current + nextIvl;
            wordProgress.last_ivl = nextIntervalByDaysWithEaseOption(wordProgress, easeOption);
        }
    }
Beispiel #9
0
 public UserLearning()
 {
     wordInfo     = null;
     wordProgress = null;
 }