Beispiel #1
0
        private IList <PublishedStory> GetPublishableStories(DateTime currentTime)
        {
            List <PublishedStory> publishableStories = new List <PublishedStory>();

            DateTime minimumDate = currentTime.AddHours(-_settings.MaximumAgeOfStoryInHoursToPublish);
            DateTime maximumDate = currentTime.AddHours(-_settings.MinimumAgeOfStoryInHoursToPublish);

            int publishableCount = _storyRepository.CountByPublishable(minimumDate, maximumDate);

            if (publishableCount > 0)
            {
                ICollection <IStory> stories = _storyRepository.FindPublishable(minimumDate, maximumDate, 0, publishableCount).Result;

                foreach (IStory story in stories)
                {
                    PublishedStory publishedStory = new PublishedStory(story);

                    foreach (IStoryWeightCalculator strategy in _storyWeightCalculators)
                    {
                        publishedStory.Weights.Add(strategy.Name, strategy.Calculate(currentTime, story));
                    }

                    publishableStories.Add(publishedStory);
                }
            }

            return(publishableStories);
        }
Beispiel #2
0
        public virtual IList <IStory> FindWeekly(DateTime minimumDate, DateTime maximumDate)
        {
            Check.Argument.IsNotInFuture(minimumDate, "minimumDate");

            if (maximumDate >= DateTime.UtcNow)
            {
                maximumDate = DateTime.UtcNow.AddMinutes(-1);
            }


            var publishableStories = new List <PublishedStory>();

            var stories = minimumDate >= new DateTime(2018, 07, 06)
                ? _storyRepository.FindPublishedBetween(minimumDate, maximumDate)
                : _storyRepository.FindCreatedBetween(minimumDate, maximumDate);

            foreach (IStory story in stories)
            {
                PublishedStory publishedStory = new PublishedStory(story);

                publishedStory.Weights.Add("View", publishedStory.Story.ViewCount);
                publishedStory.Weights.Add("Vote", publishedStory.Story.VoteCount * 100);

                publishableStories.Add(publishedStory);
            }

            return(publishableStories.OrderByDescending(x => x.TotalScore).Select(x => x.Story).ToList());
        }