small wip changes

pull/3895/head
Jamie Rees 5 years ago
parent 4b7d7410ae
commit e54ec746d6

@ -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<IMovieRequestRepository> _movieRequestRepo;
private Mock<ITvRequestRepository> _tvRequestRepo;
[SetUp]
public void Setup()
{
_movieRequestRepo = new Mock<IMovieRequestRepository>();
_tvRequestRepo = new Mock<ITvRequestRepository>();
_engine = new UserStatsEngine(_movieRequestRepo.Object, _tvRequestRepo.Object);
}
[Test]
[Ignore("Needs some more work")]
public async Task Test()
{
var f = new Fixture();
f.Build<MovieRequests>().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));
}
}
}

@ -12,14 +12,12 @@ namespace Ombi.Core.Engine
{ {
public class UserStatsEngine : IUserStatsEngine public class UserStatsEngine : IUserStatsEngine
{ {
public UserStatsEngine(OmbiUserManager um, IMovieRequestRepository movieRequest, ITvRequestRepository tvRequest) public UserStatsEngine(IMovieRequestRepository movieRequest, ITvRequestRepository tvRequest)
{ {
_userManager = um;
_movieRequest = movieRequest; _movieRequest = movieRequest;
_tvRequest = tvRequest; _tvRequest = tvRequest;
} }
private readonly OmbiUserManager _userManager;
private readonly IMovieRequestRepository _movieRequest; private readonly IMovieRequestRepository _movieRequest;
private readonly ITvRequestRepository _tvRequest; private readonly ITvRequestRepository _tvRequest;
@ -31,26 +29,24 @@ namespace Ombi.Core.Engine
var tv = _tvRequest.GetLite(); var tv = _tvRequest.GetLite();
var children = tv.SelectMany(x => var children = tv.SelectMany(x =>
x.ChildRequests.Where(c => c.RequestedDate >= request.From && c.RequestedDate <= request.To)); 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 moviesCount = filteredMovies.CountAsync();
var childrenCount = children.CountAsync(); var childrenCount = children.CountAsync();
var availableMovies = var availableMovies =
movies.Select(x => x.MarkedAsAvailable >= request.From && x.MarkedAsAvailable <= request.To).CountAsync(); filteredMovies.Select(x => x.MarkedAsAvailable >= request.From && x.MarkedAsAvailable <= request.To).CountAsync();
var availableChildren = tv.SelectMany(x => var availableChildren = children.Where(c => c.MarkedAsAvailable >= request.From && c.MarkedAsAvailable <= request.To).CountAsync();
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();
return new UserStatsSummary return new UserStatsSummary
{ {
TotalMovieRequests = await moviesCount, TotalMovieRequests = await moviesCount,
TotalTvRequests = await childrenCount, TotalTvRequests = await childrenCount,
CompletedRequestsTv = await availableChildren, CompletedRequestsTv = await availableChildren,
CompletedRequestsMovies = await availableMovies, CompletedRequestsMovies = await availableMovies,
MostRequestedUserMovie = (await userMovie).FirstOrDefault().RequestedUser, MostRequestedUserMovie = (await userMovie).FirstOrDefault()?.RequestedUser ?? new OmbiUser(),
MostRequestedUserTv = (await userTv).FirstOrDefault().RequestedUser, MostRequestedUserTv = (await userTv).FirstOrDefault()?.RequestedUser ?? new OmbiUser(),
}; };
} }
} }

@ -3,12 +3,10 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Principal; using System.Security.Principal;
using System.Threading.Tasks; using System.Threading.Tasks;
using Ombi.Api.Sonarr.Models;
using Ombi.Core.Authentication; using Ombi.Core.Authentication;
using Ombi.Core.Engine.Interfaces; using Ombi.Core.Engine.Interfaces;
using Ombi.Core.Models.Search.V2; using Ombi.Core.Models.Search.V2;
using Ombi.Core.Rule.Interfaces; using Ombi.Core.Rule.Interfaces;
using Ombi.Helpers;
using Ombi.Store.Entities; using Ombi.Store.Entities;
using Ombi.Store.Entities.Requests; using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository.Requests; using Ombi.Store.Repository.Requests;
@ -46,27 +44,41 @@ namespace Ombi.Core.Engine.V2
BackgroundColor = GetBackgroundColor(e), BackgroundColor = GetBackgroundColor(e),
ExtraParams = new List<ExtraParams> ExtraParams = new List<ExtraParams>
{ {
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) foreach (var m in movies)
{ {
viewModel.Add(new CalendarViewModel viewModel.Add(new CalendarViewModel
{ {
Title = m.Title, Title = m.Title,
Start = m.ReleaseDate.Date, Start = m.ReleaseDate.Date,
BackgroundColor = GetBackgroundColor(m), BackgroundColor = GetBackgroundColor(m),
Type = RequestType.Movie, Type = RequestType.Movie,
ExtraParams = new List<ExtraParams> ExtraParams = new List<ExtraParams>
{ {
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) private string GetBackgroundColor(BaseRequest req)

@ -106,18 +106,10 @@ namespace Ombi.Core.Engine.V2
foreach (var cover in art.images) 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()) if ((cover.thumbnails?.small ?? string.Empty).HasValue())
{ {
return new AlbumArt(cover.thumbnails.small); 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()) if ((cover.thumbnails?.large ?? string.Empty).HasValue())
{ {
return new AlbumArt(cover.thumbnails.large); return new AlbumArt(cover.thumbnails.large);

@ -35,5 +35,8 @@ namespace Ombi.Core.Models.Search.V2
{ {
public int ProviderId { get; set; } public int ProviderId { get; set; }
public string Overview { get; set; } public string Overview { get; set; }
public RequestType Type { get; set; }
public DateTime ReleaseDate { get; set; }
public string RequestStatus { get; set; }
} }
} }

@ -38,7 +38,7 @@ namespace Ombi.Store.Entities.Requests
public string RequestStatus { public string RequestStatus {
get get
{ {
if (Approved & Available) if (Available)
{ {
return "Common.Available"; return "Common.Available";
} }

@ -34,5 +34,29 @@ namespace Ombi.Store.Repository.Requests
public SeasonRequests Season { get; set; } public SeasonRequests Season { get; set; }
[NotMapped] public string AirDateDisplay => AirDate == DateTime.MinValue ? "Unknown" : AirDate.ToString(CultureInfo.InvariantCulture); [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;
}
}
} }
} }
Loading…
Cancel
Save