Exemple #1
0
        public List <PerformancesViewModel> BuildPerformanceViewModel(List <Match> matches, Player player)
        {
            List <PerformancesViewModel> lpvm = new List <PerformancesViewModel>();
            SoloQServices       sq            = new SoloQServices();
            PerformanceServices ps            = new PerformanceServices();

            List <Match> games         = ps.GetListMatchByRole(matches, player).OrderByDescending(x => x.gameId).ToList();
            List <int>   listChampions = games.Select(x => x.championId).Distinct().ToList();

            foreach (var championId in listChampions)
            {
                List <Match>      listMatch      = games.Where(x => x.championId == championId).ToList();
                List <MatchInfos> listMatchInfos = sq.GetListMatchInfos(listMatch);

                var lMatchupHistory = ps.GetListOpponentChampionIdWtihListMatch(listMatchInfos, player);
                foreach (var matchupHistory in lMatchupHistory)
                {
                    PerformancesViewModel pvm = new PerformancesViewModel();
                    pvm.championId         = championId;
                    pvm.timelines          = new List <TimelineViewModel>();
                    pvm.opponentChampionId = matchupHistory.opponentChampionId;
                    foreach (var matchInfos in matchupHistory.listMatch)
                    {
                        var timeline = BuildTimelineViewModel(matchInfos, player);

                        if (ps.DidPlayerWin(matchInfos, player))
                        {
                            pvm.nbVictory++;
                            timeline.win = true;
                        }
                        else
                        {
                            pvm.nbDefeat++;
                            timeline.win = false;
                        }

                        pvm.timelines.Add(timeline);
                    }
                    lpvm.Add(pvm);
                }
            }
            return(lpvm);
        }
Exemple #2
0
        public WinratesViewModel BuildWinratesViewModel(int nbGames, Player player)
        {
            SoloQServices     sq  = new SoloQServices();
            WinratesViewModel wrm = null;
            var ps      = new PerformanceServices();
            var matches = sq.GetSoloQHistories(player.AccountId, nbGames).OrderByDescending(x => x.timestamp).ToList();

            if (matches != null)
            {
                if (player.Role != 0)
                {
                    matches = ps.GetListMatchByRole(matches, player);
                }
                wrm            = new WinratesViewModel();
                wrm.nickname   = player.Nickname;
                wrm.blueSide   = new WinratesViewModel.Side();
                wrm.redSide    = new WinratesViewModel.Side();
                wrm.totalGames = nbGames;
                wrm.role       = GlobalVar.getRoleById(player.Role);

                foreach (var match in matches)
                {
                    var matchInfos = sq.GetMatchInfo(match.gameId.ToString());
                    //savoir dans quel side il était et si il a win
                    var  team          = ps.GetPlayerTeam(matchInfos, player);
                    var  isWin         = matchInfos.teams.Where(x => x.teamId == team).FirstOrDefault()?.win;
                    bool isBlueSideWin = false;
                    if (team == 100)
                    {
                        if (isWin.ToLower() == "win")
                        {
                            wrm.blueSide.totalGames++;
                            wrm.blueSide.nbWin++;
                            wrm.totalGamesOnlyMainRole++;
                            isBlueSideWin = true;
                        }
                        else if (isWin.ToLower() == "fail")
                        {
                            wrm.blueSide.totalGames++;
                            wrm.blueSide.nbLoss++;
                            wrm.totalGamesOnlyMainRole++;
                        }
                    }
                    else if (team == 200)
                    {
                        if (isWin.ToLower() == "win")
                        {
                            wrm.redSide.totalGames++;
                            wrm.redSide.nbWin++;
                            wrm.totalGamesOnlyMainRole++;
                        }
                        else if (isWin.ToLower() == "fail")
                        {
                            wrm.redSide.totalGames++;
                            wrm.redSide.nbLoss++;
                            wrm.totalGamesOnlyMainRole++;
                            isBlueSideWin = true;
                        }
                    }
                    int participantId = ps.GetParticipantId(matchInfos, player);
                    if (participantId != 0)
                    {
                        CalculateDraftPosition(wrm, matchInfos, participantId, isBlueSideWin);
                    }
                }
            }

            return(wrm);
        }