From 1d120be4665fb850ec3144fbef7d8e58f432d967 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 8 Oct 2017 14:55:52 -0400 Subject: [PATCH] Remove SeriesStats --- src/NzbDrone.Core/NzbDrone.Core.csproj | 4 - .../SeriesStats/SeasonStatistics.cs | 41 --------- .../SeriesStats/SeriesStatistics.cs | 43 ---------- .../SeriesStats/SeriesStatisticsRepository.cs | 83 ------------------- .../SeriesStats/SeriesStatisticsService.cs | 63 -------------- 5 files changed, 234 deletions(-) delete mode 100644 src/NzbDrone.Core/SeriesStats/SeasonStatistics.cs delete mode 100644 src/NzbDrone.Core/SeriesStats/SeriesStatistics.cs delete mode 100644 src/NzbDrone.Core/SeriesStats/SeriesStatisticsRepository.cs delete mode 100644 src/NzbDrone.Core/SeriesStats/SeriesStatisticsService.cs diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index f233e5e3f..387daa5c8 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -1132,10 +1132,6 @@ - - - - diff --git a/src/NzbDrone.Core/SeriesStats/SeasonStatistics.cs b/src/NzbDrone.Core/SeriesStats/SeasonStatistics.cs deleted file mode 100644 index 3b3731ed5..000000000 --- a/src/NzbDrone.Core/SeriesStats/SeasonStatistics.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using NzbDrone.Core.Datastore; - -namespace NzbDrone.Core.SeriesStats -{ - public class SeasonStatistics : ResultSet - { - public int SeriesId { get; set; } - public int SeasonNumber { get; set; } - public string NextAiringString { get; set; } - public string PreviousAiringString { get; set; } - public int EpisodeFileCount { get; set; } - public int EpisodeCount { get; set; } - public int TotalEpisodeCount { get; set; } - public long SizeOnDisk { get; set; } - - public DateTime? NextAiring - { - get - { - DateTime nextAiring; - - if (!DateTime.TryParse(NextAiringString, out nextAiring)) return null; - - return nextAiring; - } - } - - public DateTime? PreviousAiring - { - get - { - DateTime previousAiring; - - if (!DateTime.TryParse(PreviousAiringString, out previousAiring)) return null; - - return previousAiring; - } - } - } -} diff --git a/src/NzbDrone.Core/SeriesStats/SeriesStatistics.cs b/src/NzbDrone.Core/SeriesStats/SeriesStatistics.cs deleted file mode 100644 index 0542ca94b..000000000 --- a/src/NzbDrone.Core/SeriesStats/SeriesStatistics.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using NzbDrone.Core.Datastore; - -namespace NzbDrone.Core.SeriesStats -{ - public class SeriesStatistics : ResultSet - { - public int SeriesId { get; set; } - public string NextAiringString { get; set; } - public string PreviousAiringString { get; set; } - public int EpisodeFileCount { get; set; } - public int EpisodeCount { get; set; } - public int AvailableEpisodeCount { get; set; } - public int TotalEpisodeCount { get; set; } - public long SizeOnDisk { get; set; } - public List SeasonStatistics { get; set; } - - public DateTime? NextAiring - { - get - { - DateTime nextAiring; - - if (!DateTime.TryParse(NextAiringString, out nextAiring)) return null; - - return nextAiring; - } - } - - public DateTime? PreviousAiring - { - get - { - DateTime previousAiring; - - if (!DateTime.TryParse(PreviousAiringString, out previousAiring)) return null; - - return previousAiring; - } - } - } -} diff --git a/src/NzbDrone.Core/SeriesStats/SeriesStatisticsRepository.cs b/src/NzbDrone.Core/SeriesStats/SeriesStatisticsRepository.cs deleted file mode 100644 index a26e087d0..000000000 --- a/src/NzbDrone.Core/SeriesStats/SeriesStatisticsRepository.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using NzbDrone.Core.Datastore; - -namespace NzbDrone.Core.SeriesStats -{ - public interface ISeriesStatisticsRepository - { - List SeriesStatistics(); - List SeriesStatistics(int seriesId); - } - - public class SeriesStatisticsRepository : ISeriesStatisticsRepository - { - private readonly IMainDatabase _database; - - public SeriesStatisticsRepository(IMainDatabase database) - { - _database = database; - } - - public List SeriesStatistics() - { - var mapper = _database.GetDataMapper(); - - mapper.AddParameter("currentDate", DateTime.UtcNow); - - var sb = new StringBuilder(); - sb.AppendLine(GetSelectClause()); - sb.AppendLine(GetEpisodeFilesJoin()); - sb.AppendLine(GetGroupByClause()); - var queryText = sb.ToString(); - - return mapper.Query(queryText); - } - - public List SeriesStatistics(int seriesId) - { - var mapper = _database.GetDataMapper(); - - mapper.AddParameter("currentDate", DateTime.UtcNow); - mapper.AddParameter("seriesId", seriesId); - - var sb = new StringBuilder(); - sb.AppendLine(GetSelectClause()); - sb.AppendLine(GetEpisodeFilesJoin()); - sb.AppendLine("WHERE Episodes.SeriesId = @seriesId"); - sb.AppendLine(GetGroupByClause()); - var queryText = sb.ToString(); - - return mapper.Query(queryText); - } - - private string GetSelectClause() - { - return @"SELECT Episodes.*, SUM(EpisodeFiles.Size) as SizeOnDisk FROM - (SELECT - Episodes.SeriesId, - Episodes.SeasonNumber, - COUNT(*) AS TotalEpisodeCount, - SUM(CASE WHEN AirdateUtc <= @currentDate OR EpisodeFileId > 0 THEN 1 ELSE 0 END) AS AvailableEpisodeCount, - SUM(CASE WHEN (Monitored = 1 AND AirdateUtc <= @currentDate) OR EpisodeFileId > 0 THEN 1 ELSE 0 END) AS EpisodeCount, - SUM(CASE WHEN EpisodeFileId > 0 THEN 1 ELSE 0 END) AS EpisodeFileCount, - MIN(CASE WHEN AirDateUtc < @currentDate OR EpisodeFileId > 0 OR Monitored = 0 THEN NULL ELSE AirDateUtc END) AS NextAiringString, - MAX(CASE WHEN AirDateUtc >= @currentDate OR EpisodeFileId = 0 AND Monitored = 0 THEN NULL ELSE AirDateUtc END) AS PreviousAiringString - FROM Episodes - GROUP BY Episodes.SeriesId, Episodes.SeasonNumber) as Episodes"; - } - - private string GetGroupByClause() - { - return "GROUP BY Episodes.SeriesId, Episodes.SeasonNumber"; - } - - private string GetEpisodeFilesJoin() - { - return @"LEFT OUTER JOIN EpisodeFiles - ON EpisodeFiles.SeriesId = Episodes.SeriesId - AND EpisodeFiles.SeasonNumber = Episodes.SeasonNumber"; - } - } -} diff --git a/src/NzbDrone.Core/SeriesStats/SeriesStatisticsService.cs b/src/NzbDrone.Core/SeriesStats/SeriesStatisticsService.cs deleted file mode 100644 index b273f84ce..000000000 --- a/src/NzbDrone.Core/SeriesStats/SeriesStatisticsService.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace NzbDrone.Core.SeriesStats -{ - public interface ISeriesStatisticsService - { - List SeriesStatistics(); - SeriesStatistics SeriesStatistics(int seriesId); - } - - public class SeriesStatisticsService : ISeriesStatisticsService - { - private readonly ISeriesStatisticsRepository _seriesStatisticsRepository; - - public SeriesStatisticsService(ISeriesStatisticsRepository seriesStatisticsRepository) - { - _seriesStatisticsRepository = seriesStatisticsRepository; - } - - public List SeriesStatistics() - { - var seasonStatistics = _seriesStatisticsRepository.SeriesStatistics(); - - return seasonStatistics.GroupBy(s => s.SeriesId).Select(s => MapSeriesStatistics(s.ToList())).ToList(); - } - - public SeriesStatistics SeriesStatistics(int seriesId) - { - var stats = _seriesStatisticsRepository.SeriesStatistics(seriesId); - - if (stats == null || stats.Count == 0) return new SeriesStatistics(); - - return MapSeriesStatistics(stats); - } - - private SeriesStatistics MapSeriesStatistics(List seasonStatistics) - { - var seriesStatistics = new SeriesStatistics - { - SeasonStatistics = seasonStatistics, - SeriesId = seasonStatistics.First().SeriesId, - EpisodeFileCount = seasonStatistics.Sum(s => s.EpisodeFileCount), - EpisodeCount = seasonStatistics.Sum(s => s.EpisodeCount), - TotalEpisodeCount = seasonStatistics.Sum(s => s.TotalEpisodeCount), - SizeOnDisk = seasonStatistics.Sum(s => s.SizeOnDisk) - }; - - var nextAiring = seasonStatistics.Where(s => s.NextAiring != null) - .OrderBy(s => s.NextAiring) - .FirstOrDefault(); - - var previousAiring = seasonStatistics.Where(s => s.PreviousAiring != null) - .OrderBy(s => s.PreviousAiring) - .LastOrDefault(); - - seriesStatistics.NextAiringString = nextAiring != null ? nextAiring.NextAiringString : null; - seriesStatistics.PreviousAiringString = previousAiring != null ? previousAiring.PreviousAiringString : null; - - return seriesStatistics; - } - } -}