diff --git a/DiscImageChef.Server/Controllers/StatsController.cs b/DiscImageChef.Server/Controllers/StatsController.cs index 416e31e8..bce39f09 100644 --- a/DiscImageChef.Server/Controllers/StatsController.cs +++ b/DiscImageChef.Server/Controllers/StatsController.cs @@ -131,36 +131,11 @@ namespace DiscImageChef.Server.Controllers } if(ctx.Commands.Any()) - { ViewBag.repCommands = ctx.Commands.OrderBy(c => c.Name).ToList(); - decimal totalCommandCount = ctx.Commands.Sum(o => o.Count); - - ViewData["commandsPieData"] = ctx.Commands.Select(command => new PieSeriesData - { - Name = command.Name, Y = (double?)(command.Count / totalCommandCount), - Sliced = command.Name == "analyze", Selected = command.Name == "analyze" - }).ToList(); - } - if(ctx.Filters.Any()) - { ViewBag.repFilters = ctx.Filters.OrderBy(filter => filter.Name).ToList(); - List filtersPieData = new List(); - - decimal totalFiltersCount = ctx.Filters.Sum(o => o.Count); - - foreach(Filter filter in ctx.Filters.ToList()) - filtersPieData.Add(new PieSeriesData - { - Name = filter.Name, Y = (double?)(filter.Count / totalFiltersCount), - Sliced = filter.Name == "No filter", Selected = filter.Name == "No filter" - }); - - ViewData["filtersPieData"] = filtersPieData; - } - if(ctx.MediaFormats.Any()) { ViewBag.repMediaImages = ctx.MediaFormats.OrderBy(filter => filter.Name).ToList(); @@ -584,5 +559,23 @@ namespace DiscImageChef.Server.Controllers return Json(result); } + + public IActionResult GetFiltersData() + { + string[][] result = + { + ctx.Filters.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), + ctx.Filters.OrderByDescending(o => o.Count).Take(10).Select(x => x.Count.ToString()).ToArray() + }; + + if(result[0].Length < 10) + return Json(result); + + result[0][9] = "Other"; + + result[1][9] = (ctx.Filters.Sum(o => o.Count) - result[1].Take(9).Sum(long.Parse)).ToString(); + + return Json(result); + } } } \ No newline at end of file diff --git a/DiscImageChef.Server/Views/Stats/Index.cshtml b/DiscImageChef.Server/Views/Stats/Index.cshtml index 546b8218..d1f1b11b 100644 --- a/DiscImageChef.Server/Views/Stats/Index.cshtml +++ b/DiscImageChef.Server/Views/Stats/Index.cshtml @@ -185,7 +185,8 @@ @if (ViewBag.repFilters != null) {
-
+
+
@@ -571,6 +572,11 @@ function DrawCommandsPie(commandsData) DrawPie("commandsChart", `Top ${commandsData[0].length} used commands`, commandsData[0], commandsData[1]) } +function DrawFiltersPie(filtersData) +{ + DrawPie("filtersChart", `Top ${filtersData[0].length} filters found`, filtersData[0], filtersData[1]) +} + window.onload = () => { $.ajax({dataType: "json", url: "/Stats/GetOsData", success: DrawOsPie, cache:false}); $.ajax({dataType: "json", url: "/Stats/GetLinuxData", success: DrawLinuxPie, cache:false}); @@ -578,6 +584,7 @@ window.onload = () => { $.ajax({dataType: "json", url: "/Stats/GetWindowsData", success: DrawWindowsPie, cache:false}); $.ajax({dataType: "json", url: "/Stats/GetVersionsData", success: DrawVersionsPie, cache:false}); $.ajax({dataType: "json", url: "/Stats/GetCommandsData", success: DrawCommandsPie, cache:false}); + $.ajax({dataType: "json", url: "/Stats/GetFiltersData", success: DrawFiltersPie, cache:false}); } \ No newline at end of file