Exemple #1
0
 private static Card UpdateCard(Card card, Score score)
 {
     card.LastTrainingDate = DateTime.UtcNow;
     card.Score = score;
     card.NumberOfRepetitions++;
     //If None - return interval
     if (score == Score.None)
     {
         return ResetCard(card);
     }
     //If first or second time - return interval
     if (card.NumberOfRepetitions == 1)
     {
         card.LastInterval = FirstInterval;
     }
     else if (card.NumberOfRepetitions == 2)
     {
         card.LastInterval = SecondInterval;
     }
     else
     {
         //Calculate new EF
         card.EFactor = CalculateNextEFactor(card.EFactor, score);
         //Calculate and return new interval
         card.LastInterval = CalculateNextInterval(card.LastInterval, card.EFactor);
     }
     card.NextDate = DateTime.UtcNow.Date.AddDays(card.LastInterval);
     return card;
 }
Exemple #2
0
 public void UpdateCard(Card card, string ownerID)
 {
     if (card.Owner.Id == ownerID)
     {
         cardRepo.Update(card);
     }
 }
Exemple #3
0
 private static Card ResetCard(Card card)
 {
     card.EFactor = 2.5;
     card.NumberOfRepetitions = 0;
     card.LastInterval = 0;
     card.NextDate = DateTime.UtcNow.Date;
     return card;
 }
Exemple #4
0
 public TrainingDto(Card card, long total, int wordsLeft)
 {
     ID = card.Id;
     Word = card.Word;
     Translation = card.Translation;
     Total = total;
     WordsForToday = wordsLeft;
 }
Exemple #5
0
 public static Card InitCard(Card card)
 {
     card.LastTrainingDate = null;
     card.Score = Score.None;
     card.LastInterval = 0;
     card.NumberOfRepetitions = 0;
     card.EFactor = 2.5;
     card.NextDate = DateTime.UtcNow.Date;
     return card;
 }
Exemple #6
0
        // GET api/training - get next card for training
        public ResponseObject Get()
        {
            var currentUser = new UserService().FindByName(User.Identity.Name);
            var cardService = new CardService();
            var total = cardService.Count(currentUser.Id);

            var drillService = new DrillService();
            var cards = drillService.GetCardsForDrill(currentUser.Id);

            var currentCard = new Card();
            if (cards.Count > 0)
            {
                currentCard = cards[0];
            }

            return ResponseObject.Success(new TrainingDto(currentCard, total, cards.Count));
        }
Exemple #7
0
 public static Card GetUpdatedCard(Card card, Score score)
 {
     return UpdateCard(card, score);
 }
Exemple #8
0
 public static DateTime GetNextDate(Card card, Score score)
 {
     var newCard = UpdateCard(card, score);
     return newCard.NextDate;
 }
Exemple #9
0
 public static int GetInterval(Card card, Score score)
 {
     var newCard = UpdateCard(card, score);
     return newCard.LastInterval;
 }
Exemple #10
0
 private string Create(string word, string translation, User owner)
 {
     var card = new Card {Word = word, Translation = translation, Owner = owner};
     card = Algorithm.InitCard(card);
     card = cardRepo.Add(card);
     return card.Id;
 }
Exemple #11
0
 private string Update(Card card, string word,  string translation)
 {
     card.Word = word;
     card.Translation = translation;
     cardRepo.Update(card);
     return card.Id;
 }
Exemple #12
0
 public CardDto(Card card)
 {
     ID = card.Id;
     Word = card.Word;
     Translation = card.Translation;
 }