public async Task <KillLeader> GetLiveKillList(int topCount) { var teams = _team.GetAll("Team"); var teamPlayers = _teamPlayerRepository.GetTeamPlayers(); var liveEventKillList = _LiveEventKill.GetAll("LiveEventKill"); await Task.WhenAll(teams, teamPlayers, liveEventKillList); var result = liveEventKillList.Result.Where(ev => !ev.IsGroggy && ev.KillerTeamId != ev.VictimTeamId) .Join(teamPlayers.Result, ev => new { KillerName = ev.KillerName }, tp => new { KillerName = tp.PlayerName }, (ev, tp) => new { ev, tp }) .Join(teams.Result, evTp => new { TeamId = evTp.tp.TeamId }, t => new { TeamId = t.Id }, (evTp, t) => new { evTp, t }) .GroupBy(g => g.evTp.ev.KillerName) .Select(s => new Kills() { kills = s.Count(), playerName = s.Key, playerId = s.FirstOrDefault().evTp.tp.PlayerId, teamId = s.FirstOrDefault().t.TeamId, }) .OrderByDescending(o => o.kills) .Take(topCount > 0 ? topCount : 10); var killLeaders = new KillLeader() { //matchId = matchId, killList = result }; return(killLeaders); }
public async Task <KillLeader> GetKillLeaderList() { _logger.LogInformation("GetKillLeaderList Repository Function call started" + Environment.NewLine); var matchstats = _genericMatchPlayerStatsRepository.GetMongoDbCollection("MatchPlayerStats"); var matchstat = matchstats.FindAsync(new BsonDocument()).Result.ToListAsync().Result; var sortByKill = matchstat.AsQueryable().OrderByDescending(o => o.stats.Kills); var teams = _team.GetAll("Team").Result.ToList(); var teamPlayers = _teamPlayerRepository.GetTeamPlayers().Result; var killList = sortByKill.Join(teams, s => s.TeamId, t => t.Id, (s, t) => new { s, t }) .Join(teamPlayers, kl => kl.s.stats.Name.Trim(), tp => tp.PlayerName.Trim(), (kl, pl) => new { kl, pl }) .GroupBy(g => g.pl.PlayerName) .Select(klt => new Kills() { kills = klt.Sum(a => a.kl.s.stats.Kills), teamId = klt.Select(a => a.kl.t.TeamId).ElementAtOrDefault(0), timeSurvived = klt.Sum(a => a.kl.s.stats.TimeSurvived), playerId = klt.Select(a => a.pl.PlayerId).ElementAtOrDefault(0), playerName = klt.Key, DamageDealt = klt.Sum(a => a.kl.s.stats.DamageDealt) }).OrderByDescending(o => o.kills); var killLeaders = new KillLeader() { matchId = 0, killList = killList }; _logger.LogInformation("GetKillLeaderList Repository Function call completed" + Environment.NewLine); return(killLeaders); }
public Task <KillLeader> GetKillLeaderListToppedByDamageDealt() { var KillLeaderList = GetKillLeaderList(); var KillListToppedByDamageDealt = KillLeaderList.Result.killList.OrderByDescending(o => o.DamageDealt); var killLeaders = new KillLeader() { matchId = 0, killList = KillListToppedByDamageDealt }; return(Task.FromResult(killLeaders)); }
public Task <KillLeader> GetKillLeaderListTopByTimed() { var KillLeaderList = GetKillLeaderList(); var KillLeaderListByTimeTopped = KillLeaderList.Result.killList.OrderByDescending(o => o.timeSurvived); var killLeaders = new KillLeader() { matchId = 0, killList = KillLeaderListByTimeTopped }; return(Task.FromResult(killLeaders)); }
private IDictionary <int, int> GetTeamKillPoints(KillLeader killLeader) { var result = new Dictionary <int, int>(); foreach (var kill in killLeader.killList) { var points = MatchConstants.PointsPerKill * kill.kills; if (result.ContainsKey(kill.teamId)) { result[kill.teamId] += points; } else { result.Add(kill.teamId, points); } } return(result); }
public async Task <KillLeader> GetKillLeaderList(int matchId, int topCount) { _logger.LogInformation("GetKillLeaderList with matchId and top count Repository Function call started" + Environment.NewLine); IEnumerable <Kills> killList; if (topCount > 0) { killList = GetMatchPlayerStatsForMatchId(matchId, topCount); } else { killList = GetMatchPlayerStatsForMatchId(matchId, 0); } var killLeader = new KillLeader() { matchId = matchId, killList = killList }; _logger.LogInformation("GetKillLeaderList with matchId and top count Repository Function call completed" + Environment.NewLine); return(await Task.FromResult(killLeader)); }
public Task <IEnumerable <LiveTeamRanking> > GetTeamRankings(KillLeader killLeader, IEnumerable <LiveMatchStatus> liveStatus) { var ranking = new List <LiveTeamRanking>(); // Set kill, rank and total points var killPoints = GetTeamKillPoints(killLeader); var rankPoints = GetTeamRankPoints(liveStatus); foreach (var team in liveStatus) { var rp = rankPoints[team.TeamId]; var kp = 0; if (killPoints.ContainsKey(team.TeamId)) { kp = killPoints[team.TeamId]; } ranking.Add(new LiveTeamRanking { TeamId = team.TeamId, TeamName = team.TeamName, RankPoints = rp, KillPoints = kp, TotalPoints = rp + kp }); } // Sort by total points and set the rank accordingly ranking.Sort((a, b) => b.TotalPoints.CompareTo(a.TotalPoints)); var i = 1; foreach (var team in ranking) { team.TeamRank = i++; } return(Task.FromResult(ranking.AsEnumerable())); }