From 50ecb575919e2b783ec0186ed8ab7af177731584 Mon Sep 17 00:00:00 2001 From: Mikhail Shabanov Date: Thu, 20 Aug 2020 13:40:08 +0200 Subject: [PATCH] Account info step --- .../Model/Accounts/AccountInfoHistory.cs | 120 ++++++++++++++++++ .../AccountInformationPipelineContext.cs | 5 + .../Operations/GetAccountInfoOperation.cs | 31 ++++- .../Mappers/AccountInfoProfile.cs | 14 ++ .../Mappers/AccountInfoStatisticsProfile.cs | 14 ++ .../Model/WotAccountFullStatistics.cs | 38 +++--- .../Model/WotAccountInfo.cs | 8 +- 7 files changed, 205 insertions(+), 25 deletions(-) create mode 100644 WotBlitzStatisticsPro.DataAccess/Model/Accounts/AccountInfoHistory.cs create mode 100644 WotBlitzStatisticsPro.Logic/Mappers/AccountInfoProfile.cs create mode 100644 WotBlitzStatisticsPro.Logic/Mappers/AccountInfoStatisticsProfile.cs diff --git a/WotBlitzStatisticsPro.DataAccess/Model/Accounts/AccountInfoHistory.cs b/WotBlitzStatisticsPro.DataAccess/Model/Accounts/AccountInfoHistory.cs new file mode 100644 index 0000000..374e62b --- /dev/null +++ b/WotBlitzStatisticsPro.DataAccess/Model/Accounts/AccountInfoHistory.cs @@ -0,0 +1,120 @@ +namespace WotBlitzStatisticsPro.DataAccess.Model.Accounts +{ + public class AccountInfoHistory + { + /// + /// Player account identifier + /// + public long AccountId { get; set; } + + /// + /// Last battle time + /// + public int LastBattleTime { get; set; } + + /// + /// 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; } + + /// + /// 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 experiense per battle + /// + public long? MaxXpTankId { 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 suvived and winned battles + /// + public long? WinAndSurvived { get; set; } + + /// + /// Total wins count + /// + public long? Wins { get; set; } + + /// + /// Total amount of experience + /// + public long? Xp { get; set; } + + /// + /// Average tier + /// + public double AvgTier { get; set; } + + /// + /// Wn7 coefficient + /// + public double Wn7 { get; set; } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Logic/AccountInformationPipeline/AccountInformationPipelineContext.cs b/WotBlitzStatisticsPro.Logic/AccountInformationPipeline/AccountInformationPipelineContext.cs index 5a111ad..ab29c99 100644 --- a/WotBlitzStatisticsPro.Logic/AccountInformationPipeline/AccountInformationPipelineContext.cs +++ b/WotBlitzStatisticsPro.Logic/AccountInformationPipeline/AccountInformationPipelineContext.cs @@ -1,4 +1,5 @@ using WotBlitzStatisticsPro.Common.Model; +using WotBlitzStatisticsPro.DataAccess.Model.Accounts; namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline { @@ -19,5 +20,9 @@ namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline public RealmType RealmType { get; } public RequestLanguage RequestLanguage { get; } + public AccountInfo AccountInfo { get; set; } + + public AccountInfoHistory AccountInfoHistory { get; set; } + } } \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Logic/AccountInformationPipeline/Operations/GetAccountInfoOperation.cs b/WotBlitzStatisticsPro.Logic/AccountInformationPipeline/Operations/GetAccountInfoOperation.cs index 56dfc2b..1029bd8 100644 --- a/WotBlitzStatisticsPro.Logic/AccountInformationPipeline/Operations/GetAccountInfoOperation.cs +++ b/WotBlitzStatisticsPro.Logic/AccountInformationPipeline/Operations/GetAccountInfoOperation.cs @@ -1,14 +1,41 @@ using System; using System.Threading.Tasks; +using AutoMapper; +using WotBlitzStatisticsPro.DataAccess.Model.Accounts; using WotBlitzStatisticsPro.Logic.Pipeline; +using WotBlitzStatisticsPro.WgApiClient; +using WotBlitzStatisticsPro.WgApiClient.Model; namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations { public class GetAccountInfoOperation: IOperation { - public Task Invoke(AccountInformationPipelineContext context, Func next) + private readonly IWargamingApiClient _wargamingApi; + private readonly IMapper _mapper; + + public GetAccountInfoOperation( + IWargamingApiClient wargamingApi, + IMapper mapper) { - return next.Invoke(context); + _wargamingApi = wargamingApi; + _mapper = mapper; + } + + public async Task Invoke(AccountInformationPipelineContext context, Func next) + { + var accountInfo = await + _wargamingApi.GetPlayerAccountInfo(context.AccountId, context.RealmType, context.RequestLanguage); + + // Store info to AccountInfo and in AccountInfoHistory + context.AccountInfo = _mapper.Map(accountInfo); + context.AccountInfo.Realm = context.RealmType; + + context.AccountInfoHistory = + _mapper.Map(accountInfo.Statistics.All); + context.AccountInfoHistory.AccountId = context.AccountId; + context.AccountInfoHistory.LastBattleTime = context.AccountInfo.LastBattleTime; + + await next.Invoke(context); } } } \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Logic/Mappers/AccountInfoProfile.cs b/WotBlitzStatisticsPro.Logic/Mappers/AccountInfoProfile.cs new file mode 100644 index 0000000..303a691 --- /dev/null +++ b/WotBlitzStatisticsPro.Logic/Mappers/AccountInfoProfile.cs @@ -0,0 +1,14 @@ +using AutoMapper; +using WotBlitzStatisticsPro.DataAccess.Model.Accounts; +using WotBlitzStatisticsPro.WgApiClient.Model; + +namespace WotBlitzStatisticsPro.Logic.Mappers +{ + public class AccountInfoProfile : Profile + { + public AccountInfoProfile() + { + CreateMap(); + } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.Logic/Mappers/AccountInfoStatisticsProfile.cs b/WotBlitzStatisticsPro.Logic/Mappers/AccountInfoStatisticsProfile.cs new file mode 100644 index 0000000..4253e50 --- /dev/null +++ b/WotBlitzStatisticsPro.Logic/Mappers/AccountInfoStatisticsProfile.cs @@ -0,0 +1,14 @@ +using AutoMapper; +using WotBlitzStatisticsPro.DataAccess.Model.Accounts; +using WotBlitzStatisticsPro.WgApiClient.Model; + +namespace WotBlitzStatisticsPro.Logic.Mappers +{ + public class AccountInfoStatisticsProfile : Profile + { + public AccountInfoStatisticsProfile() + { + CreateMap(); + } + } +} \ No newline at end of file diff --git a/WotBlitzStatisticsPro.WgApiClient/Model/WotAccountFullStatistics.cs b/WotBlitzStatisticsPro.WgApiClient/Model/WotAccountFullStatistics.cs index 64692e4..58bb967 100644 --- a/WotBlitzStatisticsPro.WgApiClient/Model/WotAccountFullStatistics.cs +++ b/WotBlitzStatisticsPro.WgApiClient/Model/WotAccountFullStatistics.cs @@ -8,114 +8,114 @@ namespace WotBlitzStatisticsPro.WgApiClient.Model /// Battles count /// [JsonProperty("battles")] - public long? Battles { get; set; } + public long Battles { get; set; } /// /// Capture points /// [JsonProperty("capture_points")] - public long? CapturePoints { get; set; } + public long CapturePoints { get; set; } /// /// Total damage amount /// [JsonProperty("damage_dealt")] - public long? DamageDealt { get; set; } + public long DamageDealt { get; set; } /// /// Total amount of received damage /// [JsonProperty("damage_received")] - public long? DamageReceived { get; set; } + public long DamageReceived { get; set; } /// /// Dropped capture points /// [JsonProperty("dropped_capture_points")] - public long? DroppedCapturePoints { get; set; } + public long DroppedCapturePoints { get; set; } /// /// Total amount of frags /// [JsonProperty("frags")] - public long? Frags { get; set; } + public long Frags { get; set; } /// /// Total amount of fras grater ten 8 lvl /// [JsonProperty("frags8p")] - public long? Frags8P { get; set; } + public long Frags8P { get; set; } /// /// Total amount of hits /// [JsonProperty("hits")] - public long? Hits { get; set; } + public long Hits { get; set; } /// /// Total amount of losses /// [JsonProperty("losses")] - public long? Losses { get; set; } + public long Losses { get; set; } /// /// Max frags per battle /// [JsonProperty("max_frags")] - public long? MaxFrags { get; set; } + public long MaxFrags { get; set; } /// /// Tank id, which kills max frags per battle /// [JsonProperty("max_frags_tank_id")] - public long? MaxFragsTankId { get; set; } + public long MaxFragsTankId { get; set; } /// /// Max experience per battle /// [JsonProperty("max_xp")] - public long? MaxXp { get; set; } + public long MaxXp { get; set; } /// /// Tank Id which created max experiense per battle /// [JsonProperty("max_xp_tank_id")] - public long? MaxXpTankId { get; set; } + public long MaxXpTankId { get; set; } /// /// Total shots count /// [JsonProperty("shots")] - public long? Shots { get; set; } + public long Shots { get; set; } /// /// Total count of spotted vehicles /// [JsonProperty("spotted")] - public long? Spotted { get; set; } + public long Spotted { get; set; } /// /// Total count of survived battles /// [JsonProperty("survived_battles")] - public long? SurvivedBattles { get; set; } + public long SurvivedBattles { get; set; } /// /// Total count of suvived and winned battles /// [JsonProperty("win_and_survived")] - public long? WinAndSurvived { get; set; } + public long WinAndSurvived { get; set; } /// /// Total wins count /// [JsonProperty("wins")] - public long? Wins { get; set; } + public long Wins { get; set; } /// /// Total amount of experience /// [JsonProperty("xp")] - public long? Xp { get; set; } + public long Xp { get; set; } } } diff --git a/WotBlitzStatisticsPro.WgApiClient/Model/WotAccountInfo.cs b/WotBlitzStatisticsPro.WgApiClient/Model/WotAccountInfo.cs index f04b1de..ba70175 100644 --- a/WotBlitzStatisticsPro.WgApiClient/Model/WotAccountInfo.cs +++ b/WotBlitzStatisticsPro.WgApiClient/Model/WotAccountInfo.cs @@ -8,19 +8,19 @@ namespace WotBlitzStatisticsPro.WgApiClient.Model /// Player account identifier /// [JsonProperty("account_id")] - public long? AccountId { get; set; } + public long AccountId { get; set; } /// /// Account creation date /// [JsonProperty("created_at")] - public int? CreatedAt { get; set; } + public int CreatedAt { get; set; } /// /// Last battle time /// [JsonProperty("last_battle_time")] - public int? LastBattleTime { get; set; } + public int LastBattleTime { get; set; } /// /// Player's nick @@ -32,7 +32,7 @@ namespace WotBlitzStatisticsPro.WgApiClient.Model /// Player information update date /// [JsonProperty("updated_at")] - public int? UpdatedAt { get; set; } + public int UpdatedAt { get; set; } /// /// Private account data