diff --git a/NzbDrone.Core.Test/ParserTest.cs b/NzbDrone.Core.Test/ParserTest.cs index 538f8ce89..df838426e 100644 --- a/NzbDrone.Core.Test/ParserTest.cs +++ b/NzbDrone.Core.Test/ParserTest.cs @@ -164,7 +164,6 @@ namespace NzbDrone.Core.Test [TestCase("Pawn Stars S04E87 REPACK 720p HDTV x264 aAF", QualityTypes.HDTV, true)] [TestCase("The Real Housewives of Vancouver S01E04 DSR x264 2HD", QualityTypes.SDTV, false)] [TestCase("Vanguard S01E04 Mexicos Death Train DSR x264 MiNDTHEGAP", QualityTypes.SDTV, false)] - public void quality_parse(string postTitle, object quality, bool proper) { var result = Parser.ParseQuality(postTitle); diff --git a/NzbDrone.Core/Model/StatsModel.cs b/NzbDrone.Core/Model/StatsModel.cs new file mode 100644 index 000000000..a5d5fca9f --- /dev/null +++ b/NzbDrone.Core/Model/StatsModel.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; + +namespace NzbDrone.Core.Model +{ + public class StatsModel + { + [DisplayName("Number of Series")] + public int SeriesTotal { get; set; } + + [DisplayName("Number of Series Countinuing")] + public int SeriesContinuing { get; set; } + + [DisplayName("Number of Series Ended")] + public int SeriesEnded { get; set; } + + [DisplayName("Number of Episodes")] + public int EpisodesTotal { get; set; } + + [DisplayName("Number of Episodes On Disk")] + public int EpisodesOnDisk { get; set; } + + [DisplayName("Number of Episodes Missing")] + public int EpisodesMissing { get; set; } + + [DisplayName("Downloaded in the Last Week")] + public int DownloadLastWeek { get; set; } + + [DisplayName("Downloaded in the Last 30 days")] + public int DownloadedLastMonth { get; set; } + } +} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index aa0f193df..bca6ecde8 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -264,6 +264,7 @@ + @@ -305,6 +306,7 @@ Code + diff --git a/NzbDrone.Core/Providers/StatsProvider.cs b/NzbDrone.Core/Providers/StatsProvider.cs new file mode 100644 index 000000000..24d44fbb9 --- /dev/null +++ b/NzbDrone.Core/Providers/StatsProvider.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Ninject; +using NzbDrone.Core.Model; +using NzbDrone.Core.Repository; +using PetaPoco; + +namespace NzbDrone.Core.Providers +{ + public class StatsProvider + { + private readonly IDatabase _database; + + [Inject] + public StatsProvider(IDatabase database) + { + _database = database; + } + + public StatsProvider() + { + } + + public virtual StatsModel GetStats() + { + var series = _database.Fetch(); + var episodes = _database.Fetch(); + var history = _database.Fetch("WHERE Date <= @0", DateTime.Today.AddDays(-30)); + + var stats = new StatsModel(); + stats.SeriesTotal = series.Count; + stats.SeriesContinuing = series.Count(s => s.Status == "Continuing"); + stats.SeriesEnded = series.Count(s => s.Status == "Ended"); + stats.EpisodesTotal = episodes.Count; + stats.EpisodesOnDisk = episodes.Count(e => e.EpisodeFileId > 0); + stats.EpisodesMissing = episodes.Count(e => e.Ignored == false && e.EpisodeFileId == 0); + stats.DownloadedLastMonth = history.Count; + stats.DownloadLastWeek = history.Count(h => h.Date <= DateTime.Today.AddDays(7)); + + return stats; + } + } +} diff --git a/NzbDrone.Web/Controllers/SystemController.cs b/NzbDrone.Web/Controllers/SystemController.cs index da688d12e..f58fa99ae 100644 --- a/NzbDrone.Web/Controllers/SystemController.cs +++ b/NzbDrone.Web/Controllers/SystemController.cs @@ -22,16 +22,18 @@ namespace NzbDrone.Web.Controllers private readonly ConfigProvider _configProvider; private readonly DiskProvider _diskProvider; private readonly BackupProvider _backupProvider; + private readonly StatsProvider _statsProvider; public SystemController(JobProvider jobProvider, IndexerProvider indexerProvider, ConfigProvider configProvider, DiskProvider diskProvider, - BackupProvider backupProvider) + BackupProvider backupProvider, StatsProvider statsProvider) { _jobProvider = jobProvider; _indexerProvider = indexerProvider; _configProvider = configProvider; _diskProvider = diskProvider; _backupProvider = backupProvider; + _statsProvider = statsProvider; } public ActionResult Jobs() @@ -176,5 +178,12 @@ namespace NzbDrone.Web.Controllers return File(fileInfo.FullName, "application/binary", fileInfo.Name); } + + public ActionResult Stats() + { + var model = _statsProvider.GetStats(); + + return View(model); + } } } diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index a9241eb1d..eda9416e4 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -531,6 +531,9 @@ + + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/NzbDrone.Web/Views/System/Stats.cshtml b/NzbDrone.Web/Views/System/Stats.cshtml new file mode 100644 index 000000000..4c59e82bc --- /dev/null +++ b/NzbDrone.Web/Views/System/Stats.cshtml @@ -0,0 +1,41 @@ +@model NzbDrone.Core.Model.StatsModel + +@{ + ViewBag.Title = "Stats"; +} + +@section HeaderContent +{ + +} + +

Stats

+ +@Html.LabelFor(m => m.SeriesTotal): +@Html.DisplayTextFor(m => m.SeriesTotal) +
+@Html.LabelFor(m => m.SeriesContinuing): +@Html.DisplayTextFor(m => m.SeriesContinuing) +
+@Html.LabelFor(m => m.SeriesEnded): +@Html.DisplayTextFor(m => m.SeriesEnded) +
+@Html.LabelFor(m => m.EpisodesTotal): +@Html.DisplayTextFor(m => m.EpisodesTotal) +
+@Html.LabelFor(m => m.EpisodesOnDisk): +@Html.DisplayTextFor(m => m.EpisodesOnDisk) +
+@Html.LabelFor(m => m.EpisodesMissing): +@Html.DisplayTextFor(m => m.EpisodesMissing) +
+@Html.LabelFor(m => m.DownloadLastWeek): +@Html.DisplayTextFor(m => m.DownloadLastWeek) +
+@Html.LabelFor(m => m.DownloadedLastMonth): +@Html.DisplayTextFor(m => m.DownloadedLastMonth) \ No newline at end of file