示例#1
0
        public int GetAllCount(AnalyticsQueryModel query)
        {
            var queryable = GetQueryable();

            queryable = ApplyFilters(queryable, query);
            return(queryable.Count());
        }
示例#2
0
        public IList <SingleStatDto> GetByTag(AnalyticsQueryModel query)
        {
            if (_tagService == null)
            {
                throw (new Exception("Must enable Orchard.Tags"));
            }

            var tags = _tagService.GetTags().Select(x => new SingleStatDto {
                Name = x.TagName
            }).ToList();

            foreach (var tag in tags)
            {
                var queryable = GetQueryable();
                queryable = ApplyFilters(queryable, query);
                tag.Count = queryable.Where(x => x.Tags.Contains(tag.Name)).Count();
            }
            var result = tags.OrderByDescending(x => x.Count)
                         .Skip(query.Skip);

            if (query.Take > 0)
            {
                result = result.Take(query.Take);
            }
            return(result.ToList());
        }
示例#3
0
        public IList <RawAnalyticsDto> GetAll(AnalyticsQueryModel query)
        {
            var queryable = GetQueryable();

            queryable = ApplyFilters(queryable, query);
            queryable = queryable.OrderByDescending(x => x.VisitDateUtc)
                        .Skip(query.Skip);
            if (query.Take > 0)
            {
                queryable = queryable.Take(query.Take);
            }
            var items = queryable
                        .Select(x => new RawAnalyticsDto
            {
                Tags           = x.Tags,
                UserIdentifier = !string.IsNullOrWhiteSpace(x.UserIdentifier) ? x.UserIdentifier : T("Anonymous").ToString(),
                Url            = x.Url,
                VisitDate      = x.VisitDateUtc.ToLocalTime()
            }).ToList();

            foreach (var item in items)
            {
                var tags = (item.Tags ?? "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                Array.Sort(tags);
                item.Tags = string.Join(", ", tags);
            }
            return(items);
        }
示例#4
0
        private int GetGroupByCount(AnalyticsQueryModel query, Expression <Func <AnalyticsEntry, string> > groupSelector)
        {
            var queryable = GetQueryable();

            queryable = ApplyFilters(queryable, query);
            return(queryable.Select(groupSelector).Distinct().Count());
        }
示例#5
0
        public int GetByTagCount(AnalyticsQueryModel query)
        {
            if (_tagService == null)
            {
                throw (new Exception("Must enable Orchard.Tags"));
            }

            return(_tagService.GetTags().Count());
        }
示例#6
0
        private IList <SingleStatDto> GetGroupByItems(AnalyticsQueryModel query, Expression <Func <AnalyticsEntry, string> > groupSelector)
        {
            var queryable = GetGroupBy(query, groupSelector)
                            .Skip(query.Skip);

            if (query.Take > 0)
            {
                queryable = queryable.Take(query.Take);
            }
            return(queryable.ToList());
        }
示例#7
0
        private IQueryable <SingleStatDto> GetGroupBy(AnalyticsQueryModel query, Expression <Func <AnalyticsEntry, string> > groupSelector)
        {
            var queryable = GetQueryable();

            queryable = ApplyFilters(queryable, query);
            return(queryable.GroupBy(groupSelector)
                   .OrderByDescending(x => x.Count())
                   .Select(x => new SingleStatDto
            {
                Name = x.Key,
                Count = x.Count()
            }));
        }
示例#8
0
 public int GetByPageCount(AnalyticsQueryModel query)
 {
     return(GetGroupByCount(query, x => x.Url));
 }
示例#9
0
 /// <summary>
 /// Returns a list of unqiue page URLs with the number of times they have been
 /// visited by a user.
 /// </summary>
 /// <param name="skip">Index of row to return from.</param>
 /// <param name="take">Number of rows to take.</param>
 /// <returns>List of page URLs with their view count.</returns>
 public IList <SingleStatDto> GetByPage(AnalyticsQueryModel query)
 {
     return(GetGroupByItems(query, x => x.Url));
 }
示例#10
0
 private IQueryable <AnalyticsEntry> ApplyFilters(IQueryable <AnalyticsEntry> queryable, AnalyticsQueryModel query)
 {
     queryable = ApplyDateFilter(queryable, query.FromUtc, query.ToUtc);
     queryable = ApplyTermFilter(queryable, query.Term);
     return(queryable);
 }
示例#11
0
 public int GetByUserCount(AnalyticsQueryModel query)
 {
     return(GetGroupByCount(query, x => x.UserIdentifier));
 }
示例#12
0
 /// <summary>
 /// Returns a list of unqiue UserIdentifiers with the number of times they have been
 /// viewed a page.
 /// </summary>
 /// <param name="from">Index of row to return from.</param>
 /// <param name="to">Index of row to return up to.</param>
 /// <returns>List of UserIdentifiers with their view count.</returns>
 public IList <SingleStatDto> GetByUser(AnalyticsQueryModel query)
 {
     return(GetGroupByItems(query, x => x.UserIdentifier));
 }