mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
SeriesStats moved to its own Repo
This commit is contained in:
parent
98df1be981
commit
a04a5e8669
10 changed files with 92 additions and 41 deletions
38
NzbDrone.Core/SeriesStats/SeriesStatisticsRepository.cs
Normal file
38
NzbDrone.Core/SeriesStats/SeriesStatisticsRepository.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
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,
|
||||
SUM(CASE WHEN Ignored = 0 AND Airdate <= @currentDate THEN 1 ELSE 0 END) AS EpisodeCount,
|
||||
SUM(CASE WHEN Ignored = 0 AND Episodes.EpisodeFileId > 0 AND AirDate <= @currentDate THEN 1 ELSE 0 END) as EpisodeFileCount,
|
||||
MAX(Episodes.SeasonNumber) as NumberOfSeasons,
|
||||
MIN(CASE WHEN AirDate < @currentDate THEN NULL ELSE AirDate END) as NextAiringString
|
||||
FROM Episodes
|
||||
GROUP BY SeriesId";
|
||||
|
||||
return _dataMapper.Query<SeriesStatistics>(queryText);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue