diff --git a/WotBlitzStatisticsPro.Blazor/Program.cs b/WotBlitzStatisticsPro.Blazor/Program.cs index 0e77ade..d2c7563 100644 --- a/WotBlitzStatisticsPro.Blazor/Program.cs +++ b/WotBlitzStatisticsPro.Blazor/Program.cs @@ -43,11 +43,11 @@ namespace WotBlitzStatisticsPro.Blazor //var useMock = Environment.GetEnvironmentVariable("USE_GRAPH_QL_MOCK"); //if (useMock != null && useMock == "true") //{ - builder.Services.AddTransient(); + //builder.Services.AddTransient(); //} //else //{ - //builder.Services.AddTransient(); + builder.Services.AddTransient(); //} var host = builder.Build(); diff --git a/WotBlitzStatisticsPro.Common/Model/AccountInfoResponse.cs b/WotBlitzStatisticsPro.Common/Model/AccountInfoResponse.cs index 2a42e6d..c3ae6ce 100644 --- a/WotBlitzStatisticsPro.Common/Model/AccountInfoResponse.cs +++ b/WotBlitzStatisticsPro.Common/Model/AccountInfoResponse.cs @@ -6,7 +6,7 @@ namespace WotBlitzStatisticsPro.Common.Model /// /// Information about player /// - public class AccountInfoResponse + public class AccountInfoResponse: IStatisticsResponse { /// /// Player account identifier @@ -18,16 +18,48 @@ namespace WotBlitzStatisticsPro.Common.Model /// public DateTime CreatedAt { get; set; } = new DateTime(1970, 1, 1); - /// - /// Last battle time - /// - public DateTime LastBattleTime { get; set; } = new DateTime(1970, 1, 1); - /// /// Player's nick /// public string? Nickname { get; set; } + /// + /// Tank id, which kills max frags per battle + /// + public long MaxFragsTankId { get; set; } + + /// + /// Tank Id which created max experience per battle + /// + public long MaxXpTankId { get; set; } + + /// + /// Average tier + /// + public double AvgTier { get; set; } + + /// + /// All player's tanks + /// + public List? Tanks { get; set; } + + /// + /// Clan info + /// + public ClanInfoResponse? ClanInfo { get; set; } + + /// + /// Account Region and request language + /// + public RealmAndLanguage RegionAndLanguage { get; set; } = new(RealmType.Eu, RequestLanguage.En); + + #region statistics + + /// + /// Last battle time + /// + public DateTime LastBattleTime { get; set; } = new DateTime(1970, 1, 1); + /// /// Battles count /// @@ -78,21 +110,11 @@ namespace WotBlitzStatisticsPro.Common.Model /// public long MaxFrags { get; set; } - /// - /// Tank id, which kills max frags per battle - /// - public long MaxFragsTankId { get; set; } - /// /// Max experience per battle /// public long MaxXp { get; set; } - /// - /// Tank Id which created max experience per battle - /// - public long MaxXpTankId { get; set; } - /// /// Total shots count /// @@ -109,7 +131,7 @@ namespace WotBlitzStatisticsPro.Common.Model public long SurvivedBattles { get; set; } /// - /// Total count of survived and winned battles + /// Total count of survived and won battles /// public long WinAndSurvived { get; set; } @@ -123,54 +145,37 @@ namespace WotBlitzStatisticsPro.Common.Model /// public long Xp { get; set; } - /// - /// Average tier - /// - public double AvgTier { get; set; } - /// /// Wn7 coefficient /// public double Wn7 { get; set; } - /// - /// Player's win rate - /// - public decimal WinRate => Battles == 0 ? 0m : (decimal) 100 * Wins / Battles; + /// + /// Player's win rate + /// + public decimal WinRate => Battles == 0 ? 0m : (decimal)100 * Wins / Battles; /// /// Player's average damage /// - public decimal AvgDamage => Battles == 0 ? 0m : (decimal)DamageDealt / Battles; + public decimal AvgDamage => Battles == 0 ? 0m : (decimal)DamageDealt / Battles; /// /// Player's average XP /// - public decimal AvgXp => Battles == 0 ? 0m : (decimal)Xp / Battles; - - /// - /// Damage coefficient - /// - public decimal DamageCoefficient => DamageReceived == 0 ? 0m : (decimal) DamageDealt / DamageReceived; - - /// - /// Rate of survival - /// - public decimal SurvivalRate => Battles == 0 ? 0m : (decimal) 100 * SurvivedBattles / Battles; + public decimal AvgXp => Battles == 0 ? 0m : (decimal)Xp / Battles; /// - /// All player's tanks + /// Damage coefficient /// - public List? Tanks { get; set; } + public decimal DamageCoefficient => DamageReceived == 0 ? 0m : (decimal)DamageDealt / DamageReceived; /// - /// Clan info + /// Rate of survival /// - public ClanInfoResponse? ClanInfo { get; set; } + public decimal SurvivalRate => Battles == 0 ? 0m : (decimal)100 * SurvivedBattles / Battles; - /// - /// Account Region and request language - /// - public RealmAndLanguage RegionAndLanguage { get; set; } = new(RealmType.Eu, RequestLanguage.En); - } + + #endregion + } } \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Common/Model/IStatisticsResponse.cs b/WotBlitzStatisticsPro.Common/Model/IStatisticsResponse.cs new file mode 100644 index 0000000..d1e5751 --- /dev/null +++ b/WotBlitzStatisticsPro.Common/Model/IStatisticsResponse.cs @@ -0,0 +1,130 @@ +using System; + +namespace WotBlitzStatisticsPro.Common.Model +{ + /// + /// Represents game's statistics + /// + public interface IStatisticsResponse + { + /// + /// Last battle time + /// + DateTime LastBattleTime { get; set; } + + /// + /// Battles count + /// + long Battles { get; set; } + + /// + /// Capture points + /// + long CapturePoints { get; set; } + + /// + /// Total damage amount + /// + long DamageDealt { get; set; } + + /// + /// Total amount of received damage + /// + long DamageReceived { get; set; } + + /// + /// Dropped capture points + /// + long DroppedCapturePoints { get; set; } + + /// + /// Total amount of frags + /// + long Frags { get; set; } + + /// + /// Total amount of frags grater ten 8 lvl + /// + long Frags8P { get; set; } + + /// + /// Total amount of hits + /// + long Hits { get; set; } + + /// + /// Total amount of losses + /// + long Losses { get; set; } + + /// + /// Max frags per battle + /// + long MaxFrags { get; set; } + + /// + /// Max experience per battle + /// + long MaxXp { get; set; } + + /// + /// Total shots count + /// + long Shots { get; set; } + + /// + /// Total count of spotted vehicles + /// + long Spotted { get; set; } + + /// + /// Total count of survived battles + /// + long SurvivedBattles { get; set; } + + /// + /// Total count of survived and won battles + /// + long WinAndSurvived { get; set; } + + /// + /// Total wins count + /// + long Wins { get; set; } + + /// + /// Total amount of experience + /// + long Xp { get; set; } + + /// + /// Wn7 coefficient + /// + double Wn7 { get; set; } + + /// + /// Player's win rate + /// + decimal WinRate { get; } + + /// + /// Player's average damage + /// + decimal AvgDamage { get; } + + /// + /// Player's average XP + /// + decimal AvgXp { get; } + + /// + /// Damage coefficient + /// + decimal DamageCoefficient { get; } + + /// + /// Rate of survival + /// + decimal SurvivalRate { get; } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Common/Model/TankInfoResponse.cs b/WotBlitzStatisticsPro.Common/Model/TankInfoResponse.cs index bbc558e..874f0f2 100644 --- a/WotBlitzStatisticsPro.Common/Model/TankInfoResponse.cs +++ b/WotBlitzStatisticsPro.Common/Model/TankInfoResponse.cs @@ -5,7 +5,7 @@ namespace WotBlitzStatisticsPro.Common.Model /// /// Information about player's tank /// - public class TankInfoResponse + public class TankInfoResponse: IStatisticsResponse { /// /// Player account identifier @@ -17,16 +17,6 @@ namespace WotBlitzStatisticsPro.Common.Model /// public long TankId { get; set; } - /// - /// Total time in battle until tank killed - /// - public int BattleLifeTimeInSeconds { get; set; } - - /// - /// Last battle - /// - public DateTime LastBattleTime { get; set; } - /// /// Information is tank in garage or not. Information is not provided without Auth token /// @@ -37,126 +27,15 @@ namespace WotBlitzStatisticsPro.Common.Model /// public MarkOfMastery MarkOfMastery { get; set; } - /// - /// Battles count - /// - public long Battles { get; set; } = 1; - - /// - /// Base capture points - /// - public long CapturePoints { get; set; } - - /// - /// Damage dealt - /// - public long DamageDealt { get; set; } - - /// - /// Damage received - /// - public long DamageReceived { get; set; } - - /// - /// Base dropped capture points - /// - public long DroppedCapturePoints { get; set; } - - /// - /// Frags count - /// - public long Frags { get; set; } - - /// - /// Frags count after 8 tier - /// - public long Frags8P { get; set; } - - /// - /// Hits count - /// - public long Hits { get; set; } - - /// - /// Losses count - /// - public long Losses { get; set; } - - /// - /// Max frags per battle - /// - public long MaxFrags { get; set; } - - /// - /// Max XP per battle - /// - public long MaxXp { get; set; } - - /// - /// Shots count - /// - public long Shots { get; set; } - - /// - /// Spotted vehicles count - /// - public long Spotted { get; set; } - - /// - /// Amount of survived battles - /// - public long SurvivedBattles { get; set; } - - /// - /// Amount of survived and wined battles - /// - public long WinAndSurvived { get; set; } - - /// - /// Wins count - /// - public long Wins { get; set; } - - /// - /// Total experience - /// - public long Xp { get; set; } - /// - /// Wn7 coefficient + /// Total time in battle until tank killed /// - public double Wn7 { get; set; } + public int BattleLifeTimeInSeconds { get; set; } /// /// Average life time in battle until tank is killed. /// - public decimal AvgBattleLifeTimeInMinutes => (decimal) BattleLifeTimeInSeconds / (60 * Battles); - - /// - /// Tank's win rate - /// - public decimal WinRate => (decimal) 100 * Wins / Battles; - - /// - /// Average tank's damage - /// - public decimal AvgDamage => (decimal) DamageDealt / Battles; - - /// - /// Average XP - /// - public decimal AvgXp => (decimal) Xp / Battles; - - /// - /// Damage coefficient - /// - public decimal DamageCoefficient => DamageReceived == 0 ? 0m : (decimal)DamageDealt / DamageReceived; - - /// - /// Rate of survival - /// - public decimal SurvivalRate => (decimal)100 * SurvivedBattles / Battles; - + public decimal AvgBattleLifeTimeInMinutes => (decimal)BattleLifeTimeInSeconds / (60 * Battles); /// /// Tank name @@ -203,6 +82,129 @@ namespace WotBlitzStatisticsPro.Common.Model /// public string? NormalImage { get; set; } + #region statistics - } + /// + /// Last battle time + /// + public DateTime LastBattleTime { get; set; } = new DateTime(1970, 1, 1); + + /// + /// Battles count + /// + public long Battles { get; set; } + + /// + /// Capture points + /// + public long CapturePoints { get; set; } + + /// + /// Total damage amount + /// + public long DamageDealt { get; set; } + + /// + /// Total amount of received damage + /// + public long DamageReceived { get; set; } + + /// + /// Dropped capture points + /// + public long DroppedCapturePoints { get; set; } + + /// + /// Total amount of frags + /// + public long Frags { get; set; } + + /// + /// Total amount of fras grater ten 8 lvl + /// + public long Frags8P { get; set; } + + /// + /// Total amount of hits + /// + public long Hits { get; set; } + + /// + /// Total amount of losses + /// + public long Losses { get; set; } + + /// + /// Max frags per battle + /// + public long MaxFrags { get; set; } + + /// + /// Max experience per battle + /// + public long MaxXp { get; set; } + + /// + /// Total shots count + /// + public long Shots { get; set; } + + /// + /// Total count of spotted vehicles + /// + public long Spotted { get; set; } + + /// + /// Total count of survived battles + /// + public long SurvivedBattles { get; set; } + + /// + /// Total count of survived and won battles + /// + public long WinAndSurvived { get; set; } + + /// + /// Total wins count + /// + public long Wins { get; set; } + + /// + /// Total amount of experience + /// + public long Xp { get; set; } + + /// + /// Wn7 coefficient + /// + public double Wn7 { get; set; } + + /// + /// Player's win rate + /// + public decimal WinRate => Battles == 0 ? 0m : (decimal)100 * Wins / Battles; + + /// + /// Player's average damage + /// + public decimal AvgDamage => Battles == 0 ? 0m : (decimal)DamageDealt / Battles; + + /// + /// Player's average XP + /// + public decimal AvgXp => Battles == 0 ? 0m : (decimal)Xp / Battles; + + /// + /// Damage coefficient + /// + public decimal DamageCoefficient => DamageReceived == 0 ? 0m : (decimal)DamageDealt / DamageReceived; + + /// + /// Rate of survival + /// + public decimal SurvivalRate => Battles == 0 ? 0m : (decimal)100 * SurvivedBattles / Battles; + + + #endregion + } } \ No newline at end of file diff --git a/WotBlitzStatisticsPro.GraphQl/ObjectTypes/StatisticsResponseType.cs b/WotBlitzStatisticsPro.GraphQl/ObjectTypes/StatisticsResponseType.cs new file mode 100644 index 0000000..fc2e668 --- /dev/null +++ b/WotBlitzStatisticsPro.GraphQl/ObjectTypes/StatisticsResponseType.cs @@ -0,0 +1,14 @@ +using HotChocolate.Types; +using WotBlitzStatisticsPro.Common.Model; + +namespace WotBlitzStatisticsPro.GraphQl.ObjectTypes +{ + [ExtendObjectType(Name = "Query")] + public class StatisticsResponseType: InterfaceType + { + protected override void Configure(IInterfaceTypeDescriptor descriptor) + { + descriptor.Name("Statistics"); + } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.GraphQl/ObjectTypes/TankInfoResponseType.cs b/WotBlitzStatisticsPro.GraphQl/ObjectTypes/TankInfoResponseType.cs new file mode 100644 index 0000000..2768e5f --- /dev/null +++ b/WotBlitzStatisticsPro.GraphQl/ObjectTypes/TankInfoResponseType.cs @@ -0,0 +1,15 @@ +using HotChocolate.Types; +using WotBlitzStatisticsPro.Common.Model; + +namespace WotBlitzStatisticsPro.GraphQl.ObjectTypes +{ + [ExtendObjectType(Name = "Query")] + public class TankInfoResponseType: ObjectType + { + protected override void Configure(IObjectTypeDescriptor descriptor) + { + descriptor.Name("TankInfoResponse"); + descriptor.Implements(); + } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.GraphQl/Resolvers/AccountInfoResolver.cs b/WotBlitzStatisticsPro.GraphQl/Resolvers/AccountInfoResolver.cs index 4ea9c73..a6a4ab8 100644 --- a/WotBlitzStatisticsPro.GraphQl/Resolvers/AccountInfoResolver.cs +++ b/WotBlitzStatisticsPro.GraphQl/Resolvers/AccountInfoResolver.cs @@ -1,5 +1,6 @@ using HotChocolate.Types; using WotBlitzStatisticsPro.Common.Model; +using WotBlitzStatisticsPro.GraphQl.ObjectTypes; using WotBlitzStatisticsPro.Logic; namespace WotBlitzStatisticsPro.GraphQl.Resolvers @@ -9,6 +10,9 @@ namespace WotBlitzStatisticsPro.GraphQl.Resolvers { protected override void Configure(IObjectTypeDescriptor descriptor) { + descriptor.Name("AccountInfoResponse"); + descriptor.Implements(); + descriptor.Field(t => t.ClanInfo) .Resolver(ctx => ctx.Service().GelClanInfoByAccount(ctx.Parent().AccountId, ctx.Parent().RegionAndLanguage)); } diff --git a/WotBlitzStatisticsPro.GraphQl/Startup.cs b/WotBlitzStatisticsPro.GraphQl/Startup.cs index 5840c00..b6622fa 100644 --- a/WotBlitzStatisticsPro.GraphQl/Startup.cs +++ b/WotBlitzStatisticsPro.GraphQl/Startup.cs @@ -85,6 +85,7 @@ namespace WotBlitzStatisticsPro.GraphQl .AddType() .AddType() .AddType() + .AddType() .AddMutationType(d => d.Name("Mutation")) .AddType() .AddType()