From e54ec746d677515589f08002b8875d58f2a38bf1 Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Mon, 19 Aug 2019 16:30:54 +0100 Subject: [PATCH] small wip changes --- .../Engine/UserStatsEngineTests.cs | 49 +++++++++++++++++++ src/Ombi.Core/Engine/UserStatsEngine.cs | 22 ++++----- src/Ombi.Core/Engine/V2/CalendarEngine.cs | 42 ++++++++++------ .../Engine/V2/MusicSearchEngineV2.cs | 8 --- .../Models/Search/V2/CalendarViewModel.cs | 3 ++ .../Entities/Requests/MovieRequests.cs | 2 +- .../Entities/Requests/SeasonRequests.cs | 24 +++++++++ 7 files changed, 113 insertions(+), 37 deletions(-) create mode 100644 src/Ombi.Core.Tests/Engine/UserStatsEngineTests.cs diff --git a/src/Ombi.Core.Tests/Engine/UserStatsEngineTests.cs b/src/Ombi.Core.Tests/Engine/UserStatsEngineTests.cs new file mode 100644 index 000000000..960082066 --- /dev/null +++ b/src/Ombi.Core.Tests/Engine/UserStatsEngineTests.cs @@ -0,0 +1,49 @@ + + +using System; +using System.Threading.Tasks; +using AutoFixture; +using Moq; +using NUnit.Framework; +using Ombi.Core.Engine; +using Ombi.Store.Entities.Requests; +using Ombi.Store.Repository.Requests; + +namespace Ombi.Core.Tests.Engine +{ + [TestFixture] + public class UserStatsEngineTests + { + private UserStatsEngine _engine; + private Mock _movieRequestRepo; + private Mock _tvRequestRepo; + + [SetUp] + public void Setup() + { + _movieRequestRepo = new Mock(); + _tvRequestRepo = new Mock(); + _engine = new UserStatsEngine(_movieRequestRepo.Object, _tvRequestRepo.Object); + } + + [Test] + [Ignore("Needs some more work")] + public async Task Test() + { + var f = new Fixture(); + f.Build().With(x => x.Available, true).CreateMany(200); + var result = await _engine.GetSummary(new SummaryRequest + { + From = new DateTime(2019,08,01), + To = new DateTime(2019,09,01) + }); + + Assert.That(result.CompletedRequests, Is.EqualTo(200)); + Assert.That(result.TotalRequests, Is.EqualTo(400)); + Assert.That(result.TotalMovieRequests, Is.EqualTo(200)); + Assert.That(result.TotalTvRequests, Is.EqualTo(200)); + Assert.That(result.CompletedRequestsMovies, Is.EqualTo(100)); + Assert.That(result.CompletedRequestsTv, Is.EqualTo(100)); + } + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Engine/UserStatsEngine.cs b/src/Ombi.Core/Engine/UserStatsEngine.cs index 06ab65f92..6b26591f4 100644 --- a/src/Ombi.Core/Engine/UserStatsEngine.cs +++ b/src/Ombi.Core/Engine/UserStatsEngine.cs @@ -12,14 +12,12 @@ namespace Ombi.Core.Engine { public class UserStatsEngine : IUserStatsEngine { - public UserStatsEngine(OmbiUserManager um, IMovieRequestRepository movieRequest, ITvRequestRepository tvRequest) + public UserStatsEngine(IMovieRequestRepository movieRequest, ITvRequestRepository tvRequest) { - _userManager = um; _movieRequest = movieRequest; _tvRequest = tvRequest; } - private readonly OmbiUserManager _userManager; private readonly IMovieRequestRepository _movieRequest; private readonly ITvRequestRepository _tvRequest; @@ -31,26 +29,24 @@ namespace Ombi.Core.Engine var tv = _tvRequest.GetLite(); var children = tv.SelectMany(x => x.ChildRequests.Where(c => c.RequestedDate >= request.From && c.RequestedDate <= request.To)); + + var userMovie = filteredMovies.GroupBy(x => x.RequestedUserId).OrderBy(x => x.Key).FirstOrDefaultAsync(); + var userTv = children.GroupBy(x => x.RequestedUserId).OrderBy(x => x.Key).FirstOrDefaultAsync(); var moviesCount = filteredMovies.CountAsync(); var childrenCount = children.CountAsync(); var availableMovies = - movies.Select(x => x.MarkedAsAvailable >= request.From && x.MarkedAsAvailable <= request.To).CountAsync(); - var availableChildren = tv.SelectMany(x => - x.ChildRequests.Where(c => c.MarkedAsAvailable >= request.From && c.MarkedAsAvailable <= request.To)).CountAsync(); - - var userMovie = filteredMovies.GroupBy(x => x.RequestedUserId).OrderBy(x => x.Key).FirstOrDefaultAsync(); - var userTv = children.GroupBy(x => x.RequestedUserId).OrderBy(x => x.Key).FirstOrDefaultAsync(); - - + filteredMovies.Select(x => x.MarkedAsAvailable >= request.From && x.MarkedAsAvailable <= request.To).CountAsync(); + var availableChildren = children.Where(c => c.MarkedAsAvailable >= request.From && c.MarkedAsAvailable <= request.To).CountAsync(); + return new UserStatsSummary { TotalMovieRequests = await moviesCount, TotalTvRequests = await childrenCount, CompletedRequestsTv = await availableChildren, CompletedRequestsMovies = await availableMovies, - MostRequestedUserMovie = (await userMovie).FirstOrDefault().RequestedUser, - MostRequestedUserTv = (await userTv).FirstOrDefault().RequestedUser, + MostRequestedUserMovie = (await userMovie).FirstOrDefault()?.RequestedUser ?? new OmbiUser(), + MostRequestedUserTv = (await userTv).FirstOrDefault()?.RequestedUser ?? new OmbiUser(), }; } } diff --git a/src/Ombi.Core/Engine/V2/CalendarEngine.cs b/src/Ombi.Core/Engine/V2/CalendarEngine.cs index f4b63beb2..4b3618780 100644 --- a/src/Ombi.Core/Engine/V2/CalendarEngine.cs +++ b/src/Ombi.Core/Engine/V2/CalendarEngine.cs @@ -3,12 +3,10 @@ using System.Collections.Generic; using System.Linq; using System.Security.Principal; using System.Threading.Tasks; -using Ombi.Api.Sonarr.Models; using Ombi.Core.Authentication; using Ombi.Core.Engine.Interfaces; using Ombi.Core.Models.Search.V2; using Ombi.Core.Rule.Interfaces; -using Ombi.Helpers; using Ombi.Store.Entities; using Ombi.Store.Entities.Requests; using Ombi.Store.Repository.Requests; @@ -46,27 +44,41 @@ namespace Ombi.Core.Engine.V2 BackgroundColor = GetBackgroundColor(e), ExtraParams = new List { - new ExtraParams { Overview = e.Season?.ChildRequest?.ParentRequest?.Overview ?? string.Empty, ProviderId = e.Season?.ChildRequest?.ParentRequest?.TvDbId ?? 0} + new ExtraParams + { + Overview = e.Season?.ChildRequest?.ParentRequest?.Overview ?? string.Empty, + ProviderId = e.Season?.ChildRequest?.ParentRequest?.TvDbId ?? 0, + Type = RequestType.TvShow, + ReleaseDate = e.AirDate, + RequestStatus = e.RequestStatus + } } }); } foreach (var m in movies) - { - viewModel.Add(new CalendarViewModel - { - Title = m.Title, - Start = m.ReleaseDate.Date, - BackgroundColor = GetBackgroundColor(m), - Type = RequestType.Movie, - ExtraParams = new List + { + viewModel.Add(new CalendarViewModel + { + Title = m.Title, + Start = m.ReleaseDate.Date, + BackgroundColor = GetBackgroundColor(m), + Type = RequestType.Movie, + ExtraParams = new List { - new ExtraParams { Overview = m.Overview, ProviderId = m.TheMovieDbId} + new ExtraParams + { + Overview = m.Overview, + ProviderId = m.TheMovieDbId, + Type = RequestType.Movie, + ReleaseDate = m.ReleaseDate, + RequestStatus = m.RequestStatus + } } - }); - } + }); + } - return viewModel; + return viewModel; } private string GetBackgroundColor(BaseRequest req) diff --git a/src/Ombi.Core/Engine/V2/MusicSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/MusicSearchEngineV2.cs index e413174cf..dd132a460 100644 --- a/src/Ombi.Core/Engine/V2/MusicSearchEngineV2.cs +++ b/src/Ombi.Core/Engine/V2/MusicSearchEngineV2.cs @@ -106,18 +106,10 @@ namespace Ombi.Core.Engine.V2 foreach (var cover in art.images) { - //if ((cover.thumbnails?.px250 ?? string.Empty).HasValue()) - //{ - // return new AlbumArt(cover.thumbnails.px250); - //} if ((cover.thumbnails?.small ?? string.Empty).HasValue()) { return new AlbumArt(cover.thumbnails.small); } - //if ((cover.thumbnails?.px500 ?? string.Empty).HasValue()) - //{ - // return new AlbumArt(cover.thumbnails.px500); - //} if ((cover.thumbnails?.large ?? string.Empty).HasValue()) { return new AlbumArt(cover.thumbnails.large); diff --git a/src/Ombi.Core/Models/Search/V2/CalendarViewModel.cs b/src/Ombi.Core/Models/Search/V2/CalendarViewModel.cs index 3cdedce7c..9e7c50b56 100644 --- a/src/Ombi.Core/Models/Search/V2/CalendarViewModel.cs +++ b/src/Ombi.Core/Models/Search/V2/CalendarViewModel.cs @@ -35,5 +35,8 @@ namespace Ombi.Core.Models.Search.V2 { public int ProviderId { get; set; } public string Overview { get; set; } + public RequestType Type { get; set; } + public DateTime ReleaseDate { get; set; } + public string RequestStatus { get; set; } } } \ No newline at end of file diff --git a/src/Ombi.Store/Entities/Requests/MovieRequests.cs b/src/Ombi.Store/Entities/Requests/MovieRequests.cs index 8075ba9bc..93853fbfd 100644 --- a/src/Ombi.Store/Entities/Requests/MovieRequests.cs +++ b/src/Ombi.Store/Entities/Requests/MovieRequests.cs @@ -38,7 +38,7 @@ namespace Ombi.Store.Entities.Requests public string RequestStatus { get { - if (Approved & Available) + if (Available) { return "Common.Available"; } diff --git a/src/Ombi.Store/Entities/Requests/SeasonRequests.cs b/src/Ombi.Store/Entities/Requests/SeasonRequests.cs index ea9f74547..b33634db1 100644 --- a/src/Ombi.Store/Entities/Requests/SeasonRequests.cs +++ b/src/Ombi.Store/Entities/Requests/SeasonRequests.cs @@ -34,5 +34,29 @@ namespace Ombi.Store.Repository.Requests public SeasonRequests Season { get; set; } [NotMapped] public string AirDateDisplay => AirDate == DateTime.MinValue ? "Unknown" : AirDate.ToString(CultureInfo.InvariantCulture); + + [NotMapped] + public string RequestStatus + { + get + { + if (Available) + { + return "Common.Available"; + } + + if (Approved & !Available) + { + return "Common.ProcessingRequest"; + } + + if (!Approved && !Available) + { + return "Common.PendingApproval"; + } + + return string.Empty; + } + } } } \ No newline at end of file