2013-04-21 01:36:23 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Marr.Data;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.SeriesStats
|
|
|
|
|
{
|
|
|
|
|
public interface ISeriesStatisticsRepository
|
|
|
|
|
{
|
|
|
|
|
List<SeriesStatistics> SeriesStatistics();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SeriesStatisticsRepository : ISeriesStatisticsRepository
|
|
|
|
|
{
|
|
|
|
|
private readonly IDataMapper _dataMapper;
|
|
|
|
|
|
|
|
|
|
public SeriesStatisticsRepository(IDatabase database)
|
|
|
|
|
{
|
|
|
|
|
_dataMapper = database.DataMapper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SeriesStatistics> SeriesStatistics()
|
|
|
|
|
{
|
|
|
|
|
_dataMapper.AddParameter("currentDate", DateTime.UtcNow);
|
|
|
|
|
|
|
|
|
|
var queryText = @"SELECT
|
|
|
|
|
SeriesId,
|
2013-07-09 03:22:02 +02: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 03:21:24 +02:00
|
|
|
|
MAX(Episodes.SeasonNumber) as SeasonCount,
|
2013-04-21 01:36:23 +02:00
|
|
|
|
MIN(CASE WHEN AirDate < @currentDate THEN NULL ELSE AirDate END) as NextAiringString
|
|
|
|
|
FROM Episodes
|
|
|
|
|
GROUP BY SeriesId";
|
|
|
|
|
|
|
|
|
|
return _dataMapper.Query<SeriesStatistics>(queryText);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|