Beispiel #1
0
        public JsonResult LocaleStatistics(List <int> AdIds, string sDate = "", string eDate = "")
        {
            var ads = service.GetUserAds(User.Identity.GetUserId()).Where(a => AdIds.Contains(a.Id));

            List <LocaleVisitorsTable> table        = new List <LocaleVisitorsTable>();
            CompareChartModel          chartCompare = new CompareChartModel();
            //var sessionsByWeek = ads.SelectMany(a => a.AdSessions).Where(a => a.DateTimeStart.Date.CompareTo(date.Date) == 0);
            var         sessionsByLocale = ads.SelectMany(a => a.AdSessions).GroupBy(a => a.UserLocale);
            StatChartJS chartModel       = new StatChartJS();

            chartModel.name = "Лояльность по странам";
            foreach (var session in sessionsByLocale)
            {
                LocaleVisitorsTable row = new LocaleVisitorsTable();
                row.Locale       = session.Key;
                row.ViewsByWeek  = session.Count(a => a.DateTimeStart.AddDays(7).CompareTo(DateTime.Now) > 0).ToString();
                row.ViewsByMonth = session.Count(a => a.DateTimeStart.AddMonths(1).CompareTo(DateTime.Now) > 0).ToString();
                chartModel.labels.Add(session.Key);
                chartModel.data.Add(row.ViewsByMonth);

                row.PopularPresentation = ads.First(b => b.Id == session
                                                    .GroupBy(a => a.AdId)
                                                    .OrderByDescending(a => a.Count())
                                                    .First().Key).Name;
                table.Add(row);
            }
            chartCompare.charts.Add(chartModel);
            return(Json(chartCompare));
        }
Beispiel #2
0
        public HttpResponseMessage LocaleVisitorsStatistics(bool chart = false)
        {
            var ads = service.GetUserAds(User.Identity.GetUserId());
            List <LocaleVisitorsTable> table        = new List <LocaleVisitorsTable>();
            CompareChartModel          chartCompare = new CompareChartModel();

            if (ads.Count > 0)
            {
                //var sessionsByWeek = ads.SelectMany(a => a.AdSessions).Where(a => a.DateTimeStart.Date.CompareTo(date.Date) == 0);
                var         sessionsByLocale = ads.SelectMany(a => a.AdSessions).GroupBy(a => a.UserLocale);
                StatChartJS chartModel       = new StatChartJS();
                chartModel.name = "Лояльность по странам";
                foreach (var session in sessionsByLocale)
                {
                    LocaleVisitorsTable row = new LocaleVisitorsTable();
                    row.Locale       = session.Key;
                    row.ViewsByWeek  = session.Count(a => a.DateTimeStart.AddDays(7).CompareTo(DateTime.Now) > 0).ToString();
                    row.ViewsByMonth = session.Count(a => a.DateTimeStart.AddMonths(1).CompareTo(DateTime.Now) > 0).ToString();
                    chartModel.labels.Add(session.Key);
                    chartModel.data.Add(row.ViewsByMonth);

                    row.PopularPresentation = ads.First(b => b.Id == session
                                                        .GroupBy(a => a.AdId)
                                                        .OrderByDescending(a => a.Count())
                                                        .First().Key).Name;
                    table.Add(row);
                }
            }
            return(Request.CreateResponse(HttpStatusCode.OK, table));
        }
Beispiel #3
0
        public JsonResult FunnelStatistics(List <int> AdIds, string sDate = "", string eDate = "")
        {
            List <SimpleAdModel> ads   = new List <SimpleAdModel>();
            CompareChartModel    chart = new CompareChartModel();

            if (AdIds == null || AdIds.Count == 0)
            {
                return(Json(new StatChartJS()));
            }
            foreach (int adId in AdIds)
            {
                var ad = service.GetAdById(adId);
                ads.Add(ad);
            }
            DateTime startDateTime = DateTime.MinValue;
            DateTime endDateTime   = DateTime.MaxValue;

            if (sDate != "")
            {
                startDateTime = DateTime.Parse(sDate);
            }
            if (eDate != "")
            {
                endDateTime = DateTime.Parse(eDate);
            }
            foreach (var ad in ads)
            {
                StatChartJS jsModel = new StatChartJS();
                var         clicks  = ad.AdSessions
                                      .SelectMany(a => a.Activities)
                                      .Where(c => c.StartTime.CompareTo(startDateTime) >= 0 &&
                                             c.EndTime.CompareTo(endDateTime) <= 0).GroupBy(d => d.CurrentStateName).OrderByDescending(e => e.Count());
                jsModel.name = ad.Name;
                foreach (var clickGroup in clicks)
                {
                    var clickElem = clickGroup.First();
                    //AdState state = service.GetStateByAdIdAndVideoId(ad.Id, clickElem.ClickCurrentStage, clickElem.Activity.CurrentStateName);
                    jsModel.labels.Add(clickElem.CurrentStateName);
                    jsModel.data.Add(clickGroup.Count().ToString());
                }
                chart.charts.Add(jsModel);
            }
            return(Json(chart));
        }
Beispiel #4
0
        public JsonResult BrowserStatistics(List <int> AdIds, string sDate = "", string eDate = "")
        {
            List <SimpleAdModel> ads   = new List <SimpleAdModel>();
            CompareChartModel    chart = new CompareChartModel();

            if (AdIds == null || AdIds.Count == 0)
            {
                return(Json(new StatChartJS()));
            }
            foreach (int adId in AdIds)
            {
                var ad = service.GetAdById(adId);
                ads.Add(ad);
            }
            DateTime startDateTime = DateTime.MinValue;
            DateTime endDateTime   = DateTime.MaxValue;

            if (sDate != "")
            {
                startDateTime = DateTime.Parse(sDate);
            }
            if (eDate != "")
            {
                endDateTime = DateTime.Parse(eDate);
            }
            foreach (var ad in ads)
            {
                StatChartJS jsModel = new StatChartJS();
                jsModel.labels = Browsers.NAMES.ToList();
                jsModel.name   = ad.Name;
                foreach (var browserName in jsModel.labels)
                {
                    jsModel.data.Add(ad.AdSessions
                                     .Where(b => b.UserBrowser.Equals(browserName) &&
                                            b.DateTimeStart.CompareTo(startDateTime) >= 0 &&
                                            b.DateTimeEnd.CompareTo(endDateTime) <= 0).Count().ToString());
                }
                chart.charts.Add(jsModel);
            }
            return(Json(chart));
        }
Beispiel #5
0
        public JsonResult ClickStatistics(List <int> AdIds, string sDate = "", string eDate = "",
                                          int interval = 1, bool isMinificate = false)
        {
            List <SimpleAdModel> ads = new List <SimpleAdModel>();

            if (AdIds == null || AdIds.Count == 0)
            {
                return(Json(new CompareChartModel()));
            }
            foreach (int adId in AdIds)
            {
                var ad = service.GetAdById(adId);
                if (ad.AdSessions.Count > 0)
                {
                    ads.Add(ad);
                }
            }
            CompareChartModel chart     = new CompareChartModel();
            DateTime          startDate = DateTime.Now;
            DateTime          endDate   = DateTime.Now;

            try
            {
                startDate = ads.Min(a => a.AdSessions.OrderBy(b => b.DateTimeStart).First().DateTimeStart);
                endDate   = ads.Max(a => a.AdSessions.OrderByDescending(b => b.DateTimeStart).First().DateTimeStart);
            }
            catch (Exception ex)
            {
                return(Json(chart));
            }
            if (sDate != "")
            {
                DateTime dt = DateTime.Parse(sDate);
                if (dt.CompareTo(startDate) > 0)
                {
                    startDate = dt;
                }
            }
            if (eDate != "")
            {
                DateTime dt = DateTime.Parse(eDate);
                if (dt.CompareTo(endDate) < 0)
                {
                    endDate = dt;
                }
            }
            foreach (var ad in ads)
            {
                StatChartJS model = new StatChartJS();
                model.name = ad.Name;
                for (DateTime curDate = startDate; curDate <= endDate; curDate = curDate.Date.AddDays(interval))
                {
                    DateTime estimate = curDate.Date.AddDays(interval);
                    model.labels.Add(curDate.ToShortDateString());
                    List <AdSession> sessions = new List <AdSession>();
                    foreach (var s in ad.AdSessions)
                    {
                        if (s.DateTimeStart.Date.CompareTo(curDate.Date) >= 0 && s.DateTimeStart.CompareTo(estimate.Date) <= 0)
                        {
                            sessions.Add(s);
                        }
                    }
                    if (sessions.Count() == 0)
                    {
                        model.data.Add("0");
                    }
                    else
                    {
                        model.data.Add(sessions.SelectMany(a => a.Activities).SelectMany(b => b.Clicks).Count().ToString());
                    }
                }
                model.name = ad.Name;
                chart.charts.Add(model);
            }

            return(Json(chart));
        }