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; }
public void UpdateCard(Card card, string ownerID) { if (card.Owner.Id == ownerID) { cardRepo.Update(card); } }
private static Card ResetCard(Card card) { card.EFactor = 2.5; card.NumberOfRepetitions = 0; card.LastInterval = 0; card.NextDate = DateTime.UtcNow.Date; return card; }
public TrainingDto(Card card, long total, int wordsLeft) { ID = card.Id; Word = card.Word; Translation = card.Translation; Total = total; WordsForToday = wordsLeft; }
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; }
// 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)); }
public static Card GetUpdatedCard(Card card, Score score) { return UpdateCard(card, score); }
public static DateTime GetNextDate(Card card, Score score) { var newCard = UpdateCard(card, score); return newCard.NextDate; }
public static int GetInterval(Card card, Score score) { var newCard = UpdateCard(card, score); return newCard.LastInterval; }
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; }
private string Update(Card card, string word, string translation) { card.Word = word; card.Translation = translation; cardRepo.Update(card); return card.Id; }
public CardDto(Card card) { ID = card.Id; Word = card.Word; Translation = card.Translation; }