Added more to the stats, user stats is now available via the api !wip

This commit is contained in:
TidusJar 2018-08-02 13:34:28 +01:00
commit 17c78b48a5
4 changed files with 40 additions and 23 deletions

View file

@ -0,0 +1,9 @@
using System.Threading.Tasks;
namespace Ombi.Core.Engine
{
public interface IUserStatsEngine
{
Task<UserStatsSummary> GetSummary(SummaryRequest request);
}
}

View file

@ -10,7 +10,7 @@ using Ombi.Store.Repository.Requests;
namespace Ombi.Core.Engine
{
public class UserStatsEngine
public class UserStatsEngine : IUserStatsEngine
{
public UserStatsEngine(OmbiUserManager um, IMovieRequestRepository movieRequest, ITvRequestRepository tvRequest)
{
@ -25,27 +25,6 @@ namespace Ombi.Core.Engine
public async Task<UserStatsSummary> GetSummary(SummaryRequest request)
{
/* What do we want?
This is Per week/month/all time (filter by date)
1. Total Requests
2. Total Movie Requests
3. Total Tv Requests
4. Total Issues (If enabled)
5. Total Requests fufilled (now available)
Then
2. Most requested user Movie
3. Most requested user tv
Then
1.
*/
// get all movie requests
var movies = _movieRequest.GetWithUser();
var filteredMovies = movies.Where(x => x.RequestedDate >= request.From && x.RequestedDate <= request.To);
@ -84,7 +63,7 @@ namespace Ombi.Core.Engine
public class UserStatsSummary
{
public int TotalRequests => TotalTvRequests + TotalTvRequests;
public int TotalRequests => TotalTvRequests + TotalMovieRequests;
public int TotalMovieRequests { get; set; }
public int TotalTvRequests { get; set; }
public int TotalIssues { get; set; }

View file

@ -79,6 +79,7 @@ namespace Ombi.DependencyInjection
services.AddTransient<ITvRequestEngine, TvRequestEngine>();
services.AddTransient<ITvSearchEngine, TvSearchEngine>();
services.AddTransient<IRuleEvaluator, RuleEvaluator>();
services.AddTransient<IUserStatsEngine, UserStatsEngine>();
services.AddTransient<IMovieSender, MovieSender>();
services.AddTransient<IRecentlyAddedEngine, RecentlyAddedEngine>();
services.AddTransient<ITvSender, TvSender>();

View file

@ -0,0 +1,28 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Ombi.Attributes;
using Ombi.Core.Engine;
namespace Ombi.Controllers
{
[ApiV1]
[Admin]
[Authorize]
[Produces("application/json")]
public class StatsController : Controller
{
public StatsController(IUserStatsEngine eng)
{
_statsEngine = eng;
}
private readonly IUserStatsEngine _statsEngine;
[HttpGet]
public async Task<UserStatsSummary> GetUserStats(SummaryRequest req)
{
return await _statsEngine.GetSummary(req);
}
}
}