fixed series statistics query.

This commit is contained in:
kay.one 2013-04-20 14:23:17 -07:00
parent 373a93be64
commit 4afec69c79
6 changed files with 30 additions and 9 deletions

View File

@ -1,16 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Marr.Data;
using Marr.Data.Mapping;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Datastore
{
public static class MappingExtensions
{
public static ColumnMapBuilder<T> RegisterModel<T>(this FluentMappings.MappingsFluentEntity<T> mapBuilder, string tableName) where T : ModelBase
public static ColumnMapBuilder<T> MapResultSet<T>(this FluentMappings.MappingsFluentEntity<T> mapBuilder) where T : ResultSet, new()
{
return mapBuilder
.Columns
.AutoMapPropertiesWhere(IsMappableProperty);
}
public static ColumnMapBuilder<T> RegisterModel<T>(this FluentMappings.MappingsFluentEntity<T> mapBuilder, string tableName = null) where T : ModelBase, new()
{
return mapBuilder.Table.MapTable(tableName)
.Columns
.AutoMapPropertiesWhere(IsMappableProperty)

View File

@ -0,0 +1,6 @@
namespace NzbDrone.Core.Datastore
{
public class ResultSet
{
}
}

View File

@ -57,9 +57,7 @@ namespace NzbDrone.Core.Datastore
Mapper.Entity<Log>().RegisterModel("Logs");
Mapper.Entity<SeriesStatistics>()
.Columns
.AutoMapPropertiesWhere(MappingExtensions.IsMappableProperty);
Mapper.Entity<SeriesStatistics>().MapResultSet();
}

View File

@ -356,6 +356,7 @@
<Compile Include="Tv\Events\SeriesAddedEvent.cs" />
<Compile Include="Tv\Events\SeriesDeletedEvent.cs" />
<Compile Include="Tv\Events\SeriesUpdatedEvent.cs" />
<Compile Include="Datastore\ResultSet.cs" />
<Compile Include="Tv\SeasonRepository.cs" />
<Compile Include="Tv\SeriesRepository.cs" />
<Compile Include="Tv\QualityModel.cs" />

View File

@ -65,7 +65,7 @@ namespace NzbDrone.Core.Tv
SUM(CASE WHEN Airdate <= @currentDate THEN 1 ELSE 0 END) AS EpisodeCount,
SUM(CASE WHEN EpisodeFileId > 0 AND AirDate <= @currentDate THEN 1 ELSE 0 END) as EpisodeFileCount,
MAX(SeasonNumber) as NumberOfSeasons,
MIN(CASE WHEN AirDate < @currentDate THEN NULL ELSE AirDate END) as NextAiring
MIN(CASE WHEN AirDate < @currentDate THEN NULL ELSE AirDate END) as NextAiringString
FROM Episodes
WHERE Ignored = 0
GROUP BY SeriesId";

View File

@ -1,12 +1,17 @@
using System;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Tv
{
public class SeriesStatistics
public class SeriesStatistics : ResultSet
{
public int SeriesId { get; set; }
public int NumberOfSeasons { get; set; }
public DateTime? NextAiring { get; set; }
public string NextAiringString { get; set; }
public DateTime? NextAiring
{
get { return Convert.ToDateTime(NextAiringString); }
}
public int EpisodeFileCount { get; set; }
public int EpisodeCount { get; set; }
}