From 1c4390a9a08464c84bc7c69b46eda52ac0574794 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 3 Nov 2019 04:21:29 +0000 Subject: [PATCH] Move commands chart to ChartJS. --- .../Controllers/StatsController.cs | 19 +++++++++++++++++++ DiscImageChef.Server/Views/Stats/Index.cshtml | 9 ++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/DiscImageChef.Server/Controllers/StatsController.cs b/DiscImageChef.Server/Controllers/StatsController.cs index 2959dacb..416e31e8 100644 --- a/DiscImageChef.Server/Controllers/StatsController.cs +++ b/DiscImageChef.Server/Controllers/StatsController.cs @@ -44,6 +44,7 @@ using DiscImageChef.Server.Models; using Highsoft.Web.Mvc.Charts; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using OperatingSystem = DiscImageChef.Server.Models.OperatingSystem; using PlatformID = DiscImageChef.CommonTypes.Interop.PlatformID; using Version = DiscImageChef.Server.Models.Version; @@ -565,5 +566,23 @@ namespace DiscImageChef.Server.Controllers return Json(result); } + + public IActionResult GetCommandsData() + { + string[][] result = + { + ctx.Commands.OrderByDescending(o => o.Count).Take(10).Select(v => v.Name).ToArray(), + ctx.Commands.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.Commands.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 bbcb5c31..546b8218 100644 --- a/DiscImageChef.Server/Views/Stats/Index.cshtml +++ b/DiscImageChef.Server/Views/Stats/Index.cshtml @@ -151,7 +151,8 @@ @if (ViewBag.repCommands != null) {
-
+
+
@@ -565,12 +566,18 @@ function DrawVersionsPie(versionsData) DrawPie("versionsChart", `Top ${versionsData[0].length} DiscImageChef versions`, versionsData[0], versionsData[1]) } +function DrawCommandsPie(commandsData) +{ + DrawPie("commandsChart", `Top ${commandsData[0].length} used commands`, commandsData[0], commandsData[1]) +} + window.onload = () => { $.ajax({dataType: "json", url: "/Stats/GetOsData", success: DrawOsPie, cache:false}); $.ajax({dataType: "json", url: "/Stats/GetLinuxData", success: DrawLinuxPie, cache:false}); $.ajax({dataType: "json", url: "/Stats/GetMacOsData", success: DrawMacOsPie, cache:false}); $.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}); } \ No newline at end of file