diff --git a/MyApp.ServiceInterface/LeaderboardServices.cs b/MyApp.ServiceInterface/LeaderboardServices.cs index c640bec..6010d10 100644 --- a/MyApp.ServiceInterface/LeaderboardServices.cs +++ b/MyApp.ServiceInterface/LeaderboardServices.cs @@ -62,10 +62,13 @@ public async Task Any(CalculateTop1kLeaderboard request) var topQuestions = await Db.SelectAsync(Db.From().OrderByDescending(x => x.Score).Limit(1000)); var postIds = topQuestions.Select(x => x.Id).ToList(); - var topAnswers = await Db.SelectAsync(Db.From() + var statTotals = await Db.SelectAsync(Db.From() .Where(x => Sql.In(x.PostId,postIds))); - var topStatsByUser = topAnswers.GroupBy(x => x.Id.RightPart('-')).Select(x => new StatTotals + // filter to answers only + var answers = statTotals.Where(x => FilterSpecificModels(x)).ToList(); + + var topStatsByUser = answers.GroupBy(x => x.Id.RightPart('-')).Select(x => new StatTotals { Id = x.Key, UpVotes = x.Sum(y => y.UpVotes), @@ -74,7 +77,7 @@ public async Task Any(CalculateTop1kLeaderboard request) FavoriteCount = x.Sum(y => y.FavoriteCount) }).ToList(); - var topLeaderBoard = CalculateLeaderboardResponse(topStatsByUser, topAnswers); + var topLeaderBoard = CalculateLeaderboardResponse(topStatsByUser, statTotals); topLeaderBoard.AnswererWinRate = topLeaderBoard.AnswererWinRate .Where(x => x.NumberOfQuestions > minimumQuestions).ToList(); @@ -93,13 +96,14 @@ public async Task Any(CalculateTop1kLeaderboard request) return topLeaderBoard; } - private static bool FilterSpecificModels(StatTotals x,List modelsToExclude) + private static bool FilterSpecificModels(StatTotals x,List? modelsToExclude = null) { + var excludedModels = modelsToExclude ?? new List(); return x.Id.Contains('-') && !x.Id.EndsWith("-accepted") && !x.Id.EndsWith("-most-voted") && !x.Id.EndsWith("-undefined") - && !modelsToExclude.Contains(x.Id.RightPart('-')); + && !excludedModels.Contains(x.Id.RightPart('-')); } private CalculateLeaderboardResponse CalculateLeaderboardResponse(List statsByUser, List answers) @@ -321,6 +325,5 @@ public record LeaderboardStat public class CalculateLeaderBoard : IReturn, IGet { - public bool? TopQuestions { get; set; } public string? ModelsToExclude { get; set; } } \ No newline at end of file diff --git a/MyApp/Components/Pages/Leaderboard.razor b/MyApp/Components/Pages/Leaderboard.razor index 6020727..e9e606a 100644 --- a/MyApp/Components/Pages/Leaderboard.razor +++ b/MyApp/Components/Pages/Leaderboard.razor @@ -12,12 +12,13 @@ @if (TotalVotes.Count > 0 && WinRates.Count > 0) { -
+

Top 1000 Questions Votes

+
- +

- Based on total number of total votes received by each model by a ranking model measuring how well they answer the question asked. + Based on total number of total votes received for answers of the top 1000 questions. Votes distributed by a ranking model measuring how well they answer the question asked.

@@ -46,11 +47,14 @@ [CascadingParameter] private HttpContext HttpContext { get; set; } = default!; - CalculateLeaderboardResponse? data; + CalculateLeaderboardResponse? allData; + CalculateLeaderboardResponse? top1kData; public List TotalVotes { get; set; } = []; public List WinRates { get; set; } = []; + public List Top1kVotes { get; set; } = []; + public MarkupString ToProps(List results) => BlazorHtml.RawJson(new { results }); protected override async Task OnInitializedAsync() @@ -63,10 +67,13 @@ await gateway.ApiAsync(new CalculateLeaderBoard()); } - var jsonData = await File.ReadAllTextAsync("App_Data/leaderboard.json"); - data = jsonData.FromJson(); + var allVotesData = await File.ReadAllTextAsync("App_Data/leaderboard.json"); + allData = allVotesData.FromJson(); + + var top1kVotesData = await File.ReadAllTextAsync("App_Data/leaderboard-top1000.json"); + top1kData = top1kVotesData.FromJson(); - TotalVotes = data.MostLikedModelsByLlm.OrderByDescending(x => x.StartingUpVotes).Select((x, index) => + TotalVotes = allData.MostLikedModelsByLlm.OrderByDescending(x => x.StartingUpVotes).Select((x, index) => new LeaderboardStat { Rank = index + 1, @@ -76,7 +83,7 @@ Value = x.StartingUpVotes, }).Take(10).ToList(); - WinRates = data.ModelWinRate.OrderByDescending(x => x.WinRate).Select((x, index) => + WinRates = allData.ModelWinRate.OrderByDescending(x => x.WinRate).Select((x, index) => new LeaderboardStat { Rank = index + 1, @@ -85,5 +92,15 @@ Stat = $"{Math.Round(x.WinRate, 2)}% ({x.NumberOfQuestions.ToHumanReadable()})", Value = Math.Round(x.WinRate, 2), }).Take(10).ToList(); + + Top1kVotes = top1kData.MostLikedModelsByLlm.OrderByDescending(x => x.StartingUpVotes).Select((x, index) => + new LeaderboardStat + { + Rank = index + 1, + DisplayName = AppConfig.GetApplicationUser(x.Id).DisplayName!, + AvatarUrl = AppConfig.GetUserName(x.Id).GetAvatarUrl(), + Stat = $"{x.StartingUpVotes.ToHumanReadable()}", + Value = x.StartingUpVotes, + }).Take(10).ToList(); } } diff --git a/MyApp/Components/Pages/LeaderboardTemp.razor b/MyApp/Components/Pages/LeaderboardTemp.razor index b7c08d0..d90bf52 100644 --- a/MyApp/Components/Pages/LeaderboardTemp.razor +++ b/MyApp/Components/Pages/LeaderboardTemp.razor @@ -163,7 +163,7 @@ ["php"] = "php", }; - string modelsToExclude = "gemini-pro,claude-3-opus,claude-3-sonnet,claude-3-haiku,gpt-4-turbo"; + string modelsToExclude = "gemini-pro,claude3-opus,claude3-sonnet,claude3-haiku,gpt-4-turbo"; protected override async Task OnInitializedAsync() { diff --git a/MyApp/Components/Shared/LeaderboardStats.razor b/MyApp/Components/Shared/LeaderboardStats.razor index c219c0d..254f95f 100644 --- a/MyApp/Components/Shared/LeaderboardStats.razor +++ b/MyApp/Components/Shared/LeaderboardStats.razor @@ -10,7 +10,7 @@

@context.DisplayName

-

@context.Stat

+

@context.Stat