Пример #1
0
        /// <summary>
        /// Gets the leaderboard of a segment. You can use various filters to filter the data.
        /// Some of the filters require a Strava Premium account!
        /// </summary>
        /// <param name="segmentId">The Strava segment Id.</param>
        /// <param name="weight">The weight class used to filter the leaderboard.</param>
        /// <param name="age">The age group used to filter the leaderboard.</param>
        /// <param name="time">The time used to filter the leaderboard.</param> 
        /// <param name="gender">The gender used to filter the leaderboard.</param>
        /// <returns>The leaderboard filtered by gender.</returns>
        public async Task<Leaderboard> GetSegmentLeaderboardAsync(String segmentId, WeightFilter weight, AgeFilter age, TimeFilter time, GenderFilter gender)
        {
            int page = 1;

            //Create one dummy request to get the number of entries.
            Leaderboard request = await GetSegmentLeaderboardAsync(segmentId, weight, age, time, gender, 1, 1);
            int totalAthletes = request.EntryCount;

            Leaderboard leaderboard = new Leaderboard
            {
                EffortCount = request.EffortCount,
                EntryCount = request.EntryCount
            };

            while ((page - 1) * 200 < totalAthletes)
            {
                Leaderboard l = await GetSegmentLeaderboardAsync(segmentId, weight, age, time, gender, page++, 200);

                foreach (LeaderboardEntry entry in l.Entries)
                {
                    leaderboard.Entries.Add(entry);
                }
            }

            return leaderboard;
        }
Пример #2
0
        /// <summary>
        /// Gets the full and unfiltered leaderboard of a Strava segment.
        /// </summary>
        /// <param name="segmentId">The Strava segment Id.</param>
        /// <returns>The full and unfiltered leaderboard.</returns>
        public Leaderboard GetFullSegmentLeaderboard(String segmentId)
        {
            int page = 1;

            //Create one dummy request to get the number of entries.
            Leaderboard request = GetSegmentLeaderboard(segmentId, 1, 1);
            int totalAthletes = request.EntryCount;

            Leaderboard leaderboard = new Leaderboard
            {
                EffortCount = request.EffortCount,
                EntryCount = request.EntryCount
            };

            while ((page - 1) * 200 < totalAthletes)
            {
                Leaderboard l = GetSegmentLeaderboard(segmentId, page++, 200);

                foreach (LeaderboardEntry entry in l.Entries)
                {
                    leaderboard.Entries.Add(entry);
                }
            }

            return leaderboard;
        }