Skip to content

Commit

Permalink
Update leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric committed May 6, 2024
1 parent 0454ff0 commit 247c81f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
15 changes: 9 additions & 6 deletions MyApp.ServiceInterface/LeaderboardServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ public async Task<object> Any(CalculateTop1kLeaderboard request)
var topQuestions = await Db.SelectAsync(Db.From<Post>().OrderByDescending(x => x.Score).Limit(1000));
var postIds = topQuestions.Select(x => x.Id).ToList();

var topAnswers = await Db.SelectAsync<StatTotals>(Db.From<StatTotals>()
var statTotals = await Db.SelectAsync<StatTotals>(Db.From<StatTotals>()
.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),
Expand All @@ -74,7 +77,7 @@ public async Task<object> 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();
Expand All @@ -93,13 +96,14 @@ public async Task<object> Any(CalculateTop1kLeaderboard request)
return topLeaderBoard;
}

private static bool FilterSpecificModels(StatTotals x,List<string> modelsToExclude)
private static bool FilterSpecificModels(StatTotals x,List<string>? modelsToExclude = null)
{
var excludedModels = modelsToExclude ?? new List<string>();
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<StatTotals> statsByUser, List<StatTotals> answers)
Expand Down Expand Up @@ -321,6 +325,5 @@ public record LeaderboardStat

public class CalculateLeaderBoard : IReturn<CalculateLeaderboardResponse>, IGet
{
public bool? TopQuestions { get; set; }
public string? ModelsToExclude { get; set; }
}
33 changes: 25 additions & 8 deletions MyApp/Components/Pages/Leaderboard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

@if (TotalVotes.Count > 0 && WinRates.Count > 0)
{
<div class="mt-8 max-w-screen-md mx-auto">
<h3 class="mt-24 mb-8 text-2xl font-semibold">Top 1000 Questions Votes</h3>
<div class="mt-8 mx-auto">
<div class="mx-auto">
<LeaderboardStats Title="Total Votes" Results=@TotalVotes />
<LeaderboardStats Results=@Top1kVotes/>
</div>
<p class="text-center py-4">
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.
</p>
</div>

Expand Down Expand Up @@ -46,11 +47,14 @@
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;

CalculateLeaderboardResponse? data;
CalculateLeaderboardResponse? allData;
CalculateLeaderboardResponse? top1kData;

public List<LeaderboardStat> TotalVotes { get; set; } = [];
public List<LeaderboardStat> WinRates { get; set; } = [];

public List<LeaderboardStat> Top1kVotes { get; set; } = [];

public MarkupString ToProps(List<LeaderboardStat> results) => BlazorHtml.RawJson(new { results });

protected override async Task OnInitializedAsync()
Expand All @@ -63,10 +67,13 @@
await gateway.ApiAsync(new CalculateLeaderBoard());
}

var jsonData = await File.ReadAllTextAsync("App_Data/leaderboard.json");
data = jsonData.FromJson<CalculateLeaderboardResponse>();
var allVotesData = await File.ReadAllTextAsync("App_Data/leaderboard.json");
allData = allVotesData.FromJson<CalculateLeaderboardResponse>();

var top1kVotesData = await File.ReadAllTextAsync("App_Data/leaderboard-top1000.json");
top1kData = top1kVotesData.FromJson<CalculateLeaderboardResponse>();

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,
Expand All @@ -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,
Expand All @@ -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();
}
}
2 changes: 1 addition & 1 deletion MyApp/Components/Pages/LeaderboardTemp.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion MyApp/Components/Shared/LeaderboardStats.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<h3 class="text-xl font-semibold">@context.DisplayName</h3>
</div>
<div class="flex-1 text-center">
<h3 class="text-xl font-semibold bg-blue-100 dark:bg-blue-800 px-4 py-2 rounded-md">@context.Stat</h3>
<h3 class="text-xl font-semibold bg-gray-100 dark:bg-blue-800 px-4 py-2 rounded-md">@context.Stat</h3>
</div>
</div>
</Template>
Expand Down

0 comments on commit 247c81f

Please sign in to comment.