public void TestActivityReturnsItem() { var actService = new StravaActivity(); var result = actService.GeActivity(1, _accessToken); Assert.True(result.Count() > 0); }
public void FindFastestActivity_FastestActivityReturned() { var now_UTC = DateTime.UtcNow; var sampleActivities = new List <object> { new StravaActivity { id = "1", start_date = now_UTC, elapsed_time = 500, average_speed = 3 }, new StravaActivity { id = "2", start_date = now_UTC.AddDays(1), elapsed_time = 700, average_speed = 4.5 }, new StravaActivity { id = "3", start_date = now_UTC.AddDays(-7), elapsed_time = 100, average_speed = 5 }, }; var result = ActivityComparer.FindFastestActivity(sampleActivities); StravaActivity stravaResult = (StravaActivity)result; stravaResult.id.Should().Be("3"); stravaResult.average_speed.Should().Be(5); }
public void GetFastestStravaActivity_FastestActivityReturned() { var sut = MakeSut(); var fastestActivity = sut.PostFastestStravaActivity(StravaActivityHistory).Value; StravaActivity fastestAct = (StravaActivity)fastestActivity; fastestAct.name.Should().Be("Activity 1"); }
private void GetLastActivityIntent() { var actService = new StravaActivity(); var activityDetails = actService.GeActivity(1, GetStravaAccessToken(_alexaUser)); if (activityDetails.Count() > 0) { } }
/// <summary> /// Maps valid songs to an activity /// </summary> /// <param name="activity">Activity to map songs to.</param> /// <param name="spotifyPlayHistory">List of PlayHistoryItems that are used to map to activities</param> /// <param name="lastFMPlayHistory">List of LastTracks that are used to map to activities</param> /// <returns>A 1 item dictionary of an activity to songs that played within the correct time range.</returns> public static Dictionary <StravaActivity, List <object> > MapSongsToActivity(StravaActivity activity, List <PlayHistoryItem> spotifyPlayHistory, List <LastTrack> lastFMPlayHistory) { var startTimeUTC = activity.start_date; var endTimeUTC = startTimeUTC.AddSeconds(activity.elapsed_time); List <object> validPlayHistory = new List <object>(); foreach (var item in spotifyPlayHistory) { if (item.PlayedAt >= startTimeUTC && item.PlayedAt < endTimeUTC) { validPlayHistory.Add(item); continue; } DateTime itemStartTime = item.PlayedAt.AddMilliseconds(-item.Track.DurationMs); if (itemStartTime >= startTimeUTC && itemStartTime < endTimeUTC) { validPlayHistory.Add(item); continue; } } foreach (var item in lastFMPlayHistory) { if (item.TimePlayed >= startTimeUTC && item.TimePlayed < endTimeUTC) { validPlayHistory.Add(item); continue; } DateTime itemStartTime = item.TimePlayed.Value.DateTime.Subtract((TimeSpan)item.Duration); if (itemStartTime >= startTimeUTC && itemStartTime < endTimeUTC) { validPlayHistory.Add(item); continue; } } return(new Dictionary <StravaActivity, List <object> > { { activity, validPlayHistory } }); }
public JsonResult PostFastestStravaActivity([FromBody] List <StravaActivity> stravaActivityList) { if (stravaActivityList == null || stravaActivityList.Count == 0) { return(new JsonResult(null)); } StravaActivity kingOfTheHill = stravaActivityList[0]; foreach (StravaActivity activity in stravaActivityList) { if (activity.average_speed > kingOfTheHill.average_speed) { kingOfTheHill = activity; } } return(new JsonResult(kingOfTheHill)); }
public void MapWithStravaActivityAndSpotifySongs_CorrectResultsReturned() { var startTime = DateTime.UtcNow; var endTime = startTime.AddMinutes(20); sut = new SongsToActivityMapper(); var fakeStravaActivity = new StravaActivity { achievement_count = 2, athlete = new StravaAthlete { id = 1, resource_state = 2 }, athlete_count = 1, average_cadence = 86.1, average_heartrate = 191, average_speed = 16.5, average_temp = 10, comment_count = 0, commute = false, display_hide_heartrate_option = false, distance = 30.1, elapsed_time = 1200, elev_high = 80, elev_low = 30, end_latlng = new List <double>(), external_id = "1234253547687", flagged = false, from_accepted_tag = false, gear_id = "1", has_heartrate = true, has_kudoed = false, heartrate_opt_out = false, id = "1234253547687", kudos_count = 5, location_city = "Oxford", location_country = "UK", location_state = "OXF", manual = false, map = new StravaMap { id = "Map 1", resource_state = 2, summary_polyline = "Some data" }, max_heartrate = 200, max_speed = 18, moving_time = 1234, name = "Activity 1", photo_count = 0, Private = false, pr_count = 3, resource_state = 1, start_date = startTime, start_date_local = DateTime.Now, start_latitude = 50.121231, start_latlng = new List <double>(), start_longitude = -1.2342535, timezone = "(GMT+01:00) Europe/London", total_elevation_gain = 30, total_photo_count = 0, trainer = false, type = "1", upload_id = "1234253547687", upload_id_str = "123456789", utc_offset = 0, visibility = "private", workout_type = 1, }; var fakeListeningHistory = new List <PlayHistoryItem> { new PlayHistoryItem { Context = new Context(), PlayedAt = startTime.AddSeconds(1), Track = new SimpleTrack { Name = "Song 1", Id = "1", DurationMs = 180000 } }, new PlayHistoryItem { Context = new Context(), PlayedAt = startTime.AddMinutes(1), Track = new SimpleTrack { Name = "Song 2", Id = "2", DurationMs = 90000 } }, new PlayHistoryItem { Context = new Context(), PlayedAt = startTime.AddMinutes(-20), Track = new SimpleTrack { Name = "Song 3", Id = "3", DurationMs = 500 } }, new PlayHistoryItem { Context = new Context(), PlayedAt = startTime.AddMinutes(5), Track = new SimpleTrack { Name = "Song 4", Id = "4", DurationMs = 1500 } } }; var mappedSongsToActivity = SongsToActivityMapper.MapSongsToActivity(fakeStravaActivity, fakeListeningHistory, new List <LastTrack>()); mappedSongsToActivity.Count.Should().Be(1); mappedSongsToActivity[fakeStravaActivity].Count.Should().Be(3); List <object> mappedSongs = mappedSongsToActivity[fakeStravaActivity]; var track1 = (PlayHistoryItem)mappedSongs[0]; var track2 = (PlayHistoryItem)mappedSongs[1]; var track3 = (PlayHistoryItem)mappedSongs[2]; track1.Track.Id.Should().Be("1"); track2.Track.Id.Should().Be("2"); track3.Track.Id.Should().Be("4"); }
public void GetFastestActivitySongs_FastestActivitySongsReturned() { var now = DateTime.UtcNow; var activity1 = new StravaActivity { type = "Run", average_speed = 3.5, start_date = now.AddHours(-2), elapsed_time = 3600 }; var listOfActivity1PlayHistory = new List <object> { new PlayHistoryItem { PlayedAt = now.AddHours(-2), Track = new SimpleTrack { Name = "Song 1", DurationMs = 3600 } }, new PlayHistoryItem { PlayedAt = now.AddHours(-2).AddMinutes(5), Track = new SimpleTrack { Name = "Song 2", DurationMs = 3600 } }, new PlayHistoryItem { PlayedAt = now.AddHours(-2).AddMinutes(10), Track = new SimpleTrack { Name = "Song 3", DurationMs = 3600 } } }; var activity2 = new StravaActivity { type = "Run", average_speed = 4.5, start_date = now.AddHours(-1), elapsed_time = 3600 }; var listOfActivity2PlayHistory = new List <object> { new PlayHistoryItem { PlayedAt = now.AddHours(-1).AddMinutes(5), Track = new SimpleTrack { Name = "Faster Song 1", DurationMs = 600 } }, new PlayHistoryItem { PlayedAt = now.AddHours(-1).AddMinutes(10), Track = new SimpleTrack { Name = "Faster Song 2", DurationMs = 900 } }, new PlayHistoryItem { PlayedAt = now.AddHours(-1).AddMinutes(15), Track = new SimpleTrack { Name = "Faster Song 3", DurationMs = 1200 } }, new PlayHistoryItem { PlayedAt = now.AddHours(-1).AddMinutes(20), Track = new SimpleTrack { Name = "Faster Song 4", DurationMs = 600 } }, }; var sampleData = new Dictionary <object, List <object> > { { activity1, listOfActivity1PlayHistory }, { activity2, listOfActivity2PlayHistory } }; sut = new InsightsManager(); var result = sut.GetFastestActivityWithListeningHistory(sampleData); result.Keys.Should().Contain(activity2); result.Keys.Should().HaveCount(1); result.Values.ToList()[0].Should().BeEquivalentTo(listOfActivity2PlayHistory); }
public void GetFastestActivitySongsWithMultipleTypesOfActivity_FastestActivitySongsReturned() { var now = DateTime.UtcNow; var activity1 = new StravaActivity { type = "Run", average_speed = 3.5, start_date = now.AddHours(-2), elapsed_time = 3600 }; var listOfActivity1PlayHistory = new List <object> { new PlayHistoryItem { PlayedAt = now.AddHours(-2), Track = new SimpleTrack { Name = "Song 1", DurationMs = 3600 } }, new PlayHistoryItem { PlayedAt = now.AddHours(-2).AddMinutes(5), Track = new SimpleTrack { Name = "Song 2", DurationMs = 3600 } }, new PlayHistoryItem { PlayedAt = now.AddHours(-2).AddMinutes(10), Track = new SimpleTrack { Name = "Song 3", DurationMs = 3600 } } }; var activity2 = new Fitbit.Api.Portable.Models.Activities { ActivityTypeId = 1, Duration = 3600, Speed = 4.5, StartTime = now.AddHours(-2) }; var listOfActivity2PlayHistory = new List <object> { new LastTrack { TimePlayed = now.AddHours(-2), Name = "Last FM song 1", Duration = new TimeSpan(0, 3, 0) }, new LastTrack { TimePlayed = now.AddHours(-2).AddMinutes(3), Name = "Last FM song 2", Duration = new TimeSpan(0, 3, 0) }, }; var sampleData = new Dictionary <object, List <object> > { { activity1, listOfActivity1PlayHistory }, { activity2, listOfActivity2PlayHistory } }; sut = new InsightsManager(); var result = sut.GetFastestActivityWithListeningHistory(sampleData); result.Keys.Should().Contain(activity2); result.Keys.Should().HaveCount(1); result.Values.ToList()[0].Should().BeEquivalentTo(listOfActivity2PlayHistory); }