Skip to content

Commit

Permalink
- LeaguePoints calculation refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
FiendPopsicle committed Aug 25, 2024
1 parent e3c475c commit a423ddd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 59 deletions.
17 changes: 17 additions & 0 deletions SengokuProvider.Library/Models/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ public struct DiscordWebhookConfig
public static readonly long StreetFighter6ThreadId = 1273004373890568314;
public static readonly long GuiltyGearStriveThreadId = 1273004304764108810;
}
public struct CommonConstants
{
public static readonly Dictionary<int, int> EnhancedPointDistribution = new Dictionary<int, int>
{
{ 1, 150 },
{ 2, 100 },
{ 3, 80 },
{ 4, 70 },
{ 5, 60 },
{ 7, 50 },
{ 9, 40 },
{ 13, 30 },
{ 17, 20 },
{ 25, 10 },
{ 33, 10 }
};
}
public struct BearerConstants
{
public static readonly string[] BearerArray = ["2a7b93add38208847a394e01bd3e4575", "2b0160ef106be1c250e4db077b743429", "10cf2895837a1e6e9ea826fd997180e0",
Expand Down
104 changes: 45 additions & 59 deletions SengokuProvider.Library/Services/Players/PlayerIntakeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private List<PlayerStandingResult> MapPreviousTournamentData(PastEventPlayerData
}

int numEntrants = tempNode.NumEntrants ?? 0;
int totalPoints = CalculateLeaguePoints(participationPoints, winnerBonus, firstRecord, numEntrants);
int totalPoints = CalculateLeaguePoints(firstRecord, numEntrants);

var newStanding = new PlayerStandingResult
{
Expand Down Expand Up @@ -194,87 +194,73 @@ private List<PlayerStandingResult> MapStandingsData(PlayerGraphQLResult? data)
{
List<PlayerStandingResult> mappedResult = new List<PlayerStandingResult>();
if (data == null) return mappedResult;
const int participationPoints = 5;
const int winnerBonus = 50;

foreach (var tempNode in data.TournamentLink.Entrants.Nodes)
{
if (tempNode.Standing == null) continue;
int numEntrants = data.TournamentLink.NumEntrants ?? 0;
int totalPoints = CalculateLeaguePoints(participationPoints, winnerBonus, tempNode, numEntrants);

var newStandings = new PlayerStandingResult
try
{
Response = "Open",
EntrantsNum = numEntrants,
LastUpdated = DateTime.UtcNow,
UrlSlug = data.TournamentLink.Slug,
StandingDetails = new StandingDetails
int totalPoints = CalculateLeaguePoints(tempNode, numEntrants);
var newStandings = new PlayerStandingResult
{
IsActive = tempNode.Standing.IsActive,
Placement = tempNode.Standing.Placement ?? 0,
GamerTag = tempNode.Participants?.FirstOrDefault()?.Player?.GamerTag ?? "",
EventId = data.TournamentLink.EventLink.Id,
EventName = data.TournamentLink.EventLink.Name,
TournamentId = data.TournamentLink.Id,
TournamentName = data.TournamentLink.Name,
LeaguePoints = totalPoints
},
TournamentLinks = new Links
{
EntrantId = tempNode.Id,
StandingId = tempNode.Standing.Id,
PlayerId = tempNode.Participants?.FirstOrDefault()?.Player?.Id ?? 0,
}
};
mappedResult.Add(newStandings);
Response = "Open",
EntrantsNum = numEntrants,
LastUpdated = DateTime.UtcNow,
UrlSlug = data.TournamentLink.Slug,
StandingDetails = new StandingDetails
{
IsActive = tempNode.Standing.IsActive,
Placement = tempNode.Standing.Placement ?? 0,
GamerTag = tempNode.Participants?.FirstOrDefault()?.Player?.GamerTag ?? "",
EventId = data.TournamentLink.EventLink.Id,
EventName = data.TournamentLink.EventLink.Name,
TournamentId = data.TournamentLink.Id,
TournamentName = data.TournamentLink.Name,
LeaguePoints = totalPoints
},
TournamentLinks = new Links
{
EntrantId = tempNode.Id,
StandingId = tempNode.Standing.Id,
PlayerId = tempNode.Participants?.FirstOrDefault()?.Player?.Id ?? 0,
}
};
mappedResult.Add(newStandings);
}
catch (Exception ex)
{
Console.WriteLine($"Error Occured populating Standing Data: {ex.Message}, {ex.StackTrace}");
continue;
}
}
return mappedResult;
}
private int CalculateLeaguePoints(int participationPoints, int winnerBonus, CommonEntrantNode tempNode, int totalEntrants)
private int CalculateLeaguePoints(CommonEntrantNode tempNode, int totalEntrants)
{
int participationPoints = 5;
int totalPoints = participationPoints;
int maxWinnersRounds = (int)Math.Ceiling(Math.Log2(totalEntrants));
int maxLosersRounds = maxWinnersRounds - 1;

bool wasInWinnersBracket = true;
int placement = tempNode.Standing?.Placement ?? int.MaxValue; // Default to MaxValue if placement is not found

foreach (var set in tempNode.SetList.Nodes)
// Apply points based on placement using the enhanced point distribution
foreach (var entry in CommonConstants.EnhancedPointDistribution)
{
if (set.WinnerEntrantId != tempNode.Id) continue;
if (set?.Round == null) continue;

if (set.Round > 0)
if (placement <= entry.Key)
{
// Winners' bracket points, with higher value for staying in winners
double roundFactor = (double)set.Round / maxWinnersRounds;
int roundPoints = (int)(roundFactor * 150);
totalPoints += roundPoints;
}
else
{
if (wasInWinnersBracket)
{
// Apply a penalty for being sent to losers' bracket
totalPoints -= 50;
wasInWinnersBracket = false;
}

// Losers' bracket points, with reduced value
double roundFactor = (double)Math.Abs(set.Round) / maxLosersRounds;
int roundPoints = (int)(roundFactor * 50);
totalPoints += roundPoints;
totalPoints += entry.Value;
break;
}
}

if (tempNode?.Standing?.Placement == 1)
// Ensure minimum points for participation
if (totalPoints < participationPoints)
{
totalPoints += winnerBonus;
totalPoints = participationPoints;
}

if (totalPoints < 5) { totalPoints = 5; }
return totalPoints;
}

private async Task<int> IntakePlayerStandingData(List<PlayerStandingResult> currentStandings)
{
if (currentStandings == null || currentStandings.Count == 0) return 0;
Expand Down

0 comments on commit a423ddd

Please sign in to comment.