Example #1
0
        private IEnumerable <PointInTime> GetIrEntityForChart(IEnumerable <Post> postQuery, int members, DateRange range, Periodicity periodicity)
        {
            IList <PointInTime> result         = new List <PointInTime>();
            var irCalculator                   = new InteractionRateCalculator();
            Func <DateTime, DateTime> increase = this.GetTimeIncreaseFunction(periodicity);

            for (var i = range.From; i < range.To; i = increase(i))
            {
                var date         = i;
                var posts        = postQuery.Where(x => (x.PostedDate >= date) && (x.PostedDate < date.AddMonths(1))).ToList();
                var postcount    = posts.Count();
                var commentcount = posts.Sum(x => x.CommentsCount);
                var likecount    = posts.Sum(x => x.LikesCount);
                var sharecount   = posts.Sum(x => x.SharesCount);
                if (postcount == 0 || members == 0)
                {
                    members   = 1;
                    postcount = 1;
                }
                double interactionRate = irCalculator.GetInteractionRate(commentcount, likecount, postcount, sharecount, members);

                result.Add(new PointInTime {
                    Date = date, Value = interactionRate
                });
            }

            return(result);
        }
        public Kpi CalculateKpis()
        {
            var calculator = new InteractionRateCalculator();

            var kpi = new Kpi();

            kpi.UsersCount = this.membersCount;

            if (this.postsCount <= 0)
            {
                return(kpi);
            }

            kpi.PostsCount             = this.postsCount;
            kpi.AverageLikesPerPost    = (double)this.postLikesCount / this.postsCount;
            kpi.AverageCommentsPerPost = (double)this.postCommentsCount / this.postsCount;
            kpi.InteractionRate        = this.membersCount > 0 ? calculator.GetInteractionRate(this.postCommentsCount, this.postLikesCount, this.postsCount, this.shareCount, this.membersCount) : 0;
            kpi.ResponseRate           = (double)this.postsWithAdminCommentsCount / this.postsCount;
            kpi.UgcRate       = (double)(this.postsCount - this.adminPostsCount) / this.postsCount;
            kpi.InvolmentRate = this.membersCount > 0 ? (double)this.postsCount / this.membersCount : 0;

            kpi.AdminPostsCount = this.adminPostsCount;
            kpi.UserPostsCount  = this.postsCount - this.adminPostsCount;
            kpi.SharePerPosts   = (double)this.shareCount / this.postsCount;

            return(kpi);
        }