public List <AuthorPeriodStatsBoxToken> GetAuthorPeriodStats(ReportEnums.ePeriodSelectionKinds period)
        {
            try
            {
                var reportPeriod   = PeriodSelection2DateRange(period);
                var previousPeriod = Period2Previous(period);

                using (var context = new lfeAuthorEntities())
                {
                    var totals         = context.tvf_FACT_DASH_GetAuthorPeriodStats(reportPeriod.from, reportPeriod.to).FirstOrDefault();
                    var previousTotals = context.tvf_FACT_DASH_GetAuthorPeriodStats(previousPeriod.from, previousPeriod.to).FirstOrDefault();

                    if (totals == null)
                    {
                        return(new List <AuthorPeriodStatsBoxToken>());
                    }

                    var list = new List <AuthorPeriodStatsBoxToken>
                    {
                        ReportEnums.eStatsTypes.ActiveAuthors.Type2AuthorPeriodStatsBoxToken(1, totals.ActiveAuthors, previousTotals != null ? previousTotals.ActiveAuthors : 0),
                        ReportEnums.eStatsTypes.AvgAuthorLogins.Type2AuthorPeriodStatsBoxToken(2, totals.AvgAuthorLogins.FormatDecimal(2), previousTotals != null ? previousTotals.AvgAuthorLogins.FormatDecimal(2) : 0),
                        ReportEnums.eStatsTypes.DashboardViews.Type2AuthorPeriodStatsBoxToken(3, totals.DashboardViews, previousTotals != null ? previousTotals.DashboardViews : 0),
                        ReportEnums.eStatsTypes.CouponsCreated.Type2AuthorPeriodStatsBoxToken(4, totals.TotalCouponsCreated, previousTotals != null ? previousTotals.TotalCouponsCreated : 0)
                    };

                    return(list);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Get Admin Dashboard author period stats", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new List <AuthorPeriodStatsBoxToken>());
            }
        }
        public List <LearnerPeriodStatsBoxToken> GetLearnerPeriodStats(ReportEnums.ePeriodSelectionKinds period)
        {
            try
            {
                var reportPeriod   = PeriodSelection2DateRange(period);
                var previousPeriod = Period2Previous(period);

                using (var context = new lfeAuthorEntities())
                {
                    var totals = context.tvf_FACT_DASH_GetLearnerPeriodStats(reportPeriod.from, reportPeriod.to).FirstOrDefault();

                    if (totals == null)
                    {
                        return(new List <LearnerPeriodStatsBoxToken>());
                    }

                    var previousTotals = context.tvf_FACT_DASH_GetLearnerPeriodStats(previousPeriod.from, previousPeriod.to).FirstOrDefault();

                    var avgLogin     = ReportEnums.eStatsTypes.AvgLearnerLogin.Type2LearnerPeriodStatsBoxToken(0, totals.AvgLearnerLogin.FormatDecimal(2), previousTotals != null ? previousTotals.AvgLearnerLogin.FormatDecimal(2) : 0);
                    var buyCompltete = ReportEnums.eStatsTypes.PurchaseComplete.Type2LearnerPeriodStatsBoxToken(2, totals.TotalPurchaseComplete, previousTotals != null ? previousTotals.TotalPurchaseComplete: 0);

                    decimal avgWatched     = totals.TotalCoursesWatched > 0 ? totals.TotalVideosWatched / totals.TotalCoursesWatched : 0;
                    decimal prevAvgWatched = previousTotals != null ? (previousTotals.TotalCoursesWatched > 0 ? previousTotals.TotalVideosWatched / previousTotals.TotalCoursesWatched : 0) : 0;

                    var list = new List <LearnerPeriodStatsBoxToken>
                    {
                        ReportEnums.eStatsTypes.ActiveLearners.Type2LearnerPeriodStatsBoxToken(1, totals.TotalActiveLearners, previousTotals != null ? previousTotals.TotalActiveLearners : 0, avgLogin),
                        ReportEnums.eStatsTypes.VideoPreviewWatched.Type2LearnerPeriodStatsBoxToken(2, totals.TotalVideoPreveiwWatched, previousTotals != null ? previousTotals.TotalVideoPreveiwWatched : 0),
                        ReportEnums.eStatsTypes.CoursePreviewEntered.Type2LearnerPeriodStatsBoxToken(3, totals.TotalCoursePreviewEntered, previousTotals != null ? previousTotals.TotalCoursePreviewEntered: 0),
                        ReportEnums.eStatsTypes.PurchasePageEntered.Type2LearnerPeriodStatsBoxToken(4, totals.TotalPurchasePageEntered, previousTotals != null ? previousTotals.TotalPurchasePageEntered: 0, buyCompltete),
                        ReportEnums.eStatsTypes.AvgVideosWatchedPerCourse.Type2LearnerPeriodStatsBoxToken(5, avgWatched.FormatDecimal(2), prevAvgWatched.FormatDecimal(2)),
                        ReportEnums.eStatsTypes.TotalVideosWatched.Type2LearnerPeriodStatsBoxToken(6, totals.TotalVideosWatched, previousTotals != null ? previousTotals.TotalVideosWatched: 0)
                    };

                    return(list);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Get Admin Dashboard learner period stats", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new List <LearnerPeriodStatsBoxToken>());
            }
        }
        public List <TotalsBoxToken> GetTotals(ReportEnums.ePeriodSelectionKinds period)
        {
            try
            {
                var reportPeriod = PeriodSelection2DateRange(period);

                var previousPeriod = Period2Previous(period);

                using (var context = new lfeAuthorEntities())
                {
                    var totals = context.tvf_FACT_DASH_GetTotals().FirstOrDefault();

                    if (totals == null)
                    {
                        return(new List <TotalsBoxToken>());
                    }

                    var rows         = context.tvf_FACT_DASH_GetNewPeriodTotals(reportPeriod.from, reportPeriod.to).ToList();
                    var previousRows = context.tvf_FACT_DASH_GetNewPeriodTotals(previousPeriod.from, previousPeriod.to).ToList();

                    var list = new List <TotalsBoxToken>
                    {
                        ReportEnums.eStatsTypes.Stores.Type2TotalsBoxToken(1, totals.TotalStores, rows.Sum(x => x.NewStores), previousRows.Sum(x => x.NewStores)),
                        ReportEnums.eStatsTypes.Courses.Type2TotalsBoxToken(2, totals.TotalCourses, rows.Sum(x => x.NewCourses), previousRows.Sum(x => x.NewCourses)),
                        ReportEnums.eStatsTypes.Bundles.Type2TotalsBoxToken(3, totals.TotalBundles, rows.Sum(x => x.NewBundles), previousRows.Sum(x => x.NewBundles)),
                        ReportEnums.eStatsTypes.Learners.Type2TotalsBoxToken(4, totals.TotalLearners, rows.Sum(x => x.NewLearners), previousRows.Sum(x => x.NewLearners)),
                        ReportEnums.eStatsTypes.Authors.Type2TotalsBoxToken(5, totals.TotalAuthors, rows.Sum(x => x.NewAuthors), previousRows.Sum(x => x.NewAuthors))
                    };

                    return(list);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Get totals stats for admin dashboard", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new List <TotalsBoxToken>());
            }
        }
        public IntegrationStatsToken GetIntegrationStatsToken(ReportEnums.ePeriodSelectionKinds period)
        {
            try
            {
                var reportPeriod = PeriodSelection2DateRange(period);

                using (var context = new lfeAuthorEntities())
                {
                    var rows = context.tvf_FACT_DASH_GetNewPeriodTotals(reportPeriod.from, reportPeriod.to).ToList();

                    return(new IntegrationStatsToken
                    {
                        TotalMailchimp = rows.Sum(x => x.NewMailchimpLists)
                        , MbgJoined = rows.Sum(x => x.NewMBGJoined)
                        , MbgCanceled = rows.Sum(x => x.MBGCancelled)
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Get Admin Dashboard integration stats", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(new IntegrationStatsToken());
            }
        }
        public List <PlatformStatsToken> GetPlatformStats(ReportEnums.ePeriodSelectionKinds period)
        {
            var list = new List <PlatformStatsToken>();

            try
            {
                var reportPeriod = PeriodSelection2DateRange(period);

                var previousPeriod = Period2Previous(period);

                using (var context = new lfeAuthorEntities())
                {
                    var rows = context.tvf_FACT_DASH_GetPlatformStats(reportPeriod.from, reportPeriod.to).ToList();

                    var previousRows = context.tvf_FACT_DASH_GetPlatformStats(previousPeriod.from, previousPeriod.to).ToList();

                    var platformIds = rows.GroupBy(x => new { id = x.RegistrationTypeId }).Select(s => s.Key.id).ToArray();

                    foreach (var platformId in platformIds)
                    {
                        var platform        = Utils.ParseEnum <CommonEnums.eRegistrationSources>(platformId.ToString());
                        var subList         = rows.Where(x => x.RegistrationTypeId == (int)platform).OrderBy(x => x.FactDate).ToList();
                        var previousSubList = previousRows.Where(x => x.RegistrationTypeId == (int)platform).ToList();


                        var token = new PlatformStatsToken
                        {
                            Platform           = platform
                            , Index            = platform.RegistrationSource2AdminDashboardIndex()
                            , Stats            = new List <PlatformStatsBoxToken>()
                            , TotalPlatformNew = subList.Sum(x => x.TotalPlatformNew)
                        };

                        token.Tendency = token.TotalPlatformNew.Value2TendencyToken(previousSubList.Sum(x => x.TotalPlatformNew));

                        #region
                        Parallel.Invoke(
                            () =>
                        {
                            var box = new PlatformStatsBoxToken
                            {
                                Type     = ReportEnums.eStatsTypes.Authors
                                , Index  = 1
                                , Total  = subList[subList.Count - 1].TotalAuhtors
                                , New    = subList.Sum(x => x.NewAuthors)
                                , Points = new List <BaseChartPointToken>()
                            };

                            box.Tendency = box.New.Value2TendencyToken(previousSubList.Sum(x => x.NewAuthors));

                            foreach (var p in subList.OrderBy(x => x.FactDate).ToList())
                            {
                                box.Points.Add(new BaseChartPointToken
                                {
                                    date    = p.FactDate
                                    , value = p.NewAuthors
                                });
                            }

                            token.Stats.Add(box);
                        },
                            () =>
                        {
                            var box = new PlatformStatsBoxToken
                            {
                                Type     = ReportEnums.eStatsTypes.Items
                                , Index  = 2
                                , Total  = subList[subList.Count - 1].TotalItems
                                , New    = subList.Sum(x => x.NewItems)
                                , Points = new List <BaseChartPointToken>()
                            };

                            box.Tendency = box.New.Value2TendencyToken(previousSubList.Sum(x => x.NewItems));

                            foreach (var p in subList.OrderBy(x => x.FactDate).ToList())
                            {
                                box.Points.Add(new BaseChartPointToken
                                {
                                    date    = p.FactDate
                                    , value = p.NewItems
                                });
                            }

                            token.Stats.Add(box);
                        },
                            () =>
                        {
                            var box = new PlatformStatsBoxToken
                            {
                                Type     = ReportEnums.eStatsTypes.Stores
                                , Index  = 3
                                , Total  = subList[subList.Count - 1].TotalStores
                                , New    = subList.Sum(x => x.NewStores)
                                , Points = new List <BaseChartPointToken>()
                            };

                            box.Tendency = box.New.Value2TendencyToken(previousSubList.Sum(x => x.NewStores));

                            foreach (var p in subList.OrderBy(x => x.FactDate).ToList())
                            {
                                box.Points.Add(new BaseChartPointToken
                                {
                                    date    = p.FactDate
                                    , value = p.NewStores
                                });
                            }

                            token.Stats.Add(box);
                        },
                            () =>
                        {
                            var box = new PlatformStatsBoxToken
                            {
                                Type     = ReportEnums.eStatsTypes.Learners
                                , Index  = 4
                                , Total  = subList[subList.Count - 1].TotalLearners
                                , New    = subList.Sum(x => x.NewLearners)
                                , Points = new List <BaseChartPointToken>()
                            };

                            box.Tendency = box.New.Value2TendencyToken(previousSubList.Sum(x => x.NewLearners));

                            foreach (var p in subList.OrderBy(x => x.FactDate).ToList())
                            {
                                box.Points.Add(new BaseChartPointToken
                                {
                                    date    = p.FactDate
                                    , value = p.NewLearners
                                });
                            }

                            token.Stats.Add(box);
                        },
                            () =>
                        {
                            var box = new PlatformStatsBoxToken
                            {
                                Type     = ReportEnums.eStatsTypes.Sales
                                , Index  = 5
                                , Total  = subList[subList.Count - 1].TotalSales
                                , New    = subList.Sum(x => x.NewSales)
                                , Points = new List <BaseChartPointToken>()
                            };

                            box.Tendency = box.New.Value2TendencyToken(previousSubList.Sum(x => x.NewSales));

                            foreach (var p in subList.OrderBy(x => x.FactDate).ToList())
                            {
                                box.Points.Add(new BaseChartPointToken
                                {
                                    date    = p.FactDate
                                    , value = p.NewSales
                                });
                            }

                            token.Stats.Add(box);
                        });
                        #endregion

                        list.Add(token);
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                Logger.Error("Get platform stats for admin dashboard", ex, CommonEnums.LoggerObjectTypes.Reports);
                return(list);
            }
        }
Example #6
0
        public ActionResult GetFactDailyTotalsData(ReportEnums.ePeriodSelectionKinds period)
        {
            var facts = _reportServices.GetDailyTotalsData(period);

            return(Json(facts, JsonRequestBehavior.AllowGet));
        }
Example #7
0
        public ActionResult GetVideoUploadsDailyStatsData(ReportEnums.ePeriodSelectionKinds period)
        {
            var facts = _reportServices.GetDailyVideoStatsData(period);

            return(Json(facts, JsonRequestBehavior.AllowGet));
        }
Example #8
0
        public ActionResult GetKpiDataRows([DataSourceRequest] DataSourceRequest request, ReportEnums.ePeriodSelectionKinds period, int?authorId, int?storeId, int?itemId, CommonEnums.eEventItemTypes?itemType)
        {
            var list = _reportServices.GetKpiDataRows(period, authorId, storeId, itemId, itemType).ToArray();

            return(Json(list.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
        }
Example #9
0
        public ActionResult GetKpiData(ReportEnums.ePeriodSelectionKinds period, int?authorId, int?storeId, int?itemId, CommonEnums.eEventItemTypes?itemType)
        {
            var facts = _reportServices.GetKpiData(period, authorId, storeId, itemId, itemType);

            return(Json(facts, JsonRequestBehavior.AllowGet));
        }