예제 #1
0
        public string MostViewedTvShows()
        {
            using (var db = new PlexInfoContext())
            {
                var mvts = (from sh in db.session_history
                            join shm in db.session_history_metadata on sh.rating_key equals shm.rating_key
                            where _utilities.UnixTimestampToDateTime(sh.started) > DateTime.Now.AddDays(-7)
                            where shm.section_id == 1
                            group shm by shm.rating_key
                            into g
                            select new
                {
                    rating_key = g.Key,
                    count = g.Count()
                }).Take(5);

                var result = "Most viewed tv shows\n";
                foreach (var show in mvts.OrderByDescending(x => x.count))
                {
                    var showInfo = _tvShowService.GetTvShowInfo(show.rating_key);

                    result = result + (showInfo.grandparent_title +
                                       " - " + showInfo.parent_title +
                                       " - " + showInfo.title +
                                       " | views: " + show.count + "\n");
                }
                return(result);
            }
        }
예제 #2
0
        public SessionHistoryMetadata GetTvShowInfo(int rating_key)
        {
            SessionHistoryMetadata show;

            using (var db = new PlexInfoContext())
            {
                show = (from shmi in db.session_history_metadata
                        where shmi.rating_key == rating_key
                        select shmi).FirstOrDefault();
            }
            return(show);
        }
예제 #3
0
        public string MostActiveUser()
        {
            using (var db = new PlexInfoContext())
            {
                var mau = (from sh in db.session_history
                           join u in db.users on sh.user_id equals u.user_id
                           where _utilities.UnixTimestampToDateTime(sh.started) > DateTime.Now.AddDays(-7)
                           group u by u.username
                           into g
                           select new
                {
                    username = g.Key,
                    count = g.Count()
                }).Take(5);

                var result = "Most active users\n";
                foreach (var user in mau.OrderByDescending(x => x.count))
                {
                    result = result + (user.username + " views: " + user.count + "\n");
                }
                return(result);
            }
        }
예제 #4
0
        public string MostViewedMovies()
        {
            using (var db = new PlexInfoContext())
            {
                var mvm = (from sh in db.session_history
                           join shm in db.session_history_metadata on sh.rating_key equals shm.rating_key
                           where _utilities.UnixTimestampToDateTime(sh.started) > DateTime.Now.AddDays(-7)
                           where shm.section_id == 3
                           group shm by shm.title
                           into g
                           select new
                {
                    title = g.Key,
                    count = g.Count()
                }).Take(5);

                var result = "Most viewed movies\n";
                foreach (var movie in mvm.OrderByDescending(x => x.count))
                {
                    result = result + (movie.title + " views: " + movie.count + "\n");
                }
                return(result);
            }
        }