Exemplo n.º 1
0
        public static MatchResult MapFrom(MatchDetailsDto matchDetailsDto, string Key)
        {
            var  participantId   = matchDetailsDto.ParticipantIdentities.First(p => p.Player.AccountId == Key).ParticipantId;
            var  playerMatchInfo = matchDetailsDto.Participants.First(p => p.ParticipantId == participantId);
            bool won             = playerMatchInfo.Stats.Win;
            int  championId      = playerMatchInfo.ChampionId;

            return(new MatchResult
            {
                Win = playerMatchInfo.Stats.Win,
                Position = RiotApiUtils.GetPosition(playerMatchInfo.Timeline.Lane, playerMatchInfo.Timeline.Role),
                TotalGold = playerMatchInfo.Stats.GoldEarned,
                Kills = playerMatchInfo.Stats.Kills,
                Assists = playerMatchInfo.Stats.Assists,
                Deaths = playerMatchInfo.Stats.Deaths,
                ChampionId = playerMatchInfo.ChampionId,
                Timestamp = matchDetailsDto.GameCreation
            });
        }
Exemplo n.º 2
0
        public async Task <MatchlistDto> GetTotalMatches(int seasonId, string queue)
        {
            MatchlistDto matchlist = null;
            ConcurrentBag <MatchResult> results = new ConcurrentBag <MatchResult>();

            if (String.IsNullOrEmpty(RiotApiUtils.AccountId))
            {
                throw new Exception("AccountId cannot be null or empty");
            }

            try
            {
                long seasonTimestamp = Utils.GetSeasonTimestamp(seasonId) * 1000; // to ms

                Url request = RiotApiUtils.Api
                              .AppendPathSegment(matchListEndpoint)
                              .AppendPathSegment(RiotApiUtils.AccountId)
                              .SetQueryParam("beginTime", seasonTimestamp)
                              .SetQueryParam("api_key", RiotApiUtils.ApiKey)
                              .SetQueryParam("queue", RiotApiUtils.GetQueueID(queue));

                bool completed = false;

                if (!request.QueryParams.ContainsKey("beginIndex"))
                {
                    request.SetQueryParam("beginIndex", 0);
                }

                do
                {
                    MatchlistDto current = await request.GetJsonAsync <MatchlistDto>();

                    if (current.Matches.Last().Timestamp <= seasonTimestamp || current.Matches.Count() < 100)
                    {
                        completed = true;
                    }

                    if (matchlist == null)
                    {
                        matchlist = current;
                    }
                    else
                    {
                        matchlist.Matches.AddRange(current.Matches);
                        matchlist.endIndex = current.endIndex;
                    }

                    request.SetQueryParam("beginIndex", (request.QueryParams["beginIndex"] as int?) + 100);
                } while (!completed);

                // Trim extra matches
                int removedMatches = matchlist.Matches.RemoveAll(m => m.Timestamp < seasonTimestamp);
                matchlist.endIndex  -= removedMatches;
                matchlist.totalGames = matchlist.endIndex + 1;

                return(matchlist);
            }
            catch (Exception e)
            {
                throw new Exception(string.Format("GetTotalMatches throwed an Exception: {0}", e.Message));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Throws 429 To Many Requests exception if the rate limit is exceeded.
        /// Consider then specifiying the endIndex to receive less matches results
        /// </summary>
        /// <param name="seasonId"> Season which has the matches you want </param>
        /// <param name="queue"> Ladder from which the matches were played </param>
        /// <returns></returns>
        public async Task <List <MatchResult> > GetMatchesBySeasonAsync(int seasonId, string queue, int beginIndex = 0, int endIndex = 100, bool tooManyRequestsThrowException = true)
        {
            await RiotApiUtils.FetchSummonerData();

            ConcurrentBag <MatchResult> results = new ConcurrentBag <MatchResult>();

            if (String.IsNullOrEmpty(RiotApiUtils.AccountId))
            {
                throw new Exception("AccountId cannot be null or empty");
            }

            try
            {
                long seasonTimestamp = Utils.GetSeasonTimestamp(seasonId) * 1000; // to ms

                Url request = RiotApiUtils.Api
                              .AppendPathSegment(matchListEndpoint)
                              .AppendPathSegment(RiotApiUtils.AccountId)
                              .SetQueryParam("beginTime", seasonTimestamp)
                              .SetQueryParam("api_key", RiotApiUtils.ApiKey)
                              .SetQueryParam("queue", RiotApiUtils.GetQueueID(queue))
                              .SetQueryParam("beginIndex", beginIndex)
                              .SetQueryParam("endIndex", endIndex);

                Console.WriteLine(request.ToString());

                MatchlistDto dto = await request.GetJsonAsync <MatchlistDto>();

                try
                {
                    await dto.Matches.ParallelForEachAsync(async match =>
                    {
                        var detail = await GetMatchResultAsync(match.GameId);
                        results.Add(detail);
                    }, maxDegreeOfParallelism : 10);

                    return(results.ToList());
                }
                catch (FlurlHttpException e)
                {
                    if (e.Call.HttpStatus == ((System.Net.HttpStatusCode) 429))
                    {
                        if (tooManyRequestsThrowException)
                        {
                            throw e;
                        }
                        else
                        {
                            return(results.ToList());
                        }
                    }

                    // Propagate any other type of exception other than 429
                    throw e;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 4
0
        protected async override void OnAppearing()
        {
            base.OnAppearing();
            await RiotApiUtils.FetchSummonerData();

            // Max bar height 500
            int    maxBarHeight     = 500;
            double increaseSizeRate = (double)maxBarHeight / MyViewModel.TotalGamesPlayed;
            var    barChart         = this.FindByName <Grid>("Barchart");

            // Prepare animations

            Label []   counters = { Adc_Bar_Counter, Jungle_Bar_Counter, Mid_Bar_Counter, Support_Bar_Counter, Top_Bar_Counter };
            BoxView [] bars     = { Adc_Bar, Jungle_Bar, Mid_Bar, Support_Bar, Top_Bar };

            await MyViewModel.Init(counters, bars, barChart);

            //var lanes = MyViewModel.MatchList.Matches.GroupBy(m => m.Position).Where(g => g.Key != "UNKNOWN").OrderBy(x => x.Key);
            //var totalLanes = lanes.Count();

            //for (int i = 0; i < totalLanes; ++i)
            //{
            //    var lane = lanes.ElementAt(i).ToList();
            //    var laneSize = lane.Count();

            //    animations.Add(new Animation(
            //         callback: (h) =>
            //         {
            //             bars[i].HeightRequest = Increase(h, increaseSizeRate);
            //         },
            //         start: 0,
            //         end: (laneSize * increaseSizeRate) - increaseSizeRate,
            //         easing: Easing.Linear
            //         )
            //         );

            //    animations.Add(new Animation(
            //        callback: (l) =>
            //        {
            //            counters[i].Text = IncreaseCounter((int)l).ToString();
            //        },
            //        start: 0,
            //        end: laneSize - 1,
            //        easing: Easing.Linear
            //        ));
            //}

            //for (int i = 0; i < animations.Count; ++i)
            //{
            //    var currentAnimation = animations[i];
            //    try
            //    {

            //        if (i % 2 == 0)
            //        {
            //            currentAnimation.Commit(owner: barChart, name: "Grow" + i, rate: 30, length: 1500);
            //        }
            //        else
            //        {
            //            currentAnimation.Commit(owner: barChart, name: "Counter" + i, rate: 6, length: 1500);
            //        }

            //    }
            //    catch(Exception e)
            //    {

            //    }

            //}
        }