public MatchDetailContract(bool isBlue, MatchDetailEntity matchDetail, PlayerStatsEntity playerStats, List <AchievementEntity> achievements)
 {
     IsBlue       = isBlue;
     MatchDetail  = matchDetail;
     PlayerStats  = playerStats;
     Achievements = achievements;
 }
 public PlayerStatsView Map(PlayerStatsEntity entity, double points)
 {
     return(new PlayerStatsView
     {
         SummonerId = entity.SummonerId,
         Kills = entity.Kills,
         Deaths = entity.Deaths,
         Assists = entity.Assists,
         Kda = Math.Round((entity.Kills + entity.Assists) / (float)entity.Deaths, 2),
         CSperMin = Math.Round(entity.CS / (float)entity.GameTime.TotalMinutes, 2),
         DamagePerMin = Math.Round(entity.Gold / (float)entity.GameTime.TotalMinutes, 2),
         Kp = Math.Round((entity.Kills + entity.Assists) / (float)entity.TotalTeamKills * 100, 1),
         VisionScore = Math.Round(entity.VisionScore / ((float)entity.Games * 100) * 100, 1),
         SeasonInfoId = entity.SeasonInfoId,
         MvpVotes = points
     });
 }
示例#3
0
        private static PlayerStatsEntity CreatePlayerMatchStat(SummonerInfoEntity registeredPlayer, Participant participant,
                                                               TimeSpan gameDuration, SeasonInfoEntity seasonInfo)
        {
            var matchStat = new PlayerStatsEntity
            {
                Id           = Guid.NewGuid(),
                SummonerId   = registeredPlayer.Id,
                Kills        = (int)participant.Stats.Kills,
                Deaths       = (int)participant.Stats.Deaths,
                Assists      = (int)participant.Stats.Assists,
                CS           = (int)(participant.Stats.TotalMinionsKilled + participant.Stats.NeutralMinionsKilled),
                Gold         = (int)participant.Stats.GoldEarned,
                VisionScore  = (int)participant.Stats.VisionScore,
                GameTime     = gameDuration,
                Games        = 1,
                SeasonInfoId = seasonInfo.Id
            };

            return(matchStat);
        }
示例#4
0
        //per player
        private ChampionStatsEntity CreateChampionStat(PlayerStatsEntity playerStats, SeasonInfoEntity seasonInfo, Guid divisionId, bool win, bool loss, Guid championId, Guid matchDetailId, Guid teamScheduleId)
        {
            var championStat = new ChampionStatsEntity
            {
                Id             = Guid.NewGuid(),
                PlayerId       = playerStats.SummonerId,
                SeasonInfoId   = seasonInfo.Id,
                DivisionId     = divisionId,
                Kills          = playerStats.Kills,
                Deaths         = playerStats.Deaths,
                Assists        = playerStats.Assists,
                Picked         = true,
                Banned         = false,
                Win            = win,
                Loss           = loss,
                ChampionId     = championId,
                MatchDetailId  = matchDetailId,
                TeamScheduleId = teamScheduleId
            };

            return(championStat);
        }
        public async Task <bool> UploadPlayerStatsAsync(IEnumerable <IFormFile> files)
        {
            var newStats   = new List <PartialPlayerInfo>();
            var seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync();

            var teamsTask             = _teamRosterRepository.GetAllTeamsAsync(seasonInfo.Id);
            var registeredPlayersTask = _summonerInfoRepository.GetAllSummonersAsync();
            var playerStatsTask       = _playerStatsRepository.GetAllStatsAsync(seasonInfo.Id);
            var teams             = (await teamsTask).ToDictionary(x => x.TeamName, x => x);
            var teamPlayers       = (await _teamPlayerRepository.ReadAllForSeasonAsync(seasonInfo.Id)).ToList();
            var registeredPlayers = (await registeredPlayersTask).ToDictionary(x => x.SummonerName.ToLowerInvariant(), x => x);

            foreach (var file in files)
            {
                if (file == null || file.Length <= 0)
                {
                    continue;
                }
                var split      = file.FileName.Split("vs");
                var team1      = split[0].Trim();
                var regexSplit = Regex.Matches(split[1], @"^ [a-zA-z ]*");
                var team2      = regexSplit.First().Value;
                team2 = team2.Remove(team2.Length - 1).Trim();

                using (var stream = file.OpenReadStream())
                {
                    var matchStats = new List <PartialPlayerInfo>();
                    for (var i = 0; i < 10; i++)
                    {
                        matchStats.Add(new PartialPlayerInfo());
                    }

                    var excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

                    var result = excelReader.AsDataSet();
                    for (var i = 0; i < result.Tables.Count; i++)
                    {
                        var sheet = result.Tables[i];
                        //Match tab
                        if (i == 0)
                        {
                            foreach (var stat in matchStats)
                            {
                                var strDuration = (string)sheet.Rows[1][4];
                                var duration    = TimeSpan.Parse(strDuration);
                                stat.Duration = duration;
                            }
                        }
                        //Team tab
                        else if (i == 1)
                        {
                            //we skip this for now
                        }

                        //Player tab
                        else if (i == 2)
                        {
                            var totalTeamKillsBlue = 0;
                            var totalTeamKillsRed  = 0;
                            for (var row = 1; row < sheet.Rows.Count; row++)
                            {
                                var player = matchStats[row - 1];
                                player.Name = (string)sheet.Rows[row][4];

                                //This is to check if a player is on the team from the match or an e-sub
                                registeredPlayers.TryGetValue(player.Name.ToLowerInvariant(), out var registeredPlayer);

                                teams.TryGetValue(team1, out var dbTeam1);
                                teams.TryGetValue(team2, out var dbTeam2);
                                if (registeredPlayer != null && (dbTeam1 != null || dbTeam2 != null))
                                {
                                    var teamPlayer = teamPlayers.FirstOrDefault(x =>
                                                                                x.SummonerId == registeredPlayer.Id && (x.TeamRosterId == dbTeam1?.Id || x.TeamRosterId == dbTeam2?.Id));
                                    if (teamPlayer == null)
                                    {
                                        player.SoftDelete = true;
                                    }
                                }

                                player.Assists = Convert.ToInt32((double)sheet.Rows[row][7]);
                                player.Deaths  = Convert.ToInt32((double)sheet.Rows[row][9]);
                                player.Gold    = Convert.ToInt32((double)sheet.Rows[row][16]);
                                player.Kills   = Convert.ToInt32((double)sheet.Rows[row][20]);
                                if (row < 6)
                                {
                                    totalTeamKillsBlue += player.Kills;
                                }
                                else
                                {
                                    totalTeamKillsRed += player.Kills;
                                }
                                player.CS          = Convert.ToInt32((double)sheet.Rows[row][22]);
                                player.VisionScore = Convert.ToInt32((double)sheet.Rows[row][23]);
                            }
                            for (var j = 0; j < matchStats.Count; j++)
                            {
                                var player = matchStats[j];
                                if (j < 5)
                                {
                                    player.TotalTeamKills = totalTeamKillsBlue;
                                }
                                else
                                {
                                    player.TotalTeamKills += totalTeamKillsRed;
                                }
                            }
                        }
                    }

                    newStats.AddRange(matchStats);
                    stream.Close();
                }
            }

            var newList = new List <PartialPlayerInfo>();

            foreach (var newStat in newStats)
            {
                if (newStat.SoftDelete)
                {
                    continue;
                }

                var existing = newList.FirstOrDefault(x => x.Name.ToLowerInvariant() == newStat.Name.ToLowerInvariant());
                if (existing != null)
                {
                    existing.AddOtherGame(newStat);
                }
                else
                {
                    newList.Add(newStat);
                }
            }
            var playerStats = (await playerStatsTask).ToDictionary(x => x.SummonerId, x => x);

            var updateList = new List <PlayerStatsEntity>();
            var insertList = new List <PlayerStatsEntity>();

            foreach (var playersStat in newList)
            {
                if (registeredPlayers.TryGetValue(playersStat.Name.ToLowerInvariant(), out var registeredPlayer))
                {
                    if (playerStats.TryGetValue(registeredPlayer.Id, out var oldStats))
                    {
                        oldStats.UpdateValues(playersStat);
                        updateList.Add(oldStats);
                    }
                    else
                    {
                        var newStat = new PlayerStatsEntity(playersStat, registeredPlayer.Id, seasonInfo.Id);
                        insertList.Add(newStat);
                    }
                }
            }

            var insertResult = _playerStatsRepository.InsertAsync(insertList);
            var updateResult = _playerStatsRepository.UpdateAsync(updateList);

            return(await insertResult && await updateResult);
        }