Example #1
0
        public IEnumerable <ContentItem> ReorderChildren(ContentItem item)
        {
            var childPages      = item.Children.FindPages().ToList();
            var stats           = statistics.GetStatistics(Utility.CurrentTime().Subtract(TimeSpan.FromDays(NumberOfDaysToConsider)), Utility.CurrentTime(), childPages.Select(p => p.ID).ToArray());
            var statsDictionary = stats.GroupBy(s => s.PageID, s => s.Views).ToDictionary(s => s.Key, s => s.Sum());

            foreach (var page in childPages)
            {
                var newOrder = statsDictionary.ContainsKey(page.ID)
                                        ? -statsDictionary[page.ID]
                                        : 0;
                if (newOrder == page.SortOrder)
                {
                    continue;
                }
                page.SortOrder = newOrder;
                yield return(page);
            }
        }
Example #2
0
        public object Index(DateTime?from, DateTime?to, int?n2item, bool?raw)
        {
            to   = to ?? Utility.CurrentTime().GetSlot(granularity).Add(slotSize);
            from = from ?? to.Value.AddDays(-displayedDays);

            var statistics = repository.GetStatistics(from.Value, to.Value, n2item ?? 0)
                             .ToList();

            if (raw.HasValue && raw.Value)
            {
                return new { Views = statistics }
            }
            ;

            var views = Slottify(statistics, from.Value, to.Value).ToList();

            if (n2item == 0)
            {
                var pages = statistics.GroupBy(s => s.PageID)
                            .OrderByDescending(g => g.Sum(x => x.Views))
                            .Select(g =>
                {
                    var slots = Slottify(g, from.Value, to.Value).ToList();
                    return(new { PageID = g.Key, TotalViews = g.Sum(x => x.Views), Max = slots.Max(v => v.Views), Views = slots });
                }).ToList();

                return(new
                {
                    Max = views.Select(s => s.Views).DefaultIfEmpty().Max(),
                    Views = views,
                    Pages = pages
                });
            }
            else
            {
                return(new
                {
                    Max = views.Select(s => s.Views).DefaultIfEmpty().Max(),
                    Views = views
                });
            }
        }