/// <summary> /// Convert Strava stream information and write to database. /// </summary> /// <param name="stream">Detailed information for activity in strava format</param> private void ConvertStream(List <StravaDotNetStreams.ActivityStream> stream) { _convertedStream = ActivityStreams.CreateForNewActivity(this._activityId); // convert each strava item for (int row = 0; row <= stream[0].OriginalSize - 1; row++) { Stream s = ExtractStreamRow(stream, row); // occasinally we get duplicate rows for the same time back from Strava so need to ignore them! if (_convertedStream.Stream.Where(c => c.Time == s.Time).Any()) { System.Diagnostics.Debug.WriteLine(string.Format("Skipping row {0} for activity {1}", s.Time, _activityId)); continue; } _convertedStream.Stream.Add(s); } _convertedStream.FixGaps(); _convertedStream.StoreStreams(); _convertedStream.CalculatePeaksAndSave(); // we can only calculate a power curve for activities which have a power meter! if (_stravaActivity.HasPowerMeter) { _convertedStream.AddPowerCurveCalculationJobs(); } }
public void ActivityStreams_TestAllTimeRecordsExistWithGap() { long activityId = 1234L; ActivityStreams stream = ActivityStreams.CreateForNewActivity(activityId); // check activityId correctly assigned. Assert.AreEqual(stream.ActivityId, activityId); int itemsAdded = 0; // add a block of 100. for (int x = 0; x < 100; x++) { stream.Stream.Add(new Stream() { Time = x }); itemsAdded++; } // and another block but leaving a gap of missing time records. for (int x = 105; x < 200; x++) { stream.Stream.Add(new Stream() { Time = x }); itemsAdded++; } Assert.AreEqual(stream.Stream.Count(), itemsAdded); // check we are picking up that there is a gap in the stream. Assert.AreEqual(true, stream.GapsInStream()); // fix the gap. stream.FixGaps(); // and check it's now reporting no gaps. Assert.AreEqual(false, stream.GapsInStream()); // pull out one of the added stream items and check it exists and time/activityId are correct. Stream added = stream.Stream.Where(s => s.Time == 101).FirstOrDefault(); Assert.IsNotNull(added); Assert.AreEqual(101, added.Time); Assert.AreEqual(activityId, added.ActivityId); }
public void ActivityStreams_TestAllTimeRecordsExistNoGap() { long activityId = 1234L; ActivityStreams s = ActivityStreams.CreateForNewActivity(activityId); // check activityId correctly assigned. Assert.AreEqual(s.ActivityId, activityId); int itemsAdded = 0; for (int x = 0; x < 100; x++) { s.Stream.Add(new Stream() { Time = x }); itemsAdded++; } Assert.AreEqual(s.Stream.Count(), itemsAdded); Assert.AreEqual(false, s.GapsInStream()); }