Skip to content

Commit f8fe5b0

Browse files
committed
WIP basic leaderboard
1 parent b207558 commit f8fe5b0

File tree

3 files changed

+146
-5
lines changed

3 files changed

+146
-5
lines changed

MyApp.ServiceInterface/LeaderboardServices.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task<object> Any(CalculateLeaderBoard request)
4949
.Sum(y => y.WinRate);
5050

5151

52-
var leaderBoard = new LeaderBoard
52+
var leaderBoard = new CalculateLeaderboardResponse
5353
{
5454
MostLikedModels = statsByUser.Where(x => IsHuman(x.Id) == false)
5555
.OrderByDescending(x => x.GetScore())
@@ -110,7 +110,7 @@ double CalculateWinRate(List<StatTotals> statTotalsList, string name, int questi
110110
}
111111
}
112112

113-
public class LeaderBoard
113+
public class CalculateLeaderboardResponse
114114
{
115115
public List<ModelTotalScore> MostLikedModels { get; set; }
116116
public List<ModelTotalStartUpVotes> MostLikedModelsByLlm { get; set; }
@@ -168,7 +168,7 @@ public class LeaderBoardWinRateByTag
168168
public double WinRate { get; set; }
169169
}
170170

171-
public class CalculateLeaderBoard
171+
public class CalculateLeaderBoard : IReturn<CalculateLeaderboardResponse>, IGet
172172
{
173173

174174
}
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
11
@page "/leaderboard"
2+
@using MyApp.ServiceInterface
3+
@inherits AppComponentBase
24

35
<PageTitle>Leaderboard</PageTitle>
46

57
<div class="mt-8 mb-20 mx-auto max-w-fit">
6-
<Heading1>Counter</Heading1>
8+
<Heading1>Leaderboard</Heading1>
79

8-
<div data-component="pages/Counter.mjs"></div>
10+
<div class="mt-8">
11+
@if (data != null)
12+
{
13+
<LeaderboardView LeaderBoardData="@data"/>
14+
}
15+
</div>
916

1017
</div>
18+
19+
@code {
20+
21+
CalculateLeaderboardResponse? data;
22+
23+
protected override async Task OnInitializedAsync()
24+
{
25+
await base.OnInitializedAsync();
26+
var api = await ApiAsync(new CalculateLeaderBoard());
27+
if (api.Succeeded)
28+
data = api.Response;
29+
else
30+
Console.WriteLine(api.Error?.Message);
31+
32+
}
33+
34+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
@using MyApp.ServiceInterface
2+
3+
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
4+
<div class="bg-blue-500 text-white p-6 rounded-lg shadow-lg">
5+
<h2 class="text-2xl font-bold mb-4">Most Liked Models</h2>
6+
<div class="space-y-4">
7+
@foreach (var model in LeaderBoardData.MostLikedModelsByLlm.OrderByDescending(x => x.StartingUpVotes))
8+
{
9+
<div class="flex items-center">
10+
<img src="@GetAvatarUrl(model.Id)" alt="Avatar" class="w-12 h-12 rounded-full mr-4" />
11+
<div class="flex-1">
12+
<h3 class="text-lg font-semibold">@GetModelName(model.Id)</h3>
13+
<div class="text-sm text-green-200">@model.StartingUpVotes votes</div>
14+
</div>
15+
</div>
16+
}
17+
</div>
18+
</div>
19+
20+
<div class="bg-blue-500 text-white p-6 rounded-lg shadow-lg">
21+
<h2 class="text-2xl font-bold mb-4">Total Votes</h2>
22+
<div class="space-y-4">
23+
@foreach (var model in LeaderBoardData.ModelTotalScore.OrderByDescending(x => x.TotalScore))
24+
{
25+
<div class="flex items-center">
26+
<img src="@GetAvatarUrl(model.Id)" alt="Avatar" class="w-12 h-12 rounded-full mr-4" />
27+
<div class="flex-1">
28+
<h3 class="text-lg font-semibold">@GetModelName(model.Id)</h3>
29+
<div class="text-sm text-green-200">@model.TotalScore votes</div>
30+
</div>
31+
</div>
32+
}
33+
</div>
34+
</div>
35+
36+
<div class="bg-blue-500 text-white p-6 rounded-lg shadow-lg">
37+
<h2 class="text-2xl font-bold mb-4">Overall Win Rate</h2>
38+
<div class="space-y-4">
39+
@foreach (var model in LeaderBoardData.AnswererWinRate.OrderByDescending(x => x.WinRate))
40+
{
41+
<div class="flex items-center">
42+
<img src="@GetAvatarUrl(model.Id)" alt="Avatar" class="w-12 h-12 rounded-full mr-4" />
43+
<div class="flex-1">
44+
<h3 class="text-lg font-semibold">@GetModelName(model.Id)</h3>
45+
<div class="text-sm text-green-200">@(Math.Round(model.WinRate,2)) %</div>
46+
</div>
47+
</div>
48+
}
49+
</div>
50+
</div>
51+
52+
<div class="bg-blue-500 text-white p-6 rounded-lg shadow-lg">
53+
<h2 class="text-2xl font-bold mb-4">Win Rate By Models</h2>
54+
<div class="space-y-4">
55+
@foreach (var model in LeaderBoardData.ModelWinRate.OrderByDescending(x => x.WinRate))
56+
{
57+
<div class="flex items-center">
58+
<img src="@GetAvatarUrl(model.Id)" alt="Avatar" class="w-12 h-12 rounded-full mr-4" />
59+
<div class="flex-1">
60+
<h3 class="text-lg font-semibold">@GetModelName(model.Id)</h3>
61+
<div class="text-sm text-green-200">@(Math.Round(model.WinRate,2)) %</div>
62+
</div>
63+
</div>
64+
}
65+
</div>
66+
</div>
67+
68+
</div>
69+
70+
@code {
71+
[Parameter]
72+
public CalculateLeaderboardResponse LeaderBoardData { get; set; }
73+
74+
private string GetModelName(string modelId)
75+
{
76+
if (modelAliases.TryGetValue(modelId, out var alias))
77+
{
78+
return alias;
79+
}
80+
return modelId;
81+
}
82+
83+
private string GetAvatarUrl(string modelId)
84+
{
85+
var userName = modelUserMapping.TryGetValue(modelId, out var value) ? value : modelId;
86+
return $"/avatar/{userName}";
87+
}
88+
89+
Dictionary<string, string> modelUserMapping = new()
90+
{
91+
{ "mistral", "mistral" },
92+
{ "mixtral", "mixtral" },
93+
{ "mixtral-8x7b", "mixtral" },
94+
{ "mixtral-8x7b-32768", "mixtral"},
95+
{ "codellama", "codellama" },
96+
{ "deepseek-coder:6.7b", "deepseek-coder" },
97+
{ "deepseek-coder-6", "deepseek-coder"},
98+
{ "gemma-2b", "gemma-2b" },
99+
{ "gemma", "gemma" },
100+
{ "gemma-7b", "gemma" },
101+
{ "phi", "phi" }
102+
};
103+
104+
Dictionary<string, string> modelAliases = new()
105+
{
106+
{ "mistral", "Mistral 7B" },
107+
{ "mixtral", "Mixtral 8x7B" },
108+
{ "codellama", "Codellama" },
109+
{ "deepseek-coder:6.7b", "Deepseek Coder 6.7B" },
110+
{ "deepseek-coder-6", "Deepseek Coder 6.7B" },
111+
{ "gemma-2b", "Gemma 2B" },
112+
{ "gemma", "Gemma 7B" },
113+
{ "gemma-7b", "Gemma 7B" },
114+
{ "phi", "Phi" }
115+
};
116+
117+
}

0 commit comments

Comments
 (0)