2013-04-21 02:36:23 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.SeriesStats
|
|
|
|
{
|
|
|
|
public interface ISeriesStatisticsRepository
|
|
|
|
{
|
|
|
|
List<SeriesStatistics> SeriesStatistics();
|
|
|
|
}
|
|
|
|
|
|
|
|
public class SeriesStatisticsRepository : ISeriesStatisticsRepository
|
|
|
|
{
|
2013-07-16 03:45:49 +03:00
|
|
|
private readonly IDatabase _database;
|
2013-04-21 02:36:23 +03:00
|
|
|
|
|
|
|
public SeriesStatisticsRepository(IDatabase database)
|
|
|
|
{
|
2013-07-16 03:45:49 +03:00
|
|
|
_database = database;
|
2013-04-21 02:36:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<SeriesStatistics> SeriesStatistics()
|
|
|
|
{
|
2013-07-16 03:45:49 +03:00
|
|
|
var mapper = _database.GetDataMapper();
|
2013-04-21 02:36:23 +03:00
|
|
|
|
2013-07-16 03:45:49 +03:00
|
|
|
mapper.AddParameter("currentDate", DateTime.UtcNow);
|
|
|
|
|
|
|
|
const string queryText = @"SELECT
|
2013-04-21 02:36:23 +03:00
|
|
|
SeriesId,
|
2013-07-09 04:22:02 +03:00
|
|
|
SUM(CASE WHEN Monitored = 1 AND Airdate <= @currentDate THEN 1 ELSE 0 END) AS EpisodeCount,
|
|
|
|
SUM(CASE WHEN Monitored = 1 AND Episodes.EpisodeFileId > 0 AND AirDate <= @currentDate THEN 1 ELSE 0 END) as EpisodeFileCount,
|
2013-04-22 04:21:24 +03:00
|
|
|
MAX(Episodes.SeasonNumber) as SeasonCount,
|
2013-04-21 02:36:23 +03:00
|
|
|
MIN(CASE WHEN AirDate < @currentDate THEN NULL ELSE AirDate END) as NextAiringString
|
|
|
|
FROM Episodes
|
|
|
|
GROUP BY SeriesId";
|
|
|
|
|
2013-07-16 03:45:49 +03:00
|
|
|
return mapper.Query<SeriesStatistics>(queryText);
|
2013-04-21 02:36:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|