Ejemplo n.º 1
0
        public NetflixPlaybacksViewModel GetNetflixPlaybacksViewModel(IEnumerable <NetflixPlayback> viewingHistory)
        {
            var statsCalculator = new NetflixStatsCalculator(viewingHistory);

            return(new NetflixPlaybacksViewModel
            {
                Playbacks = viewingHistory.OrderByDescending(x => x.Sort),
                TotalPlaybackTime = Time.FromMinutes(statsCalculator.GetTotalViewedMinutes()),
                PlaybackDate = viewingHistory.FirstOrDefault().PlaybackDateTime.Date,
            });
        }
Ejemplo n.º 2
0
        public NetflixStatsViewModel GetNetflixStatsViewModel(IEnumerable <NetflixPlayback> viewingHistory)
        {
            var statsCalculator = new NetflixStatsCalculator(viewingHistory);

            var viewedHoursPerSerie = statsCalculator.GetViewedMinutesPerSerie()
                                      .OrderByDescending(x => x.Value)
                                      .DistinctBy(x => x.Key.Title)
                                      .ToDictionary(x => $"{x.Key.Title ?? "Movies"}", y => (double)Math.Round(y.Value / 60, 2));

            var viewedHoursPerDay = statsCalculator.GetViewedMinutesPerDay()
                                    .OrderBy(x => x.Key)
                                    .ToDictionary(x => x.Key.ToString("yyyy-MM-dd"), y => (double)Math.Round(y.Value / 60, 2));

            var viewedHoursPerWeekDay = statsCalculator.GetViewedMinutesPerWeekDay()
                                        .OrderBy(x => x.Key)
                                        .ToDictionary(x => x.Key.ToString(), y => (double)Math.Round(y.Value / 60, 2));

            var viewedMinutesPerTimeOfDayTemp = statsCalculator.GetViewedMinutesPerTimeOfDay()
                                                .Select(x =>
                                                        new KeyValuePair <TimeSpan, double>(x.Key.RoundToNearest(TimeSpan.FromMinutes(15)), (double)Math.Round(x.Value / 60, 2)))
                                                .GroupBy(x => x.Key)
                                                .Select(x => new KeyValuePair <TimeSpan, double>(x.Key, x.Sum(y => y.Value)))
                                                .ToList();

            var totalViewedMinutes         = statsCalculator.GetTotalViewedMinutes();
            var viewedPercentagePerCountry = statsCalculator.GetViewedMinutesPerCountry()
                                             .ToDictionary(x => x.Key, y => (double)Math.Round(y.Value / totalViewedMinutes * 100, 3));

            var viewedMinutesPerTimeOfDay = GetKeyValuePairsForTimeOfDay(viewedMinutesPerTimeOfDayTemp)
                                            .ToDictionary(x => x.Key, y => y.Value);

            return(new NetflixStatsViewModel
            {
                TotalViewedTime = Time.FromMinutes(statsCalculator.GetTotalViewedMinutes()),
                MoviesViewedTime = Time.FromMinutes(statsCalculator.GetMoviesViewedMinutes()),
                SeriesViewedTime = Time.FromMinutes(statsCalculator.GetSeriesEpisodesViewedMinutes()),
                MoviesViewedCount = statsCalculator.GetMoviesViewedCount(),
                SeriesEpisodesViewedItemsCount = statsCalculator.GetSeriesEpisodesViewedCount(),
                FirstWatchedMovie = statsCalculator.GetFirstWatchedMovie(),
                FirstWatchedSeriesEpisode = statsCalculator.GetFirstWatchedSeriesEpisode(),
                ViewedHoursPerSerieChart = GetTimePerSerieChart(viewedHoursPerSerie),
                ViewedHoursPerDayChart = GetTimePerDayChart(viewedHoursPerDay),
                HourlyActivityChart = GetHourlyActivityChart(viewedMinutesPerTimeOfDay),
                WeekDailyActivityChart = GetWeekDailyWatchedChart(viewedHoursPerWeekDay),
                ViewedPercentagePerCountryChart = GetPercentagePerCountryChart(viewedPercentagePerCountry),
                HighscoreDate = statsCalculator.GetHighscoreDateAndMinutes().date,
                HighcoreTime = Time.FromMinutes(statsCalculator.GetHighscoreDateAndMinutes().minutes)
            });
        }