예제 #1
0
        private static int GetBestMemCheckHeap(PaukerCard card, int stackIndex)
        {
            var learnedDate            = card.LearnedDate();
            var paukerExpiry           = PaukerExpiryDate(card, stackIndex);
            var resultDistanceToPauker = int.MaxValue;
            var result = 0;

            for (int i = 1; i < 20; i++)
            {
                double nbDaysOfExpiry           = Math.Pow(2, i);
                var    memCheckExpiryInThisHeap = learnedDate.AddDays(nbDaysOfExpiry);

                var distanceToPauker = (int)(paukerExpiry - memCheckExpiryInThisHeap).TotalDays;
                var absDist          = Math.Abs(distanceToPauker);

                if (absDist < resultDistanceToPauker)
                {
                    result = i;
                    resultDistanceToPauker = absDist;
                }
            }

            //if (resultDistanceToPauker != 72)
            //    logger.LogDebug($"resultDistanceToPauker: {resultDistanceToPauker} days");


            //logger.LogDebug($"Best heap for card is {result}, distance to Pauker is {resultDistanceToPauker} days");
            //logger.LogDebug($"Pauker expiry date: {paukerExpiry}");
            //DateTime memCheckExpiry = learnedDate.AddDays(Math.Pow(2, result));
            //logger.LogDebug($"MemCheck expiry date: {memCheckExpiry}");
            //return memCheckExpiry <= DateTime.Now;
            return(result);
        }
예제 #2
0
        private void RemoveDoublons(PaukerCard card)
        {
            var firstAlreadyFound = false;

            foreach (var stack in stacks)
            {
                firstAlreadyFound = stack.RemoveCard(card, !firstAlreadyFound) || firstAlreadyFound;
            }
        }
예제 #3
0
        private void SaveCard(PaukerCard card, XmlElement batchElem)
        {
            var cardElem = batchElem.OwnerDocument.CreateElement("Card");

            batchElem.AppendChild(cardElem);

            var frontSideElem = batchElem.OwnerDocument.CreateElement("FrontSide");

            cardElem.AppendChild(frontSideElem);
            SaveCardSide(card.Front, frontSideElem);

            var reverseSideElem = batchElem.OwnerDocument.CreateElement("ReverseSide");

            cardElem.AppendChild(reverseSideElem);
            SaveCardSide(card.Reverse, reverseSideElem);
        }
예제 #4
0
        internal bool RemoveCard(PaukerCard card, bool excludingFirst)
        {
            var indicesToDelete = new List <int>();

            for (int i = 0; i < cards.Count; i++)
            {
                if (cards[i].Equals(card))
                {
                    indicesToDelete.Add(i);
                }
            }

            if (indicesToDelete.Count == 0)
            {
                return(false);
            }

            if (excludingFirst)
            {
                int  indexToKeep = 0;
                long smallestLearnedTimeStamp = long.MaxValue;
                foreach (int i in indicesToDelete)
                {
                    var learned = cards[i].Front.LearnedTimestamp;
                    if (!learned.HasValue || (learned.Value < smallestLearnedTimeStamp))
                    {
                        indexToKeep = i;
                    }
                }
                indicesToDelete.Remove(indexToKeep);
            }

            for (int i = indicesToDelete.Count - 1; i >= 0; i--)
            {
                Console.WriteLine("Deleting card with front '{0}'", card.Front.Text);
                cards.RemoveAt(indicesToDelete[i]);
            }

            return(true);
        }
예제 #5
0
        private static DateTime PaukerExpiryDate(PaukerCard card, int stackIndex)
        {
            var nbDaysForExpiration = Math.Exp(stackIndex - 1);

            return(card.LearnedDate().AddDays(nbDaysForExpiration));
        }
예제 #6
0
        async public Task RunAsync()
        {
            var lesson = GetPaukerLesson();

            Console.WriteLine(string.Join(',', dbContext.Users));

            var user = dbContext.Users.Where(user => user.UserName == "Voltan").Single();
            var deck = dbContext.Decks.Where(deck => deck.Owner == user).First();
            //var tag = dbContext.Tags.Where(tag => tag.Name == "PaukerImport").Single();
            var cardLanguage = dbContext.CardLanguages.Where(cardLanguage => cardLanguage.Name == "Français").Single();

            logger.LogInformation($"Cards will be added to deck {deck.Description} of user {user.UserName}");// and tag {tag.Name} will be attached");

            const int paukerDisplayedStackIndex = 1;
            var       stack = lesson.Stacks[paukerDisplayedStackIndex + 2];

            logger.LogDebug($"Working on stack '{stack.Name}'");
            logger.LogDebug($"Stack contains {stack.Cards.Count} cards");

            for (int cardIndex = 0; cardIndex < stack.Cards.Count; cardIndex++)
            {
                logger.LogInformation($"Working on card {cardIndex} of {stack.Cards.Count}");
                PaukerCard paukerCard = stack.Cards[cardIndex];
                if (dbContext.Cards.Where(card => card.FrontSide == paukerCard.Front.Text.Trim()).Any())
                {
                    logger.LogInformation($"Card already exists in MemCheck with this front, skipping: {paukerCard.Front.Text}");
                }
                else
                {
                    CreateCard.Request request = new(
                        user.Id,
                        paukerCard.Front.Text.Trim(),
                        Array.Empty <Guid>(),
                        paukerCard.Reverse.Text.Trim(),
                        Array.Empty <Guid>(),
                        "",
                        Array.Empty <Guid>(),
                        cardLanguage.Id,
                        Array.Empty <Guid>(),
                        new[] { user.Id },
                        CardVersionDescription);

                    Card card = new()
                    {
                        FrontSide              = request.FrontSide,
                        BackSide               = request.BackSide,
                        AdditionalInfo         = request.AdditionalInfo,
                        CardLanguage           = cardLanguage,
                        VersionCreator         = user,
                        InitialCreationUtcDate = DateTime.Now.ToUniversalTime(),
                        VersionUtcDate         = DateTime.Now.ToUniversalTime()
                    };
                    await dbContext.Cards.AddAsync(card);

                    var usersWithView = new List <UserWithViewOnCard>();
                    var userWithView  = new UserWithViewOnCard()
                    {
                        UserId = user.Id, User = user, CardId = card.Id, Card = card
                    };
                    dbContext.UsersWithViewOnCards.Add(userWithView);
                    usersWithView.Add(userWithView);
                    card.UsersWithView = usersWithView;



                    //return new GetCardsOfUser.ViewModel(card.Id, card.FrontSide, card.BackSide, card.TagsInCards.Select(tagInCard => tagInCard.Tag.Name));



                    //var card = await creator.RunAsync(request, user);

                    var targetHeap = GetBestMemCheckHeap(paukerCard, paukerDisplayedStackIndex);

                    var cardInDeck = new CardInDeck()
                    {
                        CardId                  = card.Id,
                        DeckId                  = deck.Id,
                        CurrentHeap             = targetHeap,
                        LastLearnUtcTime        = paukerCard.LearnedDate().ToUniversalTime(),
                        AddToDeckUtcTime        = DateTime.UtcNow,
                        NbTimesInNotLearnedHeap = 1,
                        BiggestHeapReached      = targetHeap
                    };
                    await dbContext.CardsInDecks.AddAsync(cardInDeck);

                    //dbContext.SaveChanges();

                    //            var cardLoaded = dbContext.Cards.Where(card => card.Id == memCheckCard.Id).Include(card => card.UsersWithView).Single();
                    //            if (!cardLoaded.UsersWithView.Contains(user))
                    //                throw new ApplicationException();
                }

                //logger.LogDebug($"In stack {paukerDisplayedStackIndex}, {expiredCount} would be expired");
            }
            await dbContext.SaveChangesAsync();
        }
    }