public async Task Invoke(IOperationContext context, Func <IOperationContext, Task>?next) { var contextData = context.Get <AccountInformationPipelineContextData>(); var tanksInfo = await _wargamingApi.GetPlayerAccountTanksInfo(context.Request.AccountId, context.Request.RealmType, context.Request.RequestLanguage); if (tanksInfo == null) { _logger.LogInformation( $"Tanks not found for AccountId {context.Request.AccountId} and {context.Request.RealmType} realm"); return; } contextData.Tanks = new List <TankInfo>(); contextData.TanksHistory = new Dictionary <long, TankInfoHistory>(); tanksInfo.OrderByDescending(t => t.LastBattleTime).ToList().ForEach(tank => { var tankInfo = new TankInfo(tank.AccountId, tank.TankId); _mapper.Map(tank, tankInfo); contextData.Tanks.Add(tankInfo); var stat = new TankInfoHistory(tank.AccountId, tank.TankId, tank.LastBattleTime); _mapper.Map(tank.All, stat); contextData.TanksHistory[stat.TankId] = stat; }); if (next != null) { await next.Invoke(context); } }
private async Task SetTanksInfo(string tanksInfoFileName, AccountInformationPipelineContextData contextData) { List <WotAccountTanksStatistics> tanksInfo = null; using (var r = new StreamReader(tanksInfoFileName)) { var json = await r.ReadToEndAsync(); var tanks = JsonConvert.DeserializeObject <ResponseBody <Dictionary <string, List <WotAccountTanksStatistics> > > >(json); tanksInfo = tanks.Data?.Values.FirstOrDefault(); } if (tanksInfo == null) { throw new ApplicationException($"Can not read tanks info from '{tanksInfoFileName}'"); } contextData.Tanks = new List <TankInfo>(); contextData.TanksHistory = new Dictionary <long, TankInfoHistory>(); tanksInfo.OrderByDescending(t => t.LastBattleTime).ToList().ForEach(tank => { var tankInfo = new TankInfo(tank.AccountId, tank.TankId); _mapper.Map(tank, tankInfo); contextData.Tanks.Add(tankInfo); var stat = new TankInfoHistory(tank.AccountId, tank.TankId, tank.LastBattleTime); _mapper.Map(tank.All, stat); contextData.TanksHistory[stat.TankId] = stat; }); }
private async Task<List<(MarkOfMastery Mastery, int BattleLifetime, TankInfoHistory history)>> GetTanksHistory( long accountId, int lastBattleTime, DbConnection connection) { var resultList = new List<(MarkOfMastery Mastery, int BattleLifetime, TankInfoHistory history)>(); using (var command = connection.CreateCommand()) { command.CommandText = TanksInfoHistoryQuery; command.Parameters.Add(new SqlParameter("LastBattleTime", SqlDbType.DateTime) { Value = lastBattleTime.ToDateTime() }); command.Parameters.Add(new SqlParameter("AccountId", SqlDbType.Int) { Value = accountId }); if (connection.State.Equals(ConnectionState.Closed)) { await connection.OpenAsync(); } using (var reader = await command.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var tankHistory = new TankInfoHistory( reader.GetInt64(reader.GetOrdinal("AccountId")), reader.GetInt64(reader.GetOrdinal("TankId")), reader.GetInt32(reader.GetOrdinal("LastBattleTime"))) { Battles = reader.GetInt64(reader.GetOrdinal("Battles")), CapturePoints = reader.GetInt64(reader.GetOrdinal("CapturePoints")), DamageDealt = reader.GetInt64(reader.GetOrdinal("DamageDealt")), DamageReceived = reader.GetInt64(reader.GetOrdinal("DamageReceived")), DroppedCapturePoints = reader.GetInt64(reader.GetOrdinal("DroppedCapturePoints")), Frags = reader.GetInt64(reader.GetOrdinal("Frags")), Frags8P = reader.GetInt64(reader.GetOrdinal("Frags8P")), Hits = reader.GetInt64(reader.GetOrdinal("Hits")), Losses = reader.GetInt64(reader.GetOrdinal("Losses")), MaxFrags = reader.GetInt64(reader.GetOrdinal("MaxFrags")), MaxXp = reader.GetInt64(reader.GetOrdinal("MaxXp")), Shots = reader.GetInt64(reader.GetOrdinal("Shots")), Spotted = reader.GetInt64(reader.GetOrdinal("Spotted")), SurvivedBattles = reader.GetInt64(reader.GetOrdinal("SurvivedBattles")), WinAndSurvived = reader.GetInt64(reader.GetOrdinal("WinAndSurvived")), Wins = reader.GetInt64(reader.GetOrdinal("Wins")), Xp = reader.GetInt64(reader.GetOrdinal("Xp")), Wn7 = reader.GetDouble(reader.GetOrdinal("Wn7")) }; resultList.Add(( (MarkOfMastery) reader.GetInt32(reader.GetOrdinal("MarkOfMastery")), reader.GetInt32(reader.GetOrdinal("BattleLifeTimeInSeconds")), tankHistory)); } } } return resultList; }
public static void CalculateWn7(this TankInfoHistory tank, double tier) { if (!tank.Battles.HasValue) { return; } double avdFrags = (double)tank.Frags.DoubleValue() / tank.Battles.DoubleValue(); double avgDamage = (double)tank.DamageDealt.DoubleValue() / tank.Battles.DoubleValue(); double avgSpot = (double)tank.Spotted.DoubleValue() / tank.Battles.DoubleValue(); double avgDef = (double)tank.DroppedCapturePoints.DoubleValue() / tank.Battles.DoubleValue(); double winRate = (100d * (double)tank.Wins.DoubleValue() / tank.Battles.DoubleValue()); // - 48; tank.Wn7 = CalculateWn7(tank.Battles.Value, tier, avdFrags, avgDamage, avgSpot, avgDef, winRate); }