-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently 'hidden' to test performance on production.
- Loading branch information
Showing
9 changed files
with
371 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
</head> | ||
|
||
<body> | ||
|
||
<Routes/> | ||
<script src="_framework/blazor.web.js"></script> | ||
<script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
@page "/leaderboard" | ||
@using Shared | ||
@inject HttpClient Http | ||
@inject NavigationManager NavigationManager | ||
@attribute [StreamRendering] | ||
|
||
<h4>Leaderboards</h4> | ||
@if(LeaderboardData == null) | ||
{ | ||
<p><em>Loading leaderboard data... Please wait...</em></p> | ||
} | ||
else | ||
{ | ||
// 0, 1, 2, 3, 4, 5 = Last24Hours, Last7Days, Last30Days, Last90Days, Last365Days, AllTime | ||
<div class="btn-group" role="group" aria-label="Time range selection"> | ||
<button type="button" class="btn btn-secondary" onclick="changeTimeRange(0)">Last 24 hours</button> | ||
<button type="button" class="btn btn-secondary" onclick="changeTimeRange(1)">Last 7 days</button> | ||
<button type="button" class="btn btn-secondary" onclick="changeTimeRange(2)">Last 30 days</button> | ||
<button type="button" class="btn btn-secondary" onclick="changeTimeRange(3)">Last 90 days</button> | ||
<button type="button" class="btn btn-secondary" onclick="changeTimeRange(4)">Last 365 days</button> | ||
<button type="button" class="btn btn-secondary" onclick="changeTimeRange(5)">All time</button> | ||
</div> | ||
// Need 2 tables for MostSeenPlayers and MostAntagPlayers | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Player name</th> | ||
<th>Times seen</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var player in LeaderboardData.MostSeenPlayers) | ||
{ | ||
<tr> | ||
<td>@player.Value.Player.Username</td> | ||
<td>@player.Value.Count</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Player name</th> | ||
<th>Times antag</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var player in LeaderboardData.MostAntagPlayers) | ||
{ | ||
<tr> | ||
<td>@player.Value.Player.Username</td> | ||
<td>@player.Value.Count</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
} | ||
|
||
<script> | ||
function changeTimeRange(timeRange) { | ||
// This is a hacky way to change the time range, but it works | ||
window.location.href = "/leaderboard?timeRange=" + timeRange; | ||
} | ||
</script> | ||
|
||
@code{ | ||
private bool IsLoading { get; set; } = true; | ||
private LeaderboardData? LeaderboardData { get; set; } = null; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
// Get the time range from the query string | ||
var uri = new Uri(NavigationManager.Uri); | ||
var query = uri.Query; | ||
var timeRange = 5; // Default to AllTime | ||
if (!string.IsNullOrEmpty(query)) | ||
{ | ||
var queryDictionary = System.Web.HttpUtility.ParseQueryString(query); | ||
if (queryDictionary.AllKeys.Contains("timeRange")) | ||
{ | ||
timeRange = int.Parse(queryDictionary["timeRange"]); | ||
} | ||
} | ||
|
||
LeaderboardData = await Http.GetFromJsonAsync<LeaderboardData>("api/Data/leaderboard?rangeOption=" + timeRange); | ||
IsLoading = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Shared; | ||
|
||
public class LeaderboardData | ||
{ | ||
public Dictionary<string, PlayerCount> MostSeenPlayers { get; set; } | ||
public Dictionary<string, PlayerCount> MostAntagPlayers { get; set; } | ||
|
||
/// <summary> | ||
/// Most times as a kill or maroon target. | ||
/// </summary> | ||
public Dictionary<string, PlayerData> MostHuntedPlayer { get; set; } | ||
} | ||
|
||
public class PlayerCount | ||
{ | ||
public PlayerData Player { get; set; } | ||
public int Count { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Shared; | ||
|
||
/// <summary> | ||
/// Represents collected player data from replays. This is used to generate leaderboards and other statistics. | ||
/// </summary> | ||
public class PlayerData | ||
{ | ||
public Guid PlayerGuid { get; set; } | ||
|
||
public string Username { get; set; } | ||
|
||
|
||
public override bool Equals(object? obj) | ||
{ | ||
if (obj is not PlayerData other) | ||
{ | ||
return false; | ||
} | ||
|
||
return PlayerGuid == other.PlayerGuid; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return PlayerGuid.GetHashCode(); | ||
} | ||
} |
Oops, something went wrong.