diff --git a/Wabbajack.Server/Badge.cs b/Wabbajack.Server/Badge.cs new file mode 100644 index 00000000..be8658ad --- /dev/null +++ b/Wabbajack.Server/Badge.cs @@ -0,0 +1,19 @@ +using Wabbajack.Common.Serialization.Json; + +namespace Wabbajack.Server +{ + [JsonName("Badge")] + public class Badge + { + public int schemaVersion { get; set; } = 1; + public string label { get; set; } + public string message { get; set; } + public string color { get; set; } + + public Badge(string _label, string _message) + { + label = _label; + message = _message; + } + } +} diff --git a/Wabbajack.Server/Controllers/ListsStatus.cs b/Wabbajack.Server/Controllers/ListsStatus.cs index d0ea6715..91e4fa3f 100644 --- a/Wabbajack.Server/Controllers/ListsStatus.cs +++ b/Wabbajack.Server/Controllers/ListsStatus.cs @@ -9,6 +9,7 @@ using Nettle; using Wabbajack.Common; using Wabbajack.Common.Serialization.Json; using Wabbajack.Lib.ModListRegistry; +using Wabbajack.Server; using Wabbajack.Server.DataLayer; using Wabbajack.Server.DTOs; using Wabbajack.Server.Services; @@ -139,21 +140,6 @@ namespace Wabbajack.BuildServer.Controllers .FirstOrDefault(d => d.MachineName == Name); } - [JsonName("Badge")] - public class Badge - { - public int schemaVersion { get; set; } = 1; - public string label { get; set; } - public string message { get; set; } - public string color { get; set; } - - public Badge(string _label, string _message) - { - label = _label; - message = _message; - } - } - [HttpGet] [Route("status/badge.json")] public async Task HandleGitHubBadge() diff --git a/Wabbajack.Server/Controllers/Metrics.cs b/Wabbajack.Server/Controllers/Metrics.cs index f4d4313b..f7f03b2d 100644 --- a/Wabbajack.Server/Controllers/Metrics.cs +++ b/Wabbajack.Server/Controllers/Metrics.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Nettle; using Wabbajack.Common; +using Wabbajack.Server; using Wabbajack.Server.DataLayer; using Wabbajack.Server.DTOs; using WebSocketSharp; @@ -52,6 +53,29 @@ namespace Wabbajack.BuildServer.Controllers return Ok(results.ToList()); } + [HttpGet] + [Route("badge/{name}/badge.json")] + public async Task MetricsGitHubBadge(string name) + { + var results = (await _sql.MetricsReport("finish_install")) + .GroupBy(m => m.Subject) + .Select(g => new MetricResult + { + SeriesName = g.Key, + Labels = g.Select(m => m.Date.ToString(CultureInfo.InvariantCulture)).ToList(), + Values = g.Select(m => m.Count).ToList() + }).ToList(); + + Response.ContentType = "application/json"; + + var modlist = + results.FirstOrDefault(x => x.SeriesName.Equals(name, StringComparison.InvariantCultureIgnoreCase)); + + return Ok(modlist == null + ? new Badge($"Modlist {name} not found!", "Error") {color = "red"}.ToJson() + : new Badge("Installations: ", $"{modlist.Values.Aggregate((x, y) => x + y)}").ToJson()); + } + private static readonly Func ReportTemplate = NettleEngine.GetCompiler().Compile(@"

Tar Report for {{$.key}}