2012-04-25 22:50:37 +03:00
|
|
|
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<Series>();
|
|
|
|
var episodes = _database.Fetch<Episode>();
|
2012-10-11 10:46:38 +03:00
|
|
|
var history = _database.Fetch<History>("WHERE Date >= @0", DateTime.Today.AddDays(-30));
|
2012-04-25 22:50:37 +03:00
|
|
|
|
|
|
|
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;
|
2012-10-11 10:46:38 +03:00
|
|
|
stats.DownloadLastWeek = history.Count(h => h.Date >= DateTime.Today.AddDays(-7));
|
2012-04-25 22:50:37 +03:00
|
|
|
|
|
|
|
return stats;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|