コード例 #1
0
        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;
        }
コード例 #2
0
ファイル: CountersService.cs プロジェクト: jon123/NGM.Forum
        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));
                 */
                    
            }
        }
コード例 #3
0
ファイル: ThreadPartHandler.cs プロジェクト: six006/NGM.Forum
        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));
            }
        }
コード例 #4
0
ファイル: PostPartHandler.cs プロジェクト: six006/NGM.Forum
        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);
            }
        }
コード例 #5
0
ファイル: ThreadPartHandler.cs プロジェクト: six006/NGM.Forum
        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));
            }
        }
コード例 #6
0
ファイル: PostPartHandler.cs プロジェクト: YSRE/SuperRocket
        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);
            }
        }
コード例 #7
0
        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());
            }
        }
コード例 #8
0
 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 });
 }