diff --git a/MyApp.ServiceInterface/LeaderboardServices.cs b/MyApp.ServiceInterface/LeaderboardServices.cs index b11ba06..374cf66 100644 --- a/MyApp.ServiceInterface/LeaderboardServices.cs +++ b/MyApp.ServiceInterface/LeaderboardServices.cs @@ -23,7 +23,7 @@ public class LeaderboardServices : Service public async Task Any(CalculateLeaderBoard request) { var statTotals = await Db.SelectAsync(); - var modelsToExclude = request.ModelsToExclude?.Split(",").ToList() ?? new List(); + var modelsToExclude = request.ModelsToExclude?.Split(",").ToList() ?? []; // filter to answers only var answers = statTotals.Where(x => FilterSpecificModels(x, modelsToExclude)).ToList(); // Sum up votes by model, first group by UserName @@ -52,6 +52,14 @@ public async Task Any(CalculateLeaderBoard request) var modelsToExcludeSlug = request.ModelsToExclude?.GenerateSlug(); var combinedSuffix = modelsToExcludeSlug.IsNullOrEmpty() ? "" : $"-{modelsToExcludeSlug}"; await File.WriteAllTextAsync($"App_Data/leaderboard{combinedSuffix}.json", json); + + var count = Db.Count(x => x.Id != x.PostId.ToString()); + var info = new LeaderboardInfo + { + AnswerCount = count, + GeneratedDate = DateTime.UtcNow, + }; + await File.WriteAllTextAsync("App_Data/leaderboard-info.json", info.ToJson()); return leaderBoard; } @@ -318,6 +326,12 @@ public record LeaderboardStat public double Value { get; set; } } +public class LeaderboardInfo +{ + public long AnswerCount { get; set; } + public DateTime GeneratedDate { get; set; } +} + public class CalculateLeaderBoard : IReturn, IGet { public string? ModelsToExclude { get; set; } diff --git a/MyApp/Components/Pages/Leaderboard.razor b/MyApp/Components/Pages/Leaderboard.razor index 43bd8ef..53dd705 100644 --- a/MyApp/Components/Pages/Leaderboard.razor +++ b/MyApp/Components/Pages/Leaderboard.razor @@ -6,6 +6,20 @@ Leaderboard +@if (LeaderboardInfo != null) +{ +
+

+ Leaderboard + generated + + from @LeaderboardInfo.AnswerCount.ToString("N0") answers on + @LeaderboardInfo.GeneratedDate.ToString("MMM dd, yyyy") + +

+
+} +
@if (TotalVotes.Count > 0 && WinRates.Count > 0) @@ -70,6 +84,7 @@ [CascadingParameter] private HttpContext HttpContext { get; set; } = default!; + LeaderboardInfo? LeaderboardInfo; CalculateLeaderboardResponse? allData; CalculateLeaderboardResponse? top1kData; @@ -84,7 +99,7 @@ { // Only generate if missing, otherwise background task will update it. var gateway = GatewayFactory.GetServiceGateway(HttpContext.ToRequest()); - if (!File.Exists("App_Data/leaderboard.json")) + if (!File.Exists("App_Data/leaderboard.json") || !File.Exists("App_Data/leaderboard-info.json")) { await gateway.ApiAsync(new CalculateLeaderBoard()); } @@ -93,6 +108,7 @@ await gateway.ApiAsync(new CalculateTop1KLeaderboard()); } + LeaderboardInfo = (await File.ReadAllTextAsync("App_Data/leaderboard-info.json")).FromJson(); var allVotesData = await File.ReadAllTextAsync("App_Data/leaderboard.json"); allData = allVotesData.FromJson(); diff --git a/MyApp/wwwroot/css/app.css b/MyApp/wwwroot/css/app.css index 9158721..96a32d7 100644 --- a/MyApp/wwwroot/css/app.css +++ b/MyApp/wwwroot/css/app.css @@ -3923,6 +3923,12 @@ select{ box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); } +.hover\:shadow-lg:hover { + --tw-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); + --tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color); + box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); +} + .hover\:ring-2:hover { --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);