public async Task <bool> UpdateRosterTierScoreAsync()
        {
            var rosters = await _rosterService.GetAllRosters();

            foreach (var roster in rosters)
            {
                var teamTierScores = new List <int>();
                foreach (var player in roster.Players)
                {
                    var divisionId    = _tierDivisionMapper.Map(player.TierDivision);
                    var divisionScore = int.Parse((await _lookupRepository.GetLookupEntity(divisionId)).Value);
                    teamTierScores.Add(divisionScore + player.CurrentLp);
                }
                var currentScore = teamTierScores.OrderByDescending(x => x).Take(MinTeamCountRequirement).Sum() / MinTeamCountRequirement;
                var rosterEntity = await _teamRosterRepository.GetByTeamIdAsync(roster.RosterId);

                rosterEntity.TeamTierScore = currentScore;
                try
                {
                    var rosterUpdate = await _teamRosterRepository.UpdateAsync(rosterEntity);

                    if (!rosterUpdate)
                    {
                        throw new Exception($"Error updating team score for: {roster.TeamName}");
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "");
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 2
0
        public async Task <Guid> GetDivisionIdByScheduleAsync(Guid scheduleId)
        {
            var schedule = await _scheduleRepository.GetScheduleAsync(scheduleId);

            var homeTeam = await _teamRosterRepository.GetByTeamIdAsync(schedule.HomeRosterTeamId);

            var division = await _divisionRepository.GetDivisionByTeamScoreAsync(homeTeam.TeamTierScore.GetValueOrDefault(), homeTeam.SeasonInfoId.GetValueOrDefault());

            return(division.Id);
        }
        public async Task <MatchInfo> GetGameInfoForMatch(Guid scheduleId)
        {
            var matchInfo = new MatchInfo();

            var match = await _scheduleRepository.GetScheduleAsync(scheduleId);

            var homeTeam = await _teamRosterRepository.GetByTeamIdAsync(match.HomeRosterTeamId);

            var awayTeam = await _teamRosterRepository.GetByTeamIdAsync(match.AwayRosterTeamId);

            matchInfo.HomeTeam   = homeTeam.TeamName;
            matchInfo.AwayTeam   = awayTeam.TeamName;
            matchInfo.ScheduleId = scheduleId;

            return(matchInfo);

            //Re enable for testing

            //var rolesTask = _lookupRepository.GetLookupEntitiesByCategory("Role");
            //var championsTask = _lookupRepository.GetLookupEntitiesByCategory("Champion");
            //var matchDetailsTask = _matchDetailRepository.ReadForScheduleId(scheduleId);
            //var mvpStatsTask = _matchMvpRepository.ReadAllForTeamScheduleId(scheduleId);
            //var registeredPlayersTask = _summonerInfoRepository.GetAllValidSummonersAsync();

            //var matchDetails = await matchDetailsTask;
            //var championsPlayedTask = _championStatsRepository.GetChampionStatsForMatchDetailAsync(matchDetails.Values.Select(x => x.Id));

            //var groupedMatchDetails = matchDetails.GroupBy(x => x.Key.Game).OrderBy(x => x.Key)
            //                                        .ToDictionary(x => x.Key, x => x.ToList());

            //var mvpStats = (await mvpStatsTask).OrderBy(x => x.Game).ToList();
            //var championsPlayed = (await championsPlayedTask).ToDictionary(x => x.MatchDetailId, x => x);
            //var roles = (await rolesTask).ToDictionary(x => x.Id, x => x);
            //var champions = (await championsTask).ToDictionary(x => x.Id, x => x);
            //var registeredPlayers = (await registeredPlayersTask).ToDictionary(x => x.Id, x => x);

            //SetupGameInfos(homeTeam, awayTeam, groupedMatchDetails, mvpStats, championsPlayed, roles, champions, registeredPlayers);

            //return matchInfo;
        }
Esempio n. 4
0
        public async Task <List <AchievementEntity> > AddSpecialAchievements(Participant player, LookupEntity ourChampion, SummonerInfoEntity summonerInfo, Guid seasonInfoId, Match riotMatch, MatchSubmissionView view, int currentGame)
        {
            var achievements  = new List <AchievementEntity>();
            var teamName      = "N/a";
            var currentTeamId = (await _teamPlayerRepository.GetBySummonerAndSeasonIdAsync(summonerInfo.Id, seasonInfoId))?.TeamRosterId;

            if (currentTeamId != null)
            {
                var playerTeam = await _teamRosterRepository.GetByTeamIdAsync(currentTeamId.Value);

                if (playerTeam.TeamName == view.HomeTeamName || playerTeam.TeamName == view.AwayTeamName)
                {
                    teamName = playerTeam.TeamName;
                }
            }

            if (player.Stats.LargestMultiKill >= 5)
            {
                var achivement = new AchievementEntity
                {
                    Id           = Guid.NewGuid(),
                    UserId       = summonerInfo.UserId,
                    AchievedDate = DateTime.Today,
                    AchievedTeam = teamName,
                    Achievement  = $"Penta-kill on {ourChampion.Value} in game {currentGame}"
                };
                achievements.Add(achivement);
            }

            var blueTeamPlayers = riotMatch.Participants.Where(x => x.TeamId == 100);
            var redTeamPlayers  = riotMatch.Participants.Where(x => x.TeamId == 200);


            var blueTotalKills = blueTeamPlayers.Sum(y => y.Stats.Kills);
            var redTotalKills  = redTeamPlayers.Sum(y => y.Stats.Kills);
            var isBlue         = player.TeamId == 100;

            if (isBlue && redTotalKills == 0 || !isBlue && blueTotalKills == 0)
            {
                var blueTeam = riotMatch.Teams.First(x => x.TeamId == 100);
                var redTeam  = riotMatch.Teams.First(x => x.TeamId == 200);
                if (blueTeam.DragonKills == 0 && blueTeam.BaronKills == 0 && blueTeam.TowerKills == 0 && !isBlue ||
                    redTeam.DragonKills == 0 && redTeam.BaronKills == 0 && redTeam.TowerKills == 0 && isBlue)
                {
                    var achivement = new AchievementEntity
                    {
                        Id           = Guid.NewGuid(),
                        UserId       = summonerInfo.UserId,
                        AchievedDate = DateTime.Today,
                        AchievedTeam = teamName,
                        Achievement  = $"Perfect Game on {ourChampion.Value} in game {currentGame}"
                    };
                    achievements.Add(achivement);
                }
            }

            try
            {
                var oldAchievements = (await _achievementRepository.GetAchievementsForUserAsync(summonerInfo.UserId)).ToList();
                var tempList        = new List <AchievementEntity>(achievements);
                foreach (var newAchievement in tempList)
                {
                    var match = oldAchievements.FirstOrDefault(x => x.Equals(newAchievement));
                    if (match != null)
                    {
                        achievements.Remove(newAchievement);
                    }
                }
            }
            catch (Exception)
            {
                //ignore
            }

            return(achievements);
        }
        /// <summary>
        /// For Roster specific View
        /// </summary>
        /// <param name="rosterId"></param>
        /// <returns></returns>
        public async Task <RosterView> GetRosterAsync(Guid rosterId)
        {
            var seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync();

            var alternateAccountsTask = _alternateAccountRepository.ReadAllAsync();
            var rosterTask            = _teamRosterRepository.GetByTeamIdAsync(rosterId);
            var captainTask           = _teamCaptainRepository.GetCaptainByRosterId(rosterId);
            var playersSummoner       = (await _teamPlayerRepository.ReadAllForRosterAsync(rosterId)).ToList();
            var summonersTask         = _summonerInfoRepository.GetAllForSummonerIdsAsync(playersSummoner.Select(x => x.SummonerId));
            var matchDetails          = await _matchDetailRepository.GetMatchDetailsForPlayerAsync(playersSummoner.Select(x => x.SummonerId));

            var schedule = (await GetTeamSchedule(rosterId)).ToList();

            matchDetails = matchDetails.Where(x => x.Key.SeasonId == seasonInfo.Id).ToDictionary(x => x.Key, x => x.Value);
            var scheduleIds = schedule.Select(x => x.ScheduleId).ToList();

            var statIds = matchDetails.Values.SelectMany(x => x.Where(z => z.SeasonInfoId == seasonInfo.Id && scheduleIds.Contains(z.TeamScheduleId)).Select(y => y.PlayerStatsId));

            var mappedStats = await SetupPlayerStatsViews(statIds, schedule, matchDetails);

            var alternateAccounts = (await alternateAccountsTask).ToList();
            var summoners         = (await summonersTask).ToList();

            var summonerViews = _summonerMapper.MapDetailed(summoners, alternateAccounts, mappedStats).ToList();

            var divisions = (await _divisionRepository.GetAllForSeasonAsync(seasonInfo.Id)).ToList();
            var captain   = await captainTask;
            var roster    = await rosterTask;

            foreach (var teamPlayerEntity in playersSummoner)
            {
                var player = summoners.First(x => x.Id == teamPlayerEntity.SummonerId);

                var isSub        = teamPlayerEntity.IsSub ?? false;
                var summonerView = summonerViews.First(x => x.SummonerName == player.SummonerName);
                summonerView.IsSub = isSub;
            }

            var division = divisions.First(x =>
                                           x.LowerLimit <= roster.TeamTierScore && x.UpperLimit >= roster.TeamTierScore);
            var rosterView = new RosterView
            {
                RosterId      = roster.Id,
                Captain       = summoners.FirstOrDefault(x => x.Id == captain?.SummonerId)?.SummonerName,
                TeamName      = roster.TeamName,
                Wins          = roster.Wins ?? 0,
                Loses         = roster.Loses ?? 0,
                Players       = summonerViews,
                TeamTierScore = roster.TeamTierScore.GetValueOrDefault(),
                Division      = new DivisionView
                {
                    DivisionName     = division.Name,
                    DivisionMinScore = division.LowerLimit,
                    DivisionId       = division.Id
                },
                Schedule = schedule
            };

            var directory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\logos");
            var path      = Directory.GetFiles(directory).FirstOrDefault(x => x.Contains(rosterId.ToString()));

            if (File.Exists(path))
            {
                var byteData = await File.ReadAllBytesAsync(path);

                var base64 = Convert.ToBase64String(byteData);
                var type   = GetContentType(path);
                var imgSrc = string.Format($"data:{type};base64,{base64}");
                rosterView.FileSource = imgSrc;
            }
            rosterView.Cleanup();

            return(rosterView);
        }