Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #305 from aspriddell/add-proportion-struct
Browse files Browse the repository at this point in the history
create struct to handle modern stats ratio values
  • Loading branch information
aspriddell authored Apr 1, 2022
2 parents 86d2962 + 42a0548 commit 46796fc
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 58 deletions.
24 changes: 24 additions & 0 deletions DragonFruit.Six.Api/Modern/Containers/RatioBackedStat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Dragon6 API Copyright DragonFruit Network <inbox@dragonfruit.network>
// Licensed under Apache-2. Refer to the LICENSE file for more info

namespace DragonFruit.Six.Api.Modern.Containers
{
public struct RatioBackedStat
{
internal RatioBackedStat(uint total, float ratio)
{
Ratio = ratio;
Value = (int)(total * Ratio);
}

/// <summary>
/// Converted value formed of the total applicable values multiplied by the <see cref="Ratio"/>
/// </summary>
public int Value { get; }

/// <summary>
/// The ratio of valid items relative to the total
/// </summary>
public float Ratio { get; }
}
}
137 changes: 79 additions & 58 deletions DragonFruit.Six.Api/Modern/Entities/ModernStatsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under Apache-2. Refer to the LICENSE file for more info

using System;
using DragonFruit.Six.Api.Modern.Containers;
using DragonFruit.Six.Api.Modern.Utils;
using DragonFruit.Six.Api.Utils;
using Newtonsoft.Json;
Expand All @@ -18,8 +19,6 @@ public abstract class ModernStatsBase
[JsonProperty("statsDetail")]
public string Name { get; set; }

#region Match Stats

[JsonProperty("matchesWon")]
public uint MatchesWon { get; set; }

Expand All @@ -29,26 +28,14 @@ public abstract class ModernStatsBase
[JsonProperty("matchesPlayed")]
public uint MatchesPlayed { get; set; }

public float MatchWl => _matchWl ??= RatioUtils.RatioOf(MatchesWon, MatchesLost);

#endregion

#region Round Stats

[JsonProperty("roundsPlayed")]
public uint RoundsPlayed { get; set; }

[JsonProperty("roundsWon")]
public uint RoundsWon { get; set; }

[JsonProperty("roundsLost")]
public uint RoundsLost { get; set; }

public float RoundWl => _roundWl ??= RatioUtils.RatioOf(RoundsWon, RoundsLost);

#endregion

#region Kill/Deaths
[JsonProperty("roundsPlayed")]
public uint RoundsPlayed { get; set; }

[JsonProperty("kills")]
public uint Kills { get; set; }
Expand Down Expand Up @@ -86,20 +73,12 @@ public abstract class ModernStatsBase
[JsonProperty("openingDeathTrades")]
public uint OpeningDeathTrades { get; set; }

#endregion

#region Distance Stats

[JsonProperty("distanceTravelled")]
public float DistanceTravelled { get; set; }

[JsonProperty("distancePerRound")]
public float DistanceTravelledPerRound { get; set; }

#endregion

#region Time Played

[JsonProperty("timeAlivePerMatch")]
public float SecondsAlivePerMatch { get; set; }

Expand All @@ -109,48 +88,90 @@ public abstract class ModernStatsBase
[JsonProperty("minutesPlayed")]
public float MinutesPlayed { get; set; }

public float Kd => _kd ??= RatioUtils.RatioOf(Kills, Deaths);
public float MatchWl => _matchWl ??= RatioUtils.RatioOf(MatchesWon, MatchesLost);
public float RoundWl => _roundWl ??= RatioUtils.RatioOf(RoundsWon, RoundsLost);

public TimeSpan TimeAlivePerMatch => _timeAlivePerMatch ??= TimeSpan.FromSeconds(SecondsAlivePerMatch);
public TimeSpan TimeDeadPerMatch => _timeDeadPerMatch ??= TimeSpan.FromSeconds(SecondsDeadPerMatch);
public TimeSpan TimePlayed => _timePlayed ??= TimeSpan.FromMinutes(MinutesPlayed);

#endregion

#region Ratios

[JsonProperty("headshotAccuracy.value")]
public float HeadshotAccuracy { get; set; }

[JsonProperty("killsPerRound.value")]
public float KillsPerRound { get; set; }

[JsonProperty("roundsWithAKill.value")]
public float RoundsWithSingleKill { get; set; }

[JsonProperty("roundsWithMultiKill.value")]
public float RoundsWithMultipleKills { get; set; }

[JsonProperty("roundsWithOpeningKill.value")]
public float RoundsWithFirstKill { get; set; }

[JsonProperty("roundsWithOpeningDeath.value")]
public float RoundsWithFirstDeath { get; set; }

[JsonProperty("roundsSurvived.value")]
public float RoundsSurvived { get; set; }

[JsonProperty("roundsWithAnAce.value")]
public float RoundsAced { get; set; }

[JsonProperty("roundsWithClutch.value")]
public float RoundsClutched { get; set; }
public RatioBackedStat HeadshotAccuracy { get; set; }
public RatioBackedStat KillsPerRound { get; set; }
public RatioBackedStat RoundsWithSingleKill { get; set; }
public RatioBackedStat RoundsWithMultipleKills { get; set; }
public RatioBackedStat RoundsWithFirstKill { get; set; }
public RatioBackedStat RoundsWithFirstDeath { get; set; }
public RatioBackedStat RoundsSurvived { get; set; }
public RatioBackedStat RoundsAced { get; set; }
public RatioBackedStat RoundsClutched { get; set; }

/// <summary>
/// Rounds with a kill, objective completion, survive or trade kills
/// </summary>
[JsonProperty("roundsWithKOST.value")]
public float RoundsWithKillObjectiveSurvivalOrTrade { get; set; }

public float Kd => _kd ??= RatioUtils.RatioOf(Kills, Deaths);
public RatioBackedStat RoundsWithKillObjectiveSurvivalOrTrade { get; set; }

#region Ratio Backing Fields

[JsonProperty("headshotAccuracy.value", Order = 1)]
private float HeadshotAccuracyRatio
{
set => HeadshotAccuracy = new RatioBackedStat(Kills, value);
}

[JsonProperty("killsPerRound.value", Order = 1)]
private float KillsPerRoundRatio
{
set => KillsPerRound = new RatioBackedStat(Kills, value);
}

[JsonProperty("roundsWithAKill.value", Order = 1)]
private float RoundsWithSingleKillRatio
{
set => RoundsWithSingleKill = new RatioBackedStat(Kills, value);
}

[JsonProperty("roundsWithMultiKill.value", Order = 1)]
private float RoundsWithMultipleKillsRatio
{
set => RoundsWithMultipleKills = new RatioBackedStat(Kills, value);
}

[JsonProperty("roundsWithOpeningKill.value", Order = 1)]
private float RoundsWithFirstKillRatio
{
set => RoundsWithFirstKill = new RatioBackedStat(Kills, value);
}

[JsonProperty("roundsWithOpeningDeath.value", Order = 1)]
private float RoundsWithFirstDeathRatio
{
set => RoundsWithFirstDeath = new RatioBackedStat(RoundsPlayed, value);
}

[JsonProperty("roundsSurvived.value", Order = 1)]
private float RoundsSurvivedRatio
{
set => RoundsSurvived = new RatioBackedStat(RoundsPlayed, value);
}

[JsonProperty("roundsWithAnAce.value", Order = 1)]
private float RoundsAcedRatio
{
set => RoundsAced = new RatioBackedStat(RoundsPlayed, value);
}

[JsonProperty("roundsWithClutch.value", Order = 1)]
private float RoundsClutchedRatio
{
set => RoundsClutched = new RatioBackedStat(RoundsPlayed, value);
}

[JsonProperty("roundsWithKOST.value", Order = 1)]
private float RoundsWithKillObjectiveSurvivalOrTradeRatio
{
set => RoundsWithKillObjectiveSurvivalOrTrade = new RatioBackedStat(RoundsPlayed, value);
}

#endregion
}
Expand Down

0 comments on commit 46796fc

Please sign in to comment.