mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 02:17:20 +02:00
Some graphQL API refactor
This commit is contained in:
1 parent
c3550fbddd
commit
87fcdd31b1
8 files changed
+346
-175
No files matched your search
@@ -43,11 +43,11 @@ namespace WotBlitzStatisticsPro.Blazor
|
||||
//var useMock = Environment.GetEnvironmentVariable("USE_GRAPH_QL_MOCK");
|
||||
//if (useMock != null && useMock == "true")
|
||||
//{
|
||||
builder.Services.AddTransient<IGraphQlBackendService, GraphQlBackendMockService>();
|
||||
//builder.Services.AddTransient<IGraphQlBackendService, GraphQlBackendMockService>();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
//builder.Services.AddTransient<IGraphQlBackendService, GraphQlBackendService>();
|
||||
builder.Services.AddTransient<IGraphQlBackendService, GraphQlBackendService>();
|
||||
//}
|
||||
|
||||
var host = builder.Build();
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace WotBlitzStatisticsPro.Common.Model
|
||||
/// <summary>
|
||||
/// Information about player
|
||||
/// </summary>
|
||||
public class AccountInfoResponse
|
||||
public class AccountInfoResponse: IStatisticsResponse
|
||||
{
|
||||
///<summary>
|
||||
/// Player account identifier
|
||||
@@ -18,16 +18,48 @@ namespace WotBlitzStatisticsPro.Common.Model
|
||||
///</summary>
|
||||
public DateTime CreatedAt { get; set; } = new DateTime(1970, 1, 1);
|
||||
|
||||
///<summary>
|
||||
/// Last battle time
|
||||
///</summary>
|
||||
public DateTime LastBattleTime { get; set; } = new DateTime(1970, 1, 1);
|
||||
|
||||
///<summary>
|
||||
/// Player's nick
|
||||
///</summary>
|
||||
public string? Nickname { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Tank id, which kills max frags per battle
|
||||
///</summary>
|
||||
public long MaxFragsTankId { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Tank Id which created max experience per battle
|
||||
///</summary>
|
||||
public long MaxXpTankId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Average tier
|
||||
/// </summary>
|
||||
public double AvgTier { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// All player's tanks
|
||||
/// </summary>
|
||||
public List<TankInfoResponse>? Tanks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Clan info
|
||||
/// </summary>
|
||||
public ClanInfoResponse? ClanInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Account Region and request language
|
||||
/// </summary>
|
||||
public RealmAndLanguage RegionAndLanguage { get; set; } = new(RealmType.Eu, RequestLanguage.En);
|
||||
|
||||
#region statistics
|
||||
|
||||
///<summary>
|
||||
/// Last battle time
|
||||
///</summary>
|
||||
public DateTime LastBattleTime { get; set; } = new DateTime(1970, 1, 1);
|
||||
|
||||
///<summary>
|
||||
/// Battles count
|
||||
///</summary>
|
||||
@@ -78,21 +110,11 @@ namespace WotBlitzStatisticsPro.Common.Model
|
||||
///</summary>
|
||||
public long MaxFrags { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Tank id, which kills max frags per battle
|
||||
///</summary>
|
||||
public long MaxFragsTankId { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Max experience per battle
|
||||
///</summary>
|
||||
public long MaxXp { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Tank Id which created max experience per battle
|
||||
///</summary>
|
||||
public long MaxXpTankId { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total shots count
|
||||
///</summary>
|
||||
@@ -109,7 +131,7 @@ namespace WotBlitzStatisticsPro.Common.Model
|
||||
public long SurvivedBattles { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total count of survived and winned battles
|
||||
/// Total count of survived and won battles
|
||||
///</summary>
|
||||
public long WinAndSurvived { get; set; }
|
||||
|
||||
@@ -123,54 +145,37 @@ namespace WotBlitzStatisticsPro.Common.Model
|
||||
///</summary>
|
||||
public long Xp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Average tier
|
||||
/// </summary>
|
||||
public double AvgTier { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Wn7 coefficient
|
||||
/// </summary>
|
||||
public double Wn7 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Player's win rate
|
||||
/// </summary>
|
||||
public decimal WinRate => Battles == 0 ? 0m : (decimal) 100 * Wins / Battles;
|
||||
/// <summary>
|
||||
/// Player's win rate
|
||||
/// </summary>
|
||||
public decimal WinRate => Battles == 0 ? 0m : (decimal)100 * Wins / Battles;
|
||||
|
||||
/// <summary>
|
||||
/// Player's average damage
|
||||
/// </summary>
|
||||
public decimal AvgDamage => Battles == 0 ? 0m : (decimal)DamageDealt / Battles;
|
||||
public decimal AvgDamage => Battles == 0 ? 0m : (decimal)DamageDealt / Battles;
|
||||
|
||||
/// <summary>
|
||||
/// Player's average XP
|
||||
/// </summary>
|
||||
public decimal AvgXp => Battles == 0 ? 0m : (decimal)Xp / Battles;
|
||||
|
||||
/// <summary>
|
||||
/// Damage coefficient
|
||||
/// </summary>
|
||||
public decimal DamageCoefficient => DamageReceived == 0 ? 0m : (decimal) DamageDealt / DamageReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Rate of survival
|
||||
/// </summary>
|
||||
public decimal SurvivalRate => Battles == 0 ? 0m : (decimal) 100 * SurvivedBattles / Battles;
|
||||
public decimal AvgXp => Battles == 0 ? 0m : (decimal)Xp / Battles;
|
||||
|
||||
/// <summary>
|
||||
/// All player's tanks
|
||||
/// Damage coefficient
|
||||
/// </summary>
|
||||
public List<TankInfoResponse>? Tanks { get; set; }
|
||||
public decimal DamageCoefficient => DamageReceived == 0 ? 0m : (decimal)DamageDealt / DamageReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Clan info
|
||||
/// Rate of survival
|
||||
/// </summary>
|
||||
public ClanInfoResponse? ClanInfo { get; set; }
|
||||
public decimal SurvivalRate => Battles == 0 ? 0m : (decimal)100 * SurvivedBattles / Battles;
|
||||
|
||||
/// <summary>
|
||||
/// Account Region and request language
|
||||
/// </summary>
|
||||
public RealmAndLanguage RegionAndLanguage { get; set; } = new(RealmType.Eu, RequestLanguage.En);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Common.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents game's statistics
|
||||
/// </summary>
|
||||
public interface IStatisticsResponse
|
||||
{
|
||||
///<summary>
|
||||
/// Last battle time
|
||||
///</summary>
|
||||
DateTime LastBattleTime { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Battles count
|
||||
///</summary>
|
||||
long Battles { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Capture points
|
||||
///</summary>
|
||||
long CapturePoints { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total damage amount
|
||||
///</summary>
|
||||
long DamageDealt { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total amount of received damage
|
||||
///</summary>
|
||||
long DamageReceived { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Dropped capture points
|
||||
///</summary>
|
||||
long DroppedCapturePoints { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total amount of frags
|
||||
///</summary>
|
||||
long Frags { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total amount of frags grater ten 8 lvl
|
||||
///</summary>
|
||||
long Frags8P { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total amount of hits
|
||||
///</summary>
|
||||
long Hits { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total amount of losses
|
||||
///</summary>
|
||||
long Losses { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Max frags per battle
|
||||
///</summary>
|
||||
long MaxFrags { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Max experience per battle
|
||||
///</summary>
|
||||
long MaxXp { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total shots count
|
||||
///</summary>
|
||||
long Shots { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total count of spotted vehicles
|
||||
///</summary>
|
||||
long Spotted { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total count of survived battles
|
||||
///</summary>
|
||||
long SurvivedBattles { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total count of survived and won battles
|
||||
///</summary>
|
||||
long WinAndSurvived { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total wins count
|
||||
///</summary>
|
||||
long Wins { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total amount of experience
|
||||
///</summary>
|
||||
long Xp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Wn7 coefficient
|
||||
/// </summary>
|
||||
double Wn7 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Player's win rate
|
||||
/// </summary>
|
||||
decimal WinRate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Player's average damage
|
||||
/// </summary>
|
||||
decimal AvgDamage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Player's average XP
|
||||
/// </summary>
|
||||
decimal AvgXp { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Damage coefficient
|
||||
/// </summary>
|
||||
decimal DamageCoefficient { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Rate of survival
|
||||
/// </summary>
|
||||
decimal SurvivalRate { get; }
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace WotBlitzStatisticsPro.Common.Model
|
||||
/// <summary>
|
||||
/// Information about player's tank
|
||||
/// </summary>
|
||||
public class TankInfoResponse
|
||||
public class TankInfoResponse: IStatisticsResponse
|
||||
{
|
||||
///<summary>
|
||||
/// Player account identifier
|
||||
@@ -17,16 +17,6 @@ namespace WotBlitzStatisticsPro.Common.Model
|
||||
///</summary>
|
||||
public long TankId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total time in battle until tank killed
|
||||
/// </summary>
|
||||
public int BattleLifeTimeInSeconds { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Last battle
|
||||
///</summary>
|
||||
public DateTime LastBattleTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Information is tank in garage or not. Information is not provided without Auth token
|
||||
/// </summary>
|
||||
@@ -37,126 +27,15 @@ namespace WotBlitzStatisticsPro.Common.Model
|
||||
///</summary>
|
||||
public MarkOfMastery MarkOfMastery { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Battles count
|
||||
///</summary>
|
||||
public long Battles { get; set; } = 1;
|
||||
|
||||
///<summary>
|
||||
/// Base capture points
|
||||
///</summary>
|
||||
public long CapturePoints { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Damage dealt
|
||||
///</summary>
|
||||
public long DamageDealt { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Damage received
|
||||
///</summary>
|
||||
public long DamageReceived { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Base dropped capture points
|
||||
///</summary>
|
||||
public long DroppedCapturePoints { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Frags count
|
||||
///</summary>
|
||||
public long Frags { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Frags count after 8 tier
|
||||
///</summary>
|
||||
public long Frags8P { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Hits count
|
||||
///</summary>
|
||||
public long Hits { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Losses count
|
||||
///</summary>
|
||||
public long Losses { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Max frags per battle
|
||||
///</summary>
|
||||
public long MaxFrags { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Max XP per battle
|
||||
///</summary>
|
||||
public long MaxXp { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Shots count
|
||||
///</summary>
|
||||
public long Shots { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Spotted vehicles count
|
||||
///</summary>
|
||||
public long Spotted { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Amount of survived battles
|
||||
///</summary>
|
||||
public long SurvivedBattles { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Amount of survived and wined battles
|
||||
///</summary>
|
||||
public long WinAndSurvived { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Wins count
|
||||
///</summary>
|
||||
public long Wins { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total experience
|
||||
///</summary>
|
||||
public long Xp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Wn7 coefficient
|
||||
/// Total time in battle until tank killed
|
||||
/// </summary>
|
||||
public double Wn7 { get; set; }
|
||||
public int BattleLifeTimeInSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Average life time in battle until tank is killed.
|
||||
/// </summary>
|
||||
public decimal AvgBattleLifeTimeInMinutes => (decimal) BattleLifeTimeInSeconds / (60 * Battles);
|
||||
|
||||
/// <summary>
|
||||
/// Tank's win rate
|
||||
/// </summary>
|
||||
public decimal WinRate => (decimal) 100 * Wins / Battles;
|
||||
|
||||
/// <summary>
|
||||
/// Average tank's damage
|
||||
/// </summary>
|
||||
public decimal AvgDamage => (decimal) DamageDealt / Battles;
|
||||
|
||||
/// <summary>
|
||||
/// Average XP
|
||||
/// </summary>
|
||||
public decimal AvgXp => (decimal) Xp / Battles;
|
||||
|
||||
/// <summary>
|
||||
/// Damage coefficient
|
||||
/// </summary>
|
||||
public decimal DamageCoefficient => DamageReceived == 0 ? 0m : (decimal)DamageDealt / DamageReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Rate of survival
|
||||
/// </summary>
|
||||
public decimal SurvivalRate => (decimal)100 * SurvivedBattles / Battles;
|
||||
|
||||
public decimal AvgBattleLifeTimeInMinutes => (decimal)BattleLifeTimeInSeconds / (60 * Battles);
|
||||
|
||||
/// <summary>
|
||||
/// Tank name
|
||||
@@ -203,6 +82,129 @@ namespace WotBlitzStatisticsPro.Common.Model
|
||||
/// </summary>
|
||||
public string? NormalImage { get; set; }
|
||||
|
||||
#region statistics
|
||||
|
||||
}
|
||||
///<summary>
|
||||
/// Last battle time
|
||||
///</summary>
|
||||
public DateTime LastBattleTime { get; set; } = new DateTime(1970, 1, 1);
|
||||
|
||||
///<summary>
|
||||
/// Battles count
|
||||
///</summary>
|
||||
public long Battles { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Capture points
|
||||
///</summary>
|
||||
public long CapturePoints { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total damage amount
|
||||
///</summary>
|
||||
public long DamageDealt { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total amount of received damage
|
||||
///</summary>
|
||||
public long DamageReceived { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Dropped capture points
|
||||
///</summary>
|
||||
public long DroppedCapturePoints { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total amount of frags
|
||||
///</summary>
|
||||
public long Frags { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total amount of fras grater ten 8 lvl
|
||||
///</summary>
|
||||
public long Frags8P { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total amount of hits
|
||||
///</summary>
|
||||
public long Hits { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total amount of losses
|
||||
///</summary>
|
||||
public long Losses { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Max frags per battle
|
||||
///</summary>
|
||||
public long MaxFrags { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Max experience per battle
|
||||
///</summary>
|
||||
public long MaxXp { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total shots count
|
||||
///</summary>
|
||||
public long Shots { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total count of spotted vehicles
|
||||
///</summary>
|
||||
public long Spotted { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total count of survived battles
|
||||
///</summary>
|
||||
public long SurvivedBattles { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total count of survived and won battles
|
||||
///</summary>
|
||||
public long WinAndSurvived { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total wins count
|
||||
///</summary>
|
||||
public long Wins { get; set; }
|
||||
|
||||
///<summary>
|
||||
/// Total amount of experience
|
||||
///</summary>
|
||||
public long Xp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Wn7 coefficient
|
||||
/// </summary>
|
||||
public double Wn7 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Player's win rate
|
||||
/// </summary>
|
||||
public decimal WinRate => Battles == 0 ? 0m : (decimal)100 * Wins / Battles;
|
||||
|
||||
/// <summary>
|
||||
/// Player's average damage
|
||||
/// </summary>
|
||||
public decimal AvgDamage => Battles == 0 ? 0m : (decimal)DamageDealt / Battles;
|
||||
|
||||
/// <summary>
|
||||
/// Player's average XP
|
||||
/// </summary>
|
||||
public decimal AvgXp => Battles == 0 ? 0m : (decimal)Xp / Battles;
|
||||
|
||||
/// <summary>
|
||||
/// Damage coefficient
|
||||
/// </summary>
|
||||
public decimal DamageCoefficient => DamageReceived == 0 ? 0m : (decimal)DamageDealt / DamageReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Rate of survival
|
||||
/// </summary>
|
||||
public decimal SurvivalRate => Battles == 0 ? 0m : (decimal)100 * SurvivedBattles / Battles;
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using HotChocolate.Types;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.GraphQl.ObjectTypes
|
||||
{
|
||||
[ExtendObjectType(Name = "Query")]
|
||||
public class StatisticsResponseType: InterfaceType<IStatisticsResponse>
|
||||
{
|
||||
protected override void Configure(IInterfaceTypeDescriptor<IStatisticsResponse> descriptor)
|
||||
{
|
||||
descriptor.Name("Statistics");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using HotChocolate.Types;
|
||||
using WotBlitzStatisticsPro.Common.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.GraphQl.ObjectTypes
|
||||
{
|
||||
[ExtendObjectType(Name = "Query")]
|
||||
public class TankInfoResponseType: ObjectType<TankInfoResponse>
|
||||
{
|
||||
protected override void Configure(IObjectTypeDescriptor<TankInfoResponse> descriptor)
|
||||
{
|
||||
descriptor.Name("TankInfoResponse");
|
||||
descriptor.Implements<StatisticsResponseType>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<AccountInfoResponse> descriptor)
|
||||
{
|
||||
descriptor.Name("AccountInfoResponse");
|
||||
descriptor.Implements<StatisticsResponseType>();
|
||||
|
||||
descriptor.Field(t => t.ClanInfo)
|
||||
.Resolver(ctx => ctx.Service<IWargamingClans>().GelClanInfoByAccount(ctx.Parent<AccountInfoResponse>().AccountId, ctx.Parent<AccountInfoResponse>().RegionAndLanguage));
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ namespace WotBlitzStatisticsPro.GraphQl
|
||||
.AddType<WotBlitzStatisticsQuery>()
|
||||
.AddType<AccountInfoResolver>()
|
||||
.AddType<WotBlitzAchievementsQuery>()
|
||||
.AddType<TankInfoResponseType>()
|
||||
.AddMutationType(d => d.Name("Mutation"))
|
||||
.AddType<WotBlitzStatisticsMutation>()
|
||||
.AddType<AuthenticationMutation>()
|
||||
|
||||
Reference in new issue
Block a user