Пример #1
0
        /// <summary>
        /// Gets the summary of a certain date range.
        /// </summary>
        /// <param name="start">The start date.</param>
        /// <param name="end">The end date.</param>
        /// <returns>A summary of the date range.</returns>
        public async Task<Summary> GetSummaryAsync(DateTime start, DateTime end)
        {
            Summary summary = new Summary
            {
                Start = start,
                End = end
            };

            int page = 1;
            bool hasEntries = true;
            float rideDistance = 0F;
            float runDistance = 0F;

            while (hasEntries)
            {
                List<ActivitySummary> request = await GetActivitiesAsync(start, end, page++, 200);

                if (request.Count == 0)
                {
                    hasEntries = false;
                }

                foreach (Activity activity in request)
                {
                    if (activity.Type == ActivityType.Ride)
                    {
                        summary.AddRide(activity);
                        rideDistance += activity.Distance;
                    }
                    else if (activity.Type == ActivityType.Run)
                    {
                        summary.AddRun(activity);
                        runDistance += activity.Distance;
                    }
                    else
                    {
                        summary.AddActivity(activity);
                    }

                    summary.AddTime(TimeSpan.FromSeconds(activity.MovingTime));

                    if (ActivityReceived != null)
                    {
                        ActivityReceived(null, new ActivityReceivedEventArgs(activity));
                    }
                }
            }

            summary.RideDistance = rideDistance;
            summary.RunDistance = runDistance;

            return summary;
        }
Пример #2
0
        /// <summary>
        /// Gets the currently authenticated athletes progress for the current week.
        /// </summary>
        /// <returns>The weekly progress.</returns>
        public async Task<Summary> GetWeeklyProgressAsync()
        {
            Summary progress = new Summary();
            DateTime now = DateTime.Now;
            int days = 0;

            // What day is it today?
            switch (now.DayOfWeek)
            {
                case DayOfWeek.Monday:
                    days = 1;
                    break;
                case DayOfWeek.Tuesday:
                    days = 2;
                    break;
                case DayOfWeek.Wednesday:
                    days = 3;
                    break;
                case DayOfWeek.Thursday:
                    days = 4;
                    break;
                case DayOfWeek.Friday:
                    days = 5;
                    break;
                case DayOfWeek.Saturday:
                    days = 6;
                    break;
                case DayOfWeek.Sunday:
                    days = 7;
                    break;
            }

            // Calculate the date
            DateTime date = DateTime.Now - new TimeSpan(days, 0, 0, 0);
            progress.Start = date;
            progress.End = now;

            List<ActivitySummary> activities = await GetActivitiesAfterAsync(date);

            float rideDistance = 0F;
            float runDistance = 0f;
            
            foreach (ActivitySummary activity in activities)
            {
                if (activity.Type == ActivityType.Ride)
                {
                    progress.AddRide(activity);
                    rideDistance += activity.Distance;
                }
                else if (activity.Type == ActivityType.Run)
                {
                    progress.AddRun(activity);
                    runDistance += activity.Distance;
                }
                else
                {
                    progress.AddActivity(activity);
                }

                progress.AddTime(TimeSpan.FromSeconds(activity.MovingTime));
            }

            progress.RideDistance = rideDistance;
            progress.RunDistance = runDistance;

            return progress;
        }