示例#1
0
        public void TestEmptyActivityTcx()
        {
            var expectedActivityTime = new DateTime(1, 2, 3, 4, 5, 6, DateTimeKind.Utc);
            var writer = new TcxWriter(textWriter);
            writer.StartActivity(expectedActivityTime, TcxSport.Other);
            writer.EndActivity();
            writer.Dispose();

            var root = XElement.Parse(result.ToString());
            var activities = GetActivities(root);
            var activity = activities.Single();
            Assert.AreEqual(activity.Sport, "Other");
            Assert.AreEqual("0001-02-03T04:05:06Z", activity.Id);
            Assert.AreEqual(0, activity.Laps.Count());
        }
示例#2
0
        public void WriteTcxFile(IEnumerable<SourcedStream> laps, TextWriter textWriter)
        {
            using (var writer = new TcxWriter(textWriter))
            {
                writer.StartTcx();
                bool firstFile = true;
                var stats = new LapStats { Calories = 0, DistanceMeters = 0, TotalTimeSeconds = 0,AltitudeMeters = 0,AvgHeartRate = 0,MaxHeartRate = 0,MaxSpeed = 0};
                foreach (var lap in laps)
                {
                    var data = TcxDataFactory.CreateDefault().Create(lap);
                    if (firstFile)
                    {
                        writer.StartActivity(data.StartTime, data.Sport);
                        firstFile = false;
                    }

                    writer.StartLap(data.StartTime);

                    foreach (var point in data.TrackPoints)
                    {
                        if (point.IsLap)
                        {
                            double totalsec = writer.EndLap().TotalTimeSeconds;
                            stats = new LapStats { Calories = 0, DistanceMeters = 0, TotalTimeSeconds = totalsec, AltitudeMeters = 0, AvgHeartRate = 0, MaxHeartRate = 0, MaxSpeed = 0 };
                            writer.StartLap(data.StartTime.AddSeconds(stats.TotalTimeSeconds));
                        }
                        writer.StartTrackPoint();
                        writer.WriteTrackPointTime(point.Time);
                        writer.WriteTrackPointCadence(point.CadenceRpm);
                        writer.WriteTrackPointElapsedCalories(point.CaloriesElapsed + stats.Calories);
                        writer.WriteTrackPointElapsedDistanceMeters(point.DistanceMetersElapsed); // + stats.DistanceMeters);
                        writer.WriteTrackPointHeartRateBpm(point.HeartRateBpm);
                        writer.WriteTrackPointPowerWatts(point.PowerWatts);
                        writer.WriteTrackPointSpeedMetersPerSecond(point.SpeedMetersPerSecond);
                        writer.WriteTrackPointElapsedAltitude(point.AltitudeMetersElapsed + stats.AltitudeMeters);

                        writer.EndTrackPoint();
                    }

                    stats = writer.EndLap();
                }
                writer.EndActivity();
                writer.EndTcx();
            }
        }
示例#3
0
        public void WriteTcxFile(IEnumerable <SourcedStream> laps, TextWriter textWriter)
        {
            using (TcxWriter writer = new TcxWriter(textWriter))
            {
                writer.StartTcx();
                bool     firstFile = true;
                LapStats stats     = new LapStats()
                {
                    Calories = 0, DistanceMeters = 0, TotalTimeSeconds = 0
                };
                foreach (var lap in laps)
                {
                    var data = TcxDataFactory.CreateDefault().Create(lap);
                    if (firstFile)
                    {
                        writer.StartActivity(data.StartTime, data.Sport);
                        firstFile = false;
                    }

                    writer.StartLap(data.StartTime);

                    foreach (var point in data.TrackPoints)
                    {
                        writer.StartTrackPoint();
                        writer.WriteTrackPointTime(point.Time);
                        writer.WriteTrackPointCadence(point.CadenceRpm);
                        writer.WriteTrackPointElapsedCalories(point.CaloriesElapsed + stats.Calories);
                        writer.WriteTrackPointElapsedDistanceMeters(point.DistanceMetersElapsed + stats.DistanceMeters);
                        writer.WriteTrackPointHeartRateBpm(point.HeartRateBpm);
                        writer.WriteTrackPointPowerWatts(point.PowerWatts);
                        writer.WriteTrackPointSpeedMetersPerSecond(point.SpeedMetersPerSecond);
                        writer.EndTrackPoint();
                    }

                    stats = writer.EndLap();
                }
                writer.EndActivity();
                writer.EndTcx();
            }
        }
示例#4
0
        public void TestSingleLapSingleNoTrackTcx()
        {
            var expectedActivityTime = new DateTime(6, 5, 4, 3, 2, 1, DateTimeKind.Utc);
            var writer = new TcxWriter(textWriter);
            writer.StartActivity(expectedActivityTime, TcxSport.Biking);
            writer.StartLap(expectedActivityTime);
            writer.EndLap();
            writer.EndActivity();
            writer.Dispose();

            var root = XElement.Parse(result.ToString());
            var activities = GetActivities(root);
            var activity = activities.Single();
            Assert.AreEqual(activity.Sport, "Biking");
            Assert.AreEqual("0006-05-04T03:02:01Z", activity.Id);

            var lap = activity.Laps.Single();
            Assert.AreEqual("0", lap.TotalTimeSeconds);
            Assert.AreEqual("0", lap.DistanceMeters);
            Assert.AreEqual("0", lap.Calories);
            Assert.AreEqual("Active", lap.Intensity);
            Assert.AreEqual("Manual", lap.TriggerMethod);
        }
示例#5
0
        public void TestTwoLapsWithTwoTrackPointsEachTcx()
        {
            var writer = new TcxWriter(textWriter);
            Action writeTrackPoints = () =>
            {
                writer.StartTrackPoint();
                writer.WriteTrackPointCadence(1);
                writer.WriteTrackPointElapsedCalories(2);
                writer.WriteTrackPointElapsedDistanceMeters(3.3);
                writer.WriteTrackPointHeartRateBpm(4);
                writer.WriteTrackPointPowerWatts(5);
                writer.WriteTrackPointSpeedMetersPerSecond(6.6);
                writer.WriteTrackPointTime(point1Time);
                writer.EndTrackPoint();

                writer.StartTrackPoint();
                writer.WriteTrackPointCadence(13);
                writer.WriteTrackPointElapsedCalories(14);
                writer.WriteTrackPointElapsedDistanceMeters(15.15);
                writer.WriteTrackPointHeartRateBpm(16);
                writer.WriteTrackPointPowerWatts(17);
                writer.WriteTrackPointSpeedMetersPerSecond(18.18);
                writer.WriteTrackPointTime(point2Time);
                writer.EndTrackPoint();
            };

            var expectedActivityTime = new DateTime(6, 5, 4, 3, 2, 1, DateTimeKind.Utc);
            writer.StartActivity(expectedActivityTime, TcxSport.Biking);

            var expectedLap1Time = new DateTime(1, 2, 3, 4, 5, 6, DateTimeKind.Utc);
            writer.StartLap(expectedLap1Time);
            writeTrackPoints();
            writer.EndLap();

            var expectedLap2Time = new DateTime(1, 2, 3, 6, 5, 4, DateTimeKind.Utc);
            writer.StartLap(expectedLap2Time);
            writeTrackPoints();
            writer.EndLap();

            writer.EndActivity();
            writer.Dispose();

            var root = XElement.Parse(result.ToString());
            var activities = GetActivities(root);
            var activity = activities.Single();
            Assert.AreEqual(activity.Sport, "Biking");
            Assert.AreEqual("0006-05-04T03:02:01Z", activity.Id);

            Assert.AreEqual(2, activity.Laps.Count());
            AssertLap(activity.Laps.First());
            AssertLap(activity.Laps.Last());
        }
示例#6
0
 public void TestEmptyTcx()
 {
     var writer = new TcxWriter(textWriter);
     writer.Dispose();
     Assert.AreEqual(string.Empty, result.ToString());
 }