/// <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); }
public Summary GetSummary(DateTime start, DateTime end) { Summary summary = new Summary { Start = start, End = end }; int num = 1; bool flag = true; float num2 = 0f; float num3 = 0f; while (flag) { List <ActivitySummary> activities = GetActivities(start, end, num++, 200); if (activities.Count == 0) { flag = false; } foreach (ActivitySummary item in activities) { if (item.Type == ActivityType.Ride) { summary.AddRide(item); num2 += item.Distance; } else if (item.Type == ActivityType.Run) { summary.AddRun(item); num3 += item.Distance; } else { summary.AddActivity(item); } summary.AddTime(TimeSpan.FromSeconds((double)item.MovingTime)); if (this.ActivityReceived != null) { this.ActivityReceived(null, new ActivityReceivedEventArgs(item)); } } } summary.RideDistance = num2; summary.RunDistance = num3; return(summary); }
public Summary GetWeeklyProgress() { Summary summary = new Summary(); DateTime now = DateTime.Now; int days = 0; 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; } DateTime after = summary.Start = DateTime.Now - new TimeSpan(days, 0, 0, 0); summary.End = now; List <ActivitySummary> activitiesAfter = GetActivitiesAfter(after); float num = 0f; float num2 = 0f; foreach (ActivitySummary item in activitiesAfter) { if (item.Type == ActivityType.Ride) { summary.AddRide(item); num += item.Distance; } else if (item.Type == ActivityType.Run) { summary.AddRun(item); num2 += item.Distance; } else { summary.AddActivity(item); } summary.AddTime(TimeSpan.FromSeconds((double)item.MovingTime)); if (this.ActivityReceived != null) { this.ActivityReceived(null, new ActivityReceivedEventArgs(item)); } } summary.RideDistance = num; summary.RunDistance = num2; return(summary); }
public async Task <Summary> GetWeeklyProgressAsync() { Summary progress = new Summary(); DateTime now = DateTime.Now; int days = 0; 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; } DateTime date = progress.Start = DateTime.Now - new TimeSpan(days, 0, 0, 0); progress.End = now; List <ActivitySummary> activities = await GetActivitiesAfterAsync(date); float rideDistance = 0f; float runDistance = 0f; foreach (ActivitySummary item in activities) { if (item.Type == ActivityType.Ride) { progress.AddRide(item); rideDistance += item.Distance; } else if (item.Type == ActivityType.Run) { progress.AddRun(item); runDistance += item.Distance; } else { progress.AddActivity(item); } progress.AddTime(TimeSpan.FromSeconds((double)item.MovingTime)); } progress.RideDistance = rideDistance; progress.RunDistance = runDistance; return(progress); }
/// <summary> /// Gets the currently authenticated athletes progress for the current week. /// </summary> /// <returns>The weekly progress.</returns> public Summary GetWeeklyProgress() { 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 = GetActivitiesAfter(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)); if (ActivityReceived != null) { ActivityReceived(null, new ActivityReceivedEventArgs(activity)); } } progress.RideDistance = rideDistance; progress.RunDistance = runDistance; return(progress); }