Exemplo n.º 1
0
        public ActionResult HitsPerSong(DateTime?cutoff)
        {
            var values = userRepository.HandleQuery(ctx => {
                var idsAndHits = ctx.OfType <SongHit>().Query()
                                 .FilterIfNotNull(cutoff, s => s.Date > cutoff)
                                 .GroupBy(h => h.Entry.Id)
                                 .Select(h => new {
                    Id    = h.Key,
                    Count = h.Count()
                })
                                 .OrderByDescending(h => h.Count)
                                 .Take(25)
                                 .ToArray();

                var ids = idsAndHits.Select(i => i.Id).ToArray();

                var songs = StatsQueries.GetSongsWithNames(ctx, ids).Values;

                foreach (var hit in idsAndHits)
                {
                    songs.First(a => a.EntryId == hit.Id).Value = hit.Count;
                }

                return(songs.OrderByDescending(a => a.Value));
            });

            var categories = values.Select(p => p.Name[permissionContext.LanguagePreference]).ToArray();
            var data       = values.Select(p => p.Value).ToArray();

            return(SimpleBarChart("Views per song", "Hits", categories, data));
        }
Exemplo n.º 2
0
 public StatsController(IUserRepository userRepository, IUserPermissionContext permissionContext, SongAggregateQueries songAggregateQueries,
                        HttpContextBase context, VdbConfigManager config, ActivityEntryQueries activityEntryQueries, StatsQueries queries)
 {
     this.userRepository       = userRepository;
     this.permissionContext    = permissionContext;
     this.activityEntryQueries = activityEntryQueries;
     this.queries = queries;
     this.songAggregateQueries = songAggregateQueries;
     this.context = context;
     this.config  = config;
 }
Exemplo n.º 3
0
 public StatsController(
     IUserRepository userRepository,
     IUserPermissionContext permissionContext,
     SongAggregateQueries songAggregateQueries,
     VdbConfigManager config,
     ActivityEntryQueries activityEntryQueries,
     StatsQueries queries,
     ObjectCache cache)
 {
     _userRepository       = userRepository;
     _permissionContext    = permissionContext;
     _activityEntryQueries = activityEntryQueries;
     _queries = queries;
     _songAggregateQueries = songAggregateQueries;
     _config = config;
     _cache  = cache;
 }