Ejemplo n.º 1
0
        /// <summary>
        /// Gets an activity stream asynchronously.
        /// </summary>
        /// <param name="activityId">The Strava activity id.</param>
        /// <param name="typeFlags">Specifies the type of stream.</param>
        /// <param name="resolution">Specifies the resolution of the stream.</param>
        /// <returns>The stream data.</returns>
        public async Task<List<ActivityStream>> GetActivityStreamAsync(String activityId, StreamType typeFlags, StreamResolution resolution = StreamResolution.All)
        {
            StringBuilder types = new StringBuilder();

            foreach (StreamType type in (StreamType[])Enum.GetValues(typeof(StreamType)))
            {
                if (typeFlags.HasFlag(type))
                {
                    types.Append(type.ToString().ToLower());
                    types.Append(",");
                }
            }

            types.Remove(types.ToString().Length - 1, 1);

            String getUrl = String.Format("{0}/{1}/streams/{2}?{3}&access_token={4}",
                Endpoints.Activity,
                activityId,
                types,
                resolution != StreamResolution.All ? "resolution=" + resolution.ToString().ToLower() : "",
                Authentication.AccessToken
                );

            String json = await WebRequest.SendGetAsync(new Uri(getUrl));

            return Unmarshaller<List<ActivityStream>>.Unmarshal(json);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets an activity stream asynchronously.
        /// </summary>
        /// <param name="activityId">The Strava activity id.</param>
        /// <param name="typeFlags">Specifies the type of stream.</param>
        /// <param name="resolution">Specifies the resolution of the stream.</param>
        /// <returns>The stream data.</returns>
        public async Task <List <ActivityStream> > GetActivityStreamAsync(string activityId, StreamType typeFlags, StreamResolution resolution = StreamResolution.All)
        {
            StringBuilder types = new StringBuilder();

            foreach (StreamType type in (StreamType[])Enum.GetValues(typeof(StreamType)))
            {
                if (typeFlags.HasFlag(type))
                {
                    types.Append(type.ToString().ToLower());
                    types.Append(",");
                }
            }

            types.Remove(types.ToString().Length - 1, 1);

            string getUrl = string.Format("{0}/{1}/streams/{2}?{3}&access_token={4}",
                                          Endpoints.Activity,
                                          activityId,
                                          types,
                                          resolution != StreamResolution.All ? "resolution=" + resolution.ToString().ToLower() : "",
                                          Authentication.AccessToken
                                          );

            string json = await WebRequest.SendGetAsync(new Uri(getUrl));

            return(Unmarshaller <List <ActivityStream> > .Unmarshal(json));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets an activity stream.
        /// </summary>
        /// <param name="activityId">The Strava activity id.</param>
        /// <param name="typeFlags">Specifies the type of stream.</param>
        /// <param name="resolution">Specifies the resolution of the stream.</param>
        /// <returns>The stream data.</returns>
        public List <ActivityStream> GetActivityStream(string activityId, StreamType typeFlags, StreamResolution resolution = StreamResolution.All)
        {
            StringBuilder types = new StringBuilder();

            foreach (StreamType type in (StreamType[])Enum.GetValues(typeof(StreamType)))
            {
                if (typeFlags.HasFlag(type))
                {
                    types.Append(type.ToString().ToLower());
                    types.Append(",");
                }
            }

            types.Remove(types.ToString().Length - 1, 1);

            string getUrl = string.Format("{0}/{1}/streams/{2}?{3}&access_token={4}",
                                          Endpoints.Activity,
                                          activityId,
                                          types,
                                          resolution != StreamResolution.All ? "resolution=" + resolution.ToString().ToLower() : "",
                                          AuthSettings.ScopeAccessToken
                                          );

            string json = HttpHelper.GetRequest(getUrl);

            Debug.WriteLine(getUrl);
            return(Unmarshaller <List <ActivityStream> > .Unmarshal(json));
        }
Ejemplo n.º 4
0
        private MinMaxAve GetMinMaxAve(StreamType streamType)
        {
            // if the activity doesn't have the requested stream then no point checkings for values;
            if (!HasIndividualStream(streamType))
            {
                return(new MinMaxAve(streamType));
            }


            // need a better method to do this!  Having to split into two queries depending on the data type of the stream!!!
            if (streamType.HasFlag(StreamType.Distance) ||
                streamType.HasFlag(StreamType.Altitude) ||
                streamType.HasFlag(StreamType.Velocity) ||
                streamType.HasFlag(StreamType.Pace) ||
                streamType.HasFlag(StreamType.Gradient))
            {
                return(GetIndividualStream <double?>(streamType).GroupBy(i => 1)
                       .Select(g => new MinMaxAve(streamType)
                {
                    HasStream = true,
                    Min = Convert.ToDecimal(g.Min(s => s.Value)),
                    Ave = Convert.ToDecimal(g.Average(s => s.Value)),
                    Max = Convert.ToDecimal(g.Max(s => s.Value))
                }).First());
            }
            else if (streamType.HasFlag(StreamType.Heartrate) ||
                     streamType.HasFlag(StreamType.Cadence) ||
                     streamType.HasFlag(StreamType.Watts) ||
                     streamType.HasFlag(StreamType.Temp))
            {
                return(GetIndividualStream <int?>(streamType)
                       .Where(i => streamType == StreamType.Cadence ? i.Value > 0 : true).GroupBy(i => 1)
                       .Select(g => new MinMaxAve(streamType)
                {
                    HasStream = true,
                    Min = g.Min(s => s.Value),
                    Ave = Convert.ToDecimal(g.Average(s => s.Value)),
                    Max = g.Max(s => s.Value)
                }).First());
            }

            // unhandled stream type!
            return(new MinMaxAve(streamType));
        }
Ejemplo n.º 5
0
        public void TestEnumFlags()
        {
            StreamType typeFlags = StreamType.Altitude | StreamType.Cadence | StreamType.Time;

            StringBuilder types = new StringBuilder();

            foreach (StreamType type in (StreamType[])Enum.GetValues(typeof(StreamType)))
            {
                if (typeFlags.HasFlag(type))
                {
                    types.Append(type.ToString().ToLower());
                    types.Append(",");
                }
            }

            types.Remove(types.ToString().Length - 1, 1);

            Assert.AreEqual(types.ToString(), "time,altitude,cadence");
        }
Ejemplo n.º 6
0
        public async Task <List <ActivityStream> > GetActivityStreamAsync(string activityId, StreamType typeFlags, StreamResolution resolution = StreamResolution.All)
        {
            StringBuilder types = new StringBuilder();

            StreamType[] array = (StreamType[])Enum.GetValues(typeof(StreamType));
            for (int i = 0; i < array.Length; i++)
            {
                StreamType type = array[i];
                if (typeFlags.HasFlag(type))
                {
                    types.Append(type.ToString().ToLower());
                    types.Append(",");
                }
            }
            types.Remove(types.ToString().Length - 1, 1);
            string getUrl = string.Format("{0}/{1}/streams/{2}?{3}&access_token={4}", "https://www.strava.com/api/v3/activities", activityId, types, (resolution != StreamResolution.All) ? ("resolution=" + resolution.ToString().ToLower()) : "", Authentication.AccessToken);

            return(Unmarshaller <List <ActivityStream> > .Unmarshal(await WebRequest.SendGetAsync(new Uri(getUrl))));
        }
Ejemplo n.º 7
0
        public List <ActivityStream> GetActivityStream(string activityId, StreamType typeFlags, StreamResolution resolution = StreamResolution.All)
        {
            StringBuilder stringBuilder = new StringBuilder();

            StreamType[] array = (StreamType[])Enum.GetValues(typeof(StreamType));
            for (int i = 0; i < array.Length; i++)
            {
                StreamType streamType = array[i];
                if (typeFlags.HasFlag(streamType))
                {
                    stringBuilder.Append(streamType.ToString().ToLower());
                    stringBuilder.Append(",");
                }
            }
            stringBuilder.Remove(stringBuilder.ToString().Length - 1, 1);
            string text = string.Format("{0}/{1}/streams/{2}?{3}&access_token={4}", "https://www.strava.com/api/v3/activities", activityId, stringBuilder, (resolution != StreamResolution.All) ? ("resolution=" + resolution.ToString().ToLower()) : "", Authentication.AccessToken);
            string json = WebRequest.SendGet(new Uri(text));

            Debug.WriteLine(text);
            return(Unmarshaller <List <ActivityStream> > .Unmarshal(json));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Which streams are valid and available on the activity
        /// </summary>
        /// <returns></returns>
        public List <MinMaxAve> GetStreamSummary()
        {
            List <MinMaxAve> streamInfo = new List <MinMaxAve>();

            StreamType activityTypeStreams = StreamTypeHelper.SportStreams(Activity.ActivityType);

            foreach (StreamType t in Enum.GetValues(typeof(StreamType)))
            {
                if (!activityTypeStreams.HasFlag(t))
                {
                    continue;
                }

                MinMaxAve mma = GetMinMaxAve(t);

                if (mma.HasStream)
                {
                    streamInfo.Add(mma);
                }
            }

            return(streamInfo.OrderBy(s => s.Priority).ToList());
        }