|
|
@ -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(),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|