public double Calculate(ThreadPart thread) { double questionScore = 0D; DateTime defaultValue = DateTime.UtcNow; IList<double> answerScores = new List<double>(); var posts = _postService.Get(thread).ToArray(); var question = posts.First(o => o.IsParentThread()); var questionScoreRecord = _votingService.Get(vote => vote.ContentItemRecord == question.Record.ContentItemRecord && vote.Dimension == Constants.Voting.RatingConstant).FirstOrDefault(); if (questionScoreRecord != null) { questionScore = questionScoreRecord.Value; foreach (var answer in posts.Where(o => !o.IsParentThread())) { PostPart internalAnswer = answer; var answerScoreRecord = _votingService.Get(vote => vote.ContentItemRecord == internalAnswer.Record.ContentItemRecord && vote.Dimension == Constants.Voting.RatingConstant).FirstOrDefault(); if (answerScoreRecord != null) answerScores.Add(answerScoreRecord.Value); } } var resultRecord = _votingService.GetResult(thread.ContentItem.Id, "count", Constants.Voting.ViewConstant); var totalViews = resultRecord == null ? 0 : (int)resultRecord.Value; var threadCreatedDate = thread.As<ICommonPart>().CreatedUtc; var threadModifiedDate = thread.As<ICommonPart>().ModifiedUtc; var top = ((Math.Log(totalViews) * 4) + ((thread.PostCount * questionScore) / 5) + answerScores.Sum()); var bottom = Math.Pow(Convert.ToDouble((threadCreatedDate.GetValueOrDefault(defaultValue).AddHours(1).Hour) - ((threadCreatedDate.GetValueOrDefault(defaultValue).Subtract(threadModifiedDate.GetValueOrDefault(defaultValue))).Hours / 2)), 1.5); return top / bottom; }
public void UpdateForumPartCounters(ThreadPart threadPart) { var commonPart = threadPart.As<CommonPart>(); if (commonPart != null && commonPart.Record.Container != null) { var forumPart = threadPart.ForumPart ?? _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published); // TODO: Refactor this to do the count in the DB and not make 3 DB calls. var threads = _threadService.Get(forumPart, false, VersionOptions.Published).ToList(); forumPart.ThreadCount = threads.Count(); var threadIds = threads.Select(t => t.Id).ToList(); forumPart.PostCount = _contentManager.Query<PostPart, PostPartRecord>(VersionOptions.Published).Where(p => p.IsInappropriate == false) .Join<CommonPartRecord>().Where(c => threadIds.Contains(c.Container.Id) ).List().Count(); /* forumPart.ThreadCount = _threadService.Count(forumPart, VersionOptions.Published); forumPart.PostCount = _threadService .Get(forumPart, VersionOptions.Published) .Sum(publishedThreadPart => _postService .Count(publishedThreadPart, VersionOptions.Published)); */ } }
private void UpdateForumPartCounters(ThreadPart threadPart) { var commonPart = threadPart.As<CommonPart>(); if (commonPart != null && commonPart.Record.Container != null) { var forumPart = threadPart.ForumPart ?? _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published); // TODO: Refactor this to do the count in the DB and not make 3 DB calls. forumPart.ThreadCount = _threadService.Count(forumPart, VersionOptions.Published); forumPart.PostCount = _threadService .Get(forumPart, VersionOptions.Published) .Sum(publishedThreadPart => _postService .Count(publishedThreadPart, VersionOptions.Published)); } }
private void UpdateForumPartCounters(ThreadPart threadPart) { var commonPart = threadPart.As<CommonPart>(); if (commonPart != null && commonPart.Record.Container != null) { ForumPart forumPart = threadPart.ForumPart ?? _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published); forumPart.ThreadCount = _threadService.Count(forumPart, VersionOptions.Published); forumPart.PostCount = _threadService .Get(forumPart, VersionOptions.Published) .Sum(publishedThreadPart => publishedThreadPart.PostCount); } }
private void UpdateForumPartCounters(ThreadPart threadPart) { var commonPart = threadPart.As <CommonPart>(); if (commonPart != null && commonPart.Record.Container != null) { var forumPart = threadPart.ForumPart ?? _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published); // TODO: Refactor this to do the count in the DB and not make 3 DB calls. forumPart.ThreadCount = _threadService.Count(forumPart, VersionOptions.Published); forumPart.PostCount = _threadService .Get(forumPart, VersionOptions.Published) .Sum(publishedThreadPart => _postService .Count(publishedThreadPart, VersionOptions.Published)); } }
private void UpdateForumPartCounters(ThreadPart threadPart) { var commonPart = threadPart.As <CommonPart>(); if (commonPart != null && commonPart.Record.Container != null) { ForumPart forumPart = threadPart.ForumPart ?? _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published); forumPart.ThreadCount = _threadService.Count(forumPart, VersionOptions.Published); forumPart.PostCount = _threadService .Get(forumPart, VersionOptions.Published) .Sum(publishedThreadPart => publishedThreadPart.PostCount); } }
private void UpdateForumPartCounters(ThreadPart threadPart) { CommonPart commonPart = threadPart.As<CommonPart>(); if (commonPart != null && commonPart.Record.Container != null) { ForumPart forumPart = threadPart.ForumPart ?? _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published).As<ForumPart>(); forumPart.ContentItem.ContentManager.Flush(); forumPart.ThreadCount = _threadService.Get(forumPart, VersionOptions.Published).Count(); forumPart.PostCount = _threadService .Get(forumPart, VersionOptions.Published) .Sum(publishedThreadPart => _postService .Get(publishedThreadPart, VersionOptions.Published) .Count()); } }
public static string ViewThread(this UrlHelper urlHelper, ThreadPart threadPart) { return urlHelper.Action("Item", "Thread", new { forumPath = threadPart.ForumPart.As<IRoutableAspect>().Path, threadSlug = threadPart.As<IRoutableAspect>().GetEffectiveSlug(), area = Constants.LocalArea }); }