Example #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);
        }
Example #2
0
        private static DateTime PaukerExpiryDate(PaukerCard card, int stackIndex)
        {
            var nbDaysForExpiration = Math.Exp(stackIndex - 1);

            return(card.LearnedDate().AddDays(nbDaysForExpiration));
        }
Example #3
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();
        }
    }