Exemplo n.º 1
0
        public List <Champion> getAnswersForDraftByPlayer(Guid playerId, DraftInfos draftInfos)
        {
            Tuple <List <MatchupInfos>, long, MatchupInfos> listMatchupInfos;

            listMatchupInfos = getAllMatchupByParams(playerId, draftInfos);
            var listChampions = new DALCalculation().ComputeAnswerWithDraftInfos(listMatchupInfos, draftInfos, playerId);

            return(listChampions.OrderBy(x => x.ChampionName).ToList());
        }
Exemplo n.º 2
0
        public int SaveAsDuplicateMatchupWithActualPatch(Matchup matchup, List <MatchupRespons> matchupResponses, List <MatchupComment> matchupComments)
        {
            int result       = -1;
            var newMatchupid = Guid.NewGuid();

            using (TransactionScope scope = new TransactionScope())
            {
                //on matchup en changeant l'ID

                matchup.CreationDate = DateTime.Now;
                //on cherche le matchupResponses et on le duplique aussi en changeant l'ID
                var oldMatchupResponsId = matchup.MatchupResponseId;
                var newMatchupResponsId = Guid.NewGuid();
                if (matchupResponses?.Count() > 0)
                {
                    foreach (var item in matchupResponses)
                    {
                        db.MatchupResponses.Add(new MatchupRespons()
                        {
                            ChampionId        = item.ChampionId,
                            CreationDate      = DateTime.Now,
                            MatchupResponseId = newMatchupResponsId
                        });
                    }
                }
                //on duplique les commentaires
                if (matchupComments?.Count() > 0)
                {
                    foreach (var item in matchupComments)
                    {
                        db.MatchupComments.Add(new MatchupComment()
                        {
                            ChampionId       = item.ChampionId,
                            CreationDate     = DateTime.Now,
                            MatchupCommentId = Guid.NewGuid(),
                            CommentText      = item.CommentText,
                            MatchupId        = newMatchupid
                        });
                    }
                }

                var  newMatchup = matchup.DuplicateWithNewIds(matchup, newMatchupid, newMatchupResponsId);
                bool isExist    = new DALCalculation().isPerfectMatchupExist(newMatchup);
                if (!isExist)
                {
                    db.Matchups.Add(newMatchup);
                    result = db.SaveChanges();
                }
                scope.Complete();
            }

            return(result);
        }
Exemplo n.º 3
0
        public Tuple <List <MatchupInfos>, long, MatchupInfos> getAllMatchupByParams(Guid playerId, MatchupInfos matchupInfos)
        {
            List <MatchupInfos> listMatchupInfos = new List <MatchupInfos>();
            var dalCalculation = new DALCalculation();

            var  listMatchup = db.Matchups.Where(x => x.PlayerId == playerId);
            bool hasFilter   = false;

            //ALLY
            if (matchupInfos.AllyTop != Guid.Empty)
            {
                listMatchup = listMatchup.Where(x => x.AllyTop == matchupInfos.AllyTop);
                hasFilter   = true;
            }
            if (matchupInfos.AllyJungle != Guid.Empty)
            {
                listMatchup = listMatchup.Where(x => x.AllyJungle == matchupInfos.AllyJungle);
                hasFilter   = true;
            }
            if (matchupInfos.AllyMid != Guid.Empty)
            {
                listMatchup = listMatchup.Where(x => x.AllyMid == matchupInfos.AllyMid);
                hasFilter   = true;
            }
            if (matchupInfos.AllyAdc != Guid.Empty)
            {
                listMatchup = listMatchup.Where(x => x.AllyAdc == matchupInfos.AllyAdc);
                hasFilter   = true;
            }
            if (matchupInfos.AllySupport != Guid.Empty)
            {
                listMatchup = listMatchup.Where(x => x.AllySupport == matchupInfos.AllySupport);
                hasFilter   = true;
            }
            //ENNEMI
            if (matchupInfos.EnemyTop != Guid.Empty)
            {
                listMatchup = listMatchup.Where(x => x.EnemyTop == matchupInfos.EnemyTop);
                hasFilter   = true;
            }
            if (matchupInfos.EnemyJungle != Guid.Empty)
            {
                listMatchup = listMatchup.Where(x => x.EnemyJungle == matchupInfos.EnemyJungle);
                hasFilter   = true;
            }
            if (matchupInfos.EnemyMid != Guid.Empty)
            {
                listMatchup = listMatchup.Where(x => x.EnemyMid == matchupInfos.EnemyMid);
                hasFilter   = true;
            }
            if (matchupInfos.EnemyAdc != Guid.Empty)
            {
                listMatchup = listMatchup.Where(x => x.EnemyAdc == matchupInfos.EnemyAdc);
                hasFilter   = true;
            }
            if (matchupInfos.EnemySupport != Guid.Empty)
            {
                listMatchup = listMatchup.Where(x => x.EnemySupport == matchupInfos.EnemySupport);
                hasFilter   = true;
            }

            bool isPerfectMatch = dalCalculation.isPerfectMatchupExistWithMatchupInfo(matchupInfos, playerId);

            long time;
            var  automaticMatchup = new MatchupInfos();

            if (true)
            {
                var       listMatchupComment = db.MatchupComments.Where(x => x.PlayerId == playerId).ToList();
                Stopwatch t0 = new Stopwatch();
                t0.Start();
                var listMatchups = listMatchup.OrderByDescending(x => x.CreationDate).ThenBy(x => x.PatchVersion).Take(200).ToList();
                time             = t0.ElapsedMilliseconds;
                listMatchupInfos = ConvertMatchupsToMatchupInfos(listMatchups, listMatchupComment);
                if (!isPerfectMatch)
                {
                    matchupInfos.PlayerId = playerId;
                    automaticMatchup      = dalCalculation.GetEstimatedAnswersByMatchupParam(matchupInfos);
                }
                var t2 = t0.ElapsedMilliseconds;
            }

            return(new Tuple <List <MatchupInfos>, long, MatchupInfos>(listMatchupInfos, time, automaticMatchup));
        }