示例#1
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();
            }
        }
示例#2
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();
            }
        }
示例#3
0
        public LapStats EndLap()
        {
            LapStats stats = new LapStats();

            if (lapPoints.Count > 0)
            {
                // collect the stats from the points
                stats.TotalTimeSeconds = (lapPoints.Last().Time.Value - lapPoints.First().Time.Value).TotalSeconds;
                stats.DistanceMeters   = lapPoints.Max(p => p.ElapsedDistanceMeters.Value);
                stats.Calories         = lapPoints.Last().ElapsedCalories.Value;
            }

            // write out the status before we write out the track points
            // as required by the schema
            WriteElementAndValue("TotalTimeSeconds", TcxV2XmlNamespace, stats.TotalTimeSeconds);
            WriteElementAndValue("DistanceMeters", TcxV2XmlNamespace, stats.DistanceMeters);
            WriteElementAndValue("Calories", TcxV2XmlNamespace, stats.Calories);
            WriteElementAndValue("Intensity", TcxV2XmlNamespace, "Active");
            WriteElementAndValue("TriggerMethod", TcxV2XmlNamespace, "Manual");

            if (lapPoints.Count > 0)
            {
                // write out each of the track points
                xmlWriter.WriteStartElement("Track", TcxV2XmlNamespace);
                foreach (var point in lapPoints)
                {
                    WriteTrackPoint(point);
                }
                xmlWriter.WriteEndElement();
            }

            // </Lap>
            xmlWriter.WriteEndElement();

            this.lapPoints = null;
            return(stats);
        }
示例#4
0
        public LapStats EndLap()
        {
            LapStats stats = new LapStats();

            if (lapPoints.Count > 0)
            {
                // collect the stats from the points
                stats.TotalTimeSeconds = (lapPoints.Last().Time.Value - lapPoints.First().Time.Value).TotalSeconds;
                stats.DistanceMeters = lapPoints.Max(p => p.ElapsedDistanceMeters.Value);
                stats.Calories = lapPoints.Last().ElapsedCalories.Value;
            }

            // write out the status before we write out the track points
            // as required by the schema
            WriteElementAndValue("TotalTimeSeconds", TcxV2XmlNamespace, stats.TotalTimeSeconds);
            WriteElementAndValue("DistanceMeters", TcxV2XmlNamespace, stats.DistanceMeters);
            WriteElementAndValue("Calories", TcxV2XmlNamespace, stats.Calories);
            WriteElementAndValue("Intensity", TcxV2XmlNamespace, "Active");
            WriteElementAndValue("TriggerMethod", TcxV2XmlNamespace, "Manual");

            if (lapPoints.Count > 0)
            {
                // write out each of the track points
                xmlWriter.WriteStartElement("Track", TcxV2XmlNamespace);
                foreach (var point in lapPoints)
                {
                    WriteTrackPoint(point);
                }
                xmlWriter.WriteEndElement();
            }

            // </Lap>
            xmlWriter.WriteEndElement();

            this.lapPoints = null;
            return stats;
        }
示例#5
0
        public LapStats EndLap()
        {
            LapStats stats = new LapStats();

            if (_lapPoints.Count > 0)
            {
                // collect the stats from the points
                stats.TotalTimeSeconds = (_lapPoints.Last().Time.Value - _lapPoints.First().Time.Value).TotalSeconds;
                stats.DistanceMeters = _lapPoints.Max(p => p.ElapsedDistanceMeters??0);
                stats.Calories = _lapPoints.Last().ElapsedCalories??0;
                stats.AvgHeartRate = Convert.ToInt32(_lapPoints.Average(p => p.HeartRateBpm??0));
                stats.MaxHeartRate = Convert.ToInt32(_lapPoints.Max(p => p.HeartRateBpm ?? 0));
                stats.MaxSpeed = Convert.ToInt32(_lapPoints.Max(p => p.SpeedMetersPerSecond ?? 0));
                
            }

            // write out the status before we write out the track points
            // as required by the schema
            WriteElementAndValue("TotalTimeSeconds", TcxV2XmlNamespace, stats.TotalTimeSeconds);
            WriteElementAndValue("DistanceMeters", TcxV2XmlNamespace, stats.DistanceMeters);
            WriteElementAndValue("Calories", TcxV2XmlNamespace, stats.Calories);
            WriteElementAndValue("AverageHeartRateBpm", TcxV2XmlNamespace, stats.AvgHeartRate);
            WriteElementAndValue("MaximumHeartRateBpm", TcxV2XmlNamespace, stats.MaxHeartRate);
            WriteElementAndValue("MaximumSpeed", TcxV2XmlNamespace, stats.MaxSpeed);

            WriteElementAndValue("Intensity", TcxV2XmlNamespace, "Active");
            WriteElementAndValue("TriggerMethod", TcxV2XmlNamespace, "Manual");

            if (_lapPoints.Count > 0)
            {
                // write out each of the track points
                _xmlWriter.WriteStartElement("Track", TcxV2XmlNamespace);
                foreach (var point in _lapPoints)
                {
                    WriteTrackPoint(point);
                }
                _xmlWriter.WriteEndElement();
            }

            // </Lap>
            _xmlWriter.WriteEndElement();

            _lapPoints = null;
            return stats;
        }