Added metrics badge

This commit is contained in:
erri120 2020-07-07 14:29:05 +02:00
parent 7d1a77e754
commit eefcbfaada
No known key found for this signature in database
GPG Key ID: A8C0A18D8D4D3135
3 changed files with 44 additions and 15 deletions

19
Wabbajack.Server/Badge.cs Normal file
View File

@ -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;
}
}
}

View File

@ -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<IActionResult> HandleGitHubBadge()

View File

@ -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<IActionResult> 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<object, string> ReportTemplate = NettleEngine.GetCompiler().Compile(@"
<html><body>
<h2>Tar Report for {{$.key}}</h2>