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 #211 from byBlurr/master
Browse files Browse the repository at this point in the history
Add PvE (Training) stats requests for weapons and operators
  • Loading branch information
byBlurr authored Jan 28, 2021
2 parents 97a3fa4 + fd459b2 commit c87320b
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 0 deletions.
18 changes: 18 additions & 0 deletions DragonFruit.Six.Api.Tests/Data/GeneralStatsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public void WeaponStatsTest(string identifier, Platform platform)
Client.GetWeaponStats(account);
}

[Test]
[TestCaseSource(nameof(_accounts))]
public void WeaponTrainingStatsTest(string identifier, Platform platform)
{
var account = GetAccountInfoFor(identifier, platform);
Client.GetWeaponTrainingStats(account);
}

[Test]
[TestCaseSource(nameof(_accounts))]
public void PlayerLevelStatsTest(string identifier, Platform platform)
Expand All @@ -51,5 +59,15 @@ public void PlayerOperatorStatsTest(string identifier, Platform platform)
var account = GetAccountInfoFor(identifier, platform);
Client.GetOperatorStats(account, OperatorInfo);
}

[Test]
[TestCaseSource(nameof(_accounts))]
public void PlayerOperatorTrainingStatsTest(string identifier, Platform platform)
{
OperatorInfo ??= Client.GetOperatorInfo();

var account = GetAccountInfoFor(identifier, platform);
Client.GetOperatorTrainingStats(account, OperatorInfo);
}
}
}
30 changes: 30 additions & 0 deletions DragonFruit.Six.Api/Deserializers/OperatorStatsDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,35 @@ public static IEnumerable<OperatorStats> DeserializeOperatorStatsFor(this JObjec
yield return op;
}
}

public static IEnumerable<OperatorStats> DeserializeOperatorTrainingStatsFor(this JObject jObject, string guid, IEnumerable<OperatorStats> data)
{
var json = jObject[Misc.Results]?[guid] as JObject;

if (json == null)
yield break;

foreach (var op in data.Select(x => x.Clone()))
{
op.Guid = guid;

op.Kills = json.GetUInt(Operator.KillsTraining.ToIndexedStatsKey(op.Index));
op.Deaths = json.GetUInt(Operator.DeathsTraining.ToIndexedStatsKey(op.Index));

op.Wins = json.GetUInt(Operator.WinsTraining.ToIndexedStatsKey(op.Index));
op.Losses = json.GetUInt(Operator.LossesTraining.ToIndexedStatsKey(op.Index));

op.RoundsPlayed = json.GetUInt(Operator.RoundsTraining.ToIndexedStatsKey(op.Index));
op.Duration = json.GetUInt(Operator.TimeTraining.ToIndexedStatsKey(op.Index));

op.Headshots = json.GetUInt(Operator.HeadshotsTraining.ToIndexedStatsKey(op.Index));
op.Downs = json.GetUInt(Operator.DownsTraining.ToIndexedStatsKey(op.Index));

op.Experience = json.GetUInt(Operator.ExperienceTraining.ToIndexedStatsKey(op.Index));
op.ActionCount = (uint?)json[op.OperatorActionResultId];

yield return op;
}
}
}
}
30 changes: 30 additions & 0 deletions DragonFruit.Six.Api/Deserializers/WeaponStatsDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,35 @@ public static IEnumerable<WeaponStats> DeserializeWeaponStatsFor(this JObject jO
};
}
}

public static IEnumerable<WeaponStats> DeserializeWeaponTrainingStatsFor(this JObject jObject, string guid)
{
var json = jObject[Misc.Results]?[guid] as JObject;

if (json == null)
yield break;

foreach (var index in Enum.GetValues(typeof(WeaponType)).Cast<WeaponType>())
{
var numericIndex = (int)index;

yield return new WeaponStats
{
Guid = guid,
Class = index,
TimesChosen = json.GetUInt(Weapon.PickedTraining.ToIndexedStatsKey(numericIndex)),

Kills = json.GetUInt(Weapon.KillsTraining.ToIndexedStatsKey(numericIndex)),
Deaths = json.GetUInt(Weapon.DeathsTraining.ToIndexedStatsKey(numericIndex)),

Headshots = json.GetUInt(Weapon.HeadshotsTraining.ToIndexedStatsKey(numericIndex)),
Downs = json.GetUInt(Weapon.DownsTraining.ToIndexedStatsKey(numericIndex)),
DownAssists = json.GetUInt(Weapon.DownAssistsTraining.ToIndexedStatsKey(numericIndex)),

ShotsFired = json.GetUInt(Weapon.ShotsFiredTraining.ToIndexedStatsKey(numericIndex)),
ShotsLanded = json.GetUInt(Weapon.ShotsHitTraining.ToIndexedStatsKey(numericIndex))
};
}
}
}
}
27 changes: 27 additions & 0 deletions DragonFruit.Six.Api/Extensions/OperatorStatsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,32 @@ public static IEnumerable<IEnumerable<OperatorStats>> GetOperatorStats<T>(this T
}
}
}

/// <summary>
/// Get the <see cref="OperatorStats"/> for an <see cref="AccountInfo"/>
/// </summary>
public static IEnumerable<OperatorStats> GetOperatorTrainingStats<T>(this T client, AccountInfo account, IEnumerable<OperatorStats> operators, CancellationToken token = default)
where T : Dragon6Client
=> GetOperatorTrainingStats(client, new[] { account }, operators, token).First();

/// <summary>
/// Get the <see cref="OperatorStats"/> for an array of <see cref="AccountInfo"/>s
/// </summary>
public static IEnumerable<IEnumerable<OperatorStats>> GetOperatorTrainingStats<T>(this T client, IEnumerable<AccountInfo> accounts, IEnumerable<OperatorStats> operators,
CancellationToken token = default) where T : Dragon6Client
{
var filteredGroups = accounts.GroupBy(x => x.Platform);

foreach (var group in filteredGroups)
{
var request = new OperatorTrainingStatsRequest(group, operators);
var data = client.Perform<JObject>(request, token);

foreach (var id in request.AccountIds)
{
yield return data.DeserializeOperatorTrainingStatsFor(id, operators);
}
}
}
}
}
25 changes: 25 additions & 0 deletions DragonFruit.Six.Api/Extensions/WeaponStatsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,30 @@ public static IEnumerable<IEnumerable<WeaponStats>> GetWeaponStats<T>(this T cli
}
}
}

/// <summary>
/// Get <see cref="WeaponStats"/> for an <see cref="AccountInfo"/>
/// </summary>
public static IEnumerable<WeaponStats> GetWeaponTrainingStats<T>(this T client, AccountInfo account, CancellationToken token = default) where T : Dragon6Client
=> GetWeaponTrainingStats(client, new[] { account }, token).First();

/// <summary>
/// Get <see cref="WeaponStats"/> for an array of <see cref="AccountInfo"/>s
/// </summary>
public static IEnumerable<IEnumerable<WeaponStats>> GetWeaponTrainingStats<T>(this T client, IEnumerable<AccountInfo> accounts, CancellationToken token = default) where T : Dragon6Client
{
var filteredGroups = accounts.GroupBy(x => x.Platform);

foreach (var group in filteredGroups)
{
var request = new WeaponTrainingStatsRequest(group);
var data = client.Perform<JObject>(request, token);

foreach (var id in request.AccountIds)
{
yield return data.DeserializeWeaponTrainingStatsFor(id);
}
}
}
}
}
29 changes: 29 additions & 0 deletions DragonFruit.Six.Api/Requests/OperatorStatsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,33 @@ public OperatorStatsRequest(IEnumerable<AccountInfo> accounts, IEnumerable<Opera
});
}
}

public sealed class OperatorTrainingStatsRequest : BasicStatsRequest
{
public OperatorTrainingStatsRequest(AccountInfo account, IEnumerable<OperatorStats> operators)
: this(new[] { account }, operators)
{
}

public OperatorTrainingStatsRequest(IEnumerable<AccountInfo> accounts, IEnumerable<OperatorStats> operators)
: base(accounts)
{
Stats = operators.Select(x => x.OperatorActionId).Where(x => !string.IsNullOrWhiteSpace(x)).Concat(new[]
{
Operator.KillsTraining,
Operator.DeathsTraining,

Operator.HeadshotsTraining,
Operator.DownsTraining,

Operator.WinsTraining,
Operator.LossesTraining,

Operator.RoundsTraining,
Operator.TimeTraining,

Operator.ExperienceTraining
});
}
}
}
28 changes: 28 additions & 0 deletions DragonFruit.Six.Api/Requests/WeaponStatsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,32 @@ public WeaponStatsRequest(IEnumerable<AccountInfo> accounts)
Weapon.ShotsHit
};
}

public sealed class WeaponTrainingStatsRequest : BasicStatsRequest
{
public WeaponTrainingStatsRequest(AccountInfo account)
: base(account)
{
}

public WeaponTrainingStatsRequest(IEnumerable<AccountInfo> accounts)
: base(accounts)
{
}

public override IEnumerable<string> Stats { get; set; } = new[]
{
Weapon.PickedTraining,

Weapon.KillsTraining,
Weapon.DeathsTraining,

Weapon.HeadshotsTraining,
Weapon.DownsTraining,
Weapon.DownAssistsTraining,

Weapon.ShotsFiredTraining,
Weapon.ShotsHitTraining
};
}
}
9 changes: 9 additions & 0 deletions DragonFruit.Six.Api/Strings/Operator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@ namespace DragonFruit.Six.Api.Strings
public static class Operator
{
public static string Wins => "operatorpvp_roundwon";
public static string WinsTraining => "operatorpve_roundwon";
public static string Losses => "operatorpvp_roundlost";
public static string LossesTraining => "operatorpve_roundlost";

public static string Kills => "operatorpvp_kills";
public static string KillsTraining => "operatorpve_kills";
public static string Deaths => "operatorpvp_death";
public static string DeathsTraining => "operatorpve_death";

public static string Downs => "operatorpvp_headshot";
public static string DownsTraining => "operatorpve_headshot";
public static string Headshots => "operatorpvp_dbno";
public static string HeadshotsTraining => "operatorpve_dbno";

public static string Rounds => "operatorpvp_roundplayed";
public static string RoundsTraining => "operatorpve_roundplayed";
public static string Time => "operatorpvp_timeplayed";
public static string TimeTraining => "operatorpve_timeplayed";
public static string Experience => "operatorpvp_totalxp";
public static string ExperienceTraining => "operatorpve_totalxp";
}
}
8 changes: 8 additions & 0 deletions DragonFruit.Six.Api/Strings/Weapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ namespace DragonFruit.Six.Api.Strings
public static class Weapon
{
public static string Picked => "weapontypepvp_chosen";
public static string PickedTraining => "weapontypepve_chosen";

public static string Kills => "weapontypepvp_kills";
public static string KillsTraining => "weapontypepve_kills";
public static string Deaths => "weapontypepvp_death";
public static string DeathsTraining => "weapontypepve_death";

public static string Headshots => "weapontypepvp_headshot";
public static string HeadshotsTraining => "weapontypepve_headshot";
public static string Downs => "weapontypepvp_dbno";
public static string DownsTraining => "weapontypepve_dbno";
public static string DownAssists => "weapontypepvp_dbnoassists";
public static string DownAssistsTraining => "weapontypepve_dbnoassists";

public static string ShotsFired => "weapontypepvp_bulletfired";
public static string ShotsFiredTraining => "weapontypepve_bulletfired";
public static string ShotsHit => "weapontypepvp_bullethit";
public static string ShotsHitTraining => "weapontypepve_bullethit";
}
}

0 comments on commit c87320b

Please sign in to comment.