Preparing for the History query

This commit is contained in:
Mikhail Shabanov committed 2020-11-17 11:01:35 +01:00
1 parent ddbf42e7bb
commit ed52a65788
14 files changed
+334 -6

No files matched your search

+63
View File
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
@@ -0,0 +1,45 @@
using System;
namespace WotBlitzStatisticsPro.Common.Model
{
/// <summary>
/// Information about player statistics history
/// </summary>
public class AccountInfoHistoryResponse
{
///<summary>
/// Player account identifier
///</summary>
public long AccountId { get; set; }
///<summary>
/// Account creation date
///</summary>
public DateTime CreatedAt { get; set; }
///<summary>
/// Player's nick
///</summary>
public string Nickname { get; set; }
/// <summary>
/// Overall statistics since account creation
/// </summary>
public ShortStatistics OverallAccountStatistics { get; set; }
/// <summary>
/// Statistics for period
/// </summary>
public ShortStatistics PeriodAccountStatistics { get; set; }
/// <summary>
/// Difference between start and end of the period
/// </summary>
public StatisticsDifference PeriodDifference { get; set; }
/// <summary>
/// The detailed history
/// </summary>
public StatisticsDifference[] StatisticsHistory { get; set; }
}
}
@@ -0,0 +1,46 @@
using System;
namespace WotBlitzStatisticsPro.Common.Model
{
/// <summary>
/// Short statistics info
/// </summary>
public class ShortStatistics
{
///<summary>
/// Last battle time
///</summary>
public DateTime LastBattleTime { get; set; }
///<summary>
/// Battles count
///</summary>
public long Battles { 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 { get; set; }
/// <summary>
/// Player's average damage
/// </summary>
public decimal AvgDamage { get; set; }
/// <summary>
/// Player's average XP
/// </summary>
public decimal AvgXp { get; set; }
}
}
@@ -0,0 +1,46 @@
using System;
namespace WotBlitzStatisticsPro.Common.Model
{
/// <summary>
/// The difference between current statistics state and previous
/// </summary>
public class StatisticsDifference
{
///<summary>
/// Last battle time
///</summary>
public DateTime LastBattleTime { get; set; }
///<summary>
/// Difference in Battles count
///</summary>
public StatisticsDifferenceItem<long> Battles { get; set; }
/// <summary>
/// Difference in Average tier
/// </summary>
public StatisticsDifferenceItem<double> AvgTier { get; set; }
/// <summary>
/// Difference in Wn7 coefficient
/// </summary>
public StatisticsDifferenceItem<double> Wn7 { get; set; }
/// <summary>
/// Difference in Player's win rate
/// </summary>
public StatisticsDifferenceItem<decimal> WinRate { get; set; }
/// <summary>
/// Difference in Player's average damage
/// </summary>
public StatisticsDifferenceItem<decimal> AvgDamage { get; set; }
/// <summary>
/// Difference in Player's average XP
/// </summary>
public StatisticsDifferenceItem<decimal> AvgXp { get; set; }
}
}
@@ -0,0 +1,18 @@
namespace WotBlitzStatisticsPro.Common.Model
{
/// <summary>
/// Represents the difference of one statistics parameter
/// </summary>
public class StatisticsDifferenceItem<T> where T: struct
{
/// <summary>
/// The current value of statistics item
/// </summary>
public T CurrentValue { get; set; }
/// <summary>
/// The difference between current and previous value
/// </summary>
public T? Difference { get; set; }
}
}
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
namespace WotBlitzStatisticsPro.DataAccess
@@ -16,5 +17,9 @@ namespace WotBlitzStatisticsPro.DataAccess
Task AddOrUpdateTankInfo(TankInfo tankInfo);
Task AddTankInfoHistory(TankInfoHistory tankInfoHistory);
Task<IEnumerable<AccountInfoHistory>> GetAccountHistory(long accountId, int lastBattleSince);
Task<IEnumerable<TankInfoHistory>> GetTankHistory(long accountId, long tankId, int lastBattleSince);
}
}
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;
using MongoDB.Driver;
using WotBlitzStatisticsPro.Common;
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
@@ -109,5 +110,15 @@ namespace WotBlitzStatisticsPro.DataAccess
return _database.GetCollection<TankInfoHistory>(TankInfoHistoryCollectionName)
.InsertOneAsync(tankInfoHistory);
}
public Task<IEnumerable<AccountInfoHistory>> GetAccountHistory(long accountId, int lastBattleSince)
{
throw new System.NotImplementedException();
}
public Task<IEnumerable<TankInfoHistory>> GetTankHistory(long accountId, long tankId, int lastBattleSince)
{
throw new System.NotImplementedException();
}
}
}
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using WotBlitzStatisticsPro.Common.Model;
using WotBlitzStatisticsPro.Logic;
@@ -68,5 +69,23 @@ namespace WotBlitzStatisticsPro.GraphQl.Query
{
return _wargamingAccounts.GatherAccountInformation(realmType ?? RealmType.Ru, accountId, requestLanguage ?? RequestLanguage.En);
}
/// <summary>
/// Account statistics history for period since "startDate"
/// </summary>
/// <param name="accountId">AccountId</param>
/// <param name="startDate">Date from history started</param>
/// <param name="realmType">Account region</param>
/// <param name="requestLanguage">Request language</param>
/// <returns></returns>
public Task<AccountInfoHistoryResponse> AccountInfoHistory(
long accountId,
DateTime startDate,
RealmType? realmType,
RequestLanguage? requestLanguage)
{
return _wargamingAccounts.GetAccountInfoHistory(realmType ?? RealmType.Ru, accountId, startDate,
requestLanguage ?? RequestLanguage.En);
}
}
}
@@ -4,7 +4,7 @@ using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline
{
public class AccountInformationPipelineContext
public class AccountInformationPipelineContext: IDatabasePipelineContext
{
public AccountInformationPipelineContext(
long accountId,
@@ -0,0 +1,28 @@
using WotBlitzStatisticsPro.Common.Model;
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline
{
public class HistoryInformationPipelineContext: IDatabasePipelineContext
{
public HistoryInformationPipelineContext(
long accountId,
RealmType realmType,
RequestLanguage requestLanguage)
{
AccountId = accountId;
RealmType = realmType;
RequestLanguage = requestLanguage;
}
public long AccountId { get; }
public RealmType RealmType { get; }
public RequestLanguage RequestLanguage { get; }
public AccountInfo DbAccountInfo { get; set; }
public AccountInfoHistoryResponse Response { get; set; }
}
}
@@ -0,0 +1,11 @@
using WotBlitzStatisticsPro.Common.Model;
namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline
{
public interface IAccountPipelineContext
{
long AccountId { get; }
RealmType RealmType { get; }
RequestLanguage RequestLanguage { get; }
}
}
@@ -0,0 +1,9 @@
using WotBlitzStatisticsPro.DataAccess.Model.Accounts;
namespace WotBlitzStatisticsPro.Logic.AccountInformationPipeline
{
public interface IDatabasePipelineContext: IAccountPipelineContext
{
AccountInfo DbAccountInfo { get; set; }
}
}
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using WotBlitzStatisticsPro.Common.Model;
namespace WotBlitzStatisticsPro.Logic
@@ -8,5 +9,8 @@ namespace WotBlitzStatisticsPro.Logic
Task<AccountInfoResponse> GatherAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage);
Task<AccountInfoResponse> GatherAndSaveAccountInformation(RealmType realm, long accountId, RequestLanguage requestLanguage);
Task<AccountInfoHistoryResponse> GetAccountInfoHistory(RealmType realm, long accountId, DateTime startDate,
RequestLanguage requestLanguage);
}
}
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using WotBlitzStatisticsPro.Common.Model;
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline;
using WotBlitzStatisticsPro.Logic.AccountInformationPipeline.Operations;
@@ -53,5 +54,27 @@ namespace WotBlitzStatisticsPro.Logic
return context.Response;
}
public async Task<AccountInfoHistoryResponse> GetAccountInfoHistory(RealmType realm, long accountId, DateTime startDate, RequestLanguage requestLanguage)
{
var context = new HistoryInformationPipelineContext(accountId, realm, requestLanguage);
var pipeline = new Pipeline<HistoryInformationPipelineContext>(_operationFactory);
//pipeline.AddOperation<ReadAccountInfoFromDbOperation>()
// ToDo:
// 1. First read account info from DB operation
// 2. Read account history from DB at the startDate !Array SortedByDate! operation
// 3. Fill the OverallAccountStatistics
// PeriodAccountStatistics
// PeriodDifference
// StatisticsHistory
await pipeline.Build()
.Invoke(context, null)
.ConfigureAwait(false);
return context.Response;
}
}
}