public static IPoolLengthInfo GetPoolLength(IPoolLengthInfo p) { IPoolLengthInfo res = p; if (p.TotalDistanceMeters > 600) { //At least 920XT w fw 5.20/6.10 is imported incorrectly in ST res = new PoolLengthInfo(p); uint iByte = BitConverter.ToUInt32(BitConverter.GetBytes(p.TotalDistanceMeters), 0); if (iByte == 0x442338f6) { res.TotalDistanceMeters = 25; } else if (iByte == 0x4423345c || iByte == 0x44233f5c /*??*/) { res.TotalDistanceMeters = 50; } else if (iByte == 0x44233b85) { res.TotalDistanceMeters = 33.333f; } else if (iByte == 0x44235852) { res.TotalDistanceMeters = 150; } else if (iByte == 0x4423370a) { res.TotalDistanceMeters = 17; } else if (iByte == 0x44233a3d) { res.TotalDistanceMeters = (float)Length.Convert(33.333, Length.Units.Yard, Length.Units.Meter); } else if (iByte == 0x44233852) { res.TotalDistanceMeters = (float)Length.Convert(25, Length.Units.Yard, Length.Units.Meter); } } return(res); }
public static TrailResultInfo TrailResultInfoFromSplits(IActivity activity, bool onlyActiveLaps) { TrailResultInfo results = new TrailResultInfo(activity, false); if (activity == null) { //summary result return(results); } //Get around a problem with only Rest laps if (onlyActiveLaps) { onlyActiveLaps = false; for (int j = 0; j < activity.Laps.Count; j++) { if (!activity.Laps[j].Rest) { onlyActiveLaps = true; break; } } } bool lastIsRestlap = false; if (null == activity.Laps || 0 == activity.Laps.Count) { //Use MovingDistanceMetersTrack rather than ActualDistanceMetersTrack, assume similar activities have similar pauses/slow parts IDistanceDataTrack track = ActivityInfoCache.Instance.GetInfo(activity).MovingDistanceMetersTrack; if (track != null && track.Max > 0) { //Create some kind of points - could be dependent on length const float cDist = 1000; float dist = 0; while (dist < track.Max) { DateTime time = track.GetTimeAtDistanceMeters(dist); IGPSPoint p = Utils.TrackUtil.getGpsLoc(activity, time); if (p != null) { results.Points.Add(new TrailResultPoint(new TrailGPSLocation(p), time)); } else { if (activity.GPSRoute == null || activity.GPSRoute.Count == 0) { results.Points.Add(new TrailResultPoint(new TrailGPSLocation(activity.Name, true), time, track.TotalElapsedSeconds)); } else { System.Diagnostics.Debug.Assert(false, "out of GPS"); if (results.Points.Count > 0) { //end insert break; } } } dist = Math.Min(track.Max, dist + cDist); } } else { DateTime time = ActivityInfoCache.Instance.GetInfo(activity).ActualTrackStart; IGPSPoint p = Utils.TrackUtil.getGpsLoc(activity, time); if (p != null) { results.Points.Add(new TrailResultPoint(new TrailGPSLocation(p), time)); } } } else { int subresultIndex = 1; for (int j = 0; j < activity.Laps.Count; j++) { ILapInfo l = activity.Laps[j]; if (!onlyActiveLaps || !l.Rest || j > 0 && !activity.Laps[j - 1].Rest) { string name = l.Notes; if (string.IsNullOrEmpty(name)) { name = "#" + (results.Points.Count + 1); } DateTime d = l.StartTime; if (activity.GPSRoute == null || activity.GPSRoute.Count == 0) { results.Points.Add(new TrailResultPoint(new TrailGPSLocation(name, !l.Rest), d, l.TotalTime, l)); } else { IGPSPoint t = Utils.TrackUtil.getGpsLoc(activity, d); if (t != null) { results.Points.Add(new TrailResultPoint(new TrailGPSLocation(t, name, !l.Rest), d, l.TotalTime, l)); } } if (//All swim related have at least one PoolLength for each lap l.PoolLengths != null && (l.PoolLengths.Count > 0)) { TrailResultPoint tp = results.Points[results.Points.Count - 1]; foreach (IPoolLengthInfo p in l.PoolLengths) { DateTime d2 = p.StartTime; IPoolLengthInfo p1 = PoolLengthInfo.GetPoolLength(p); tp.SubPoints.Add(new TrailResultPoint(new TrailGPSLocation(null, !l.Rest), d2, p.TotalTime, p1, subresultIndex++)); } //Need (dummy) last point IPoolLengthInfo p2 = tp.SubPoints[tp.SubPoints.Count - 1].PoolLengthInfo; tp.SubPoints.Add(new TrailResultPoint(new TrailGPSLocation(null, !l.Rest), p2.StartTime + p2.TotalTime, TimeSpan.Zero, p2, subresultIndex)); } } } lastIsRestlap = activity.Laps[activity.Laps.Count - 1].Rest; } //Add end point, except if last is a rest lap (where last already is added) if (!onlyActiveLaps || !lastIsRestlap) { DateTime d = ActivityInfoCache.Instance.GetInfo(activity).ActualTrackEnd; if (activity.GPSRoute == null || activity.GPSRoute.Count == 0) { results.Points.Add(new TrailResultPoint(new TrailGPSLocation(activity.Name, !lastIsRestlap), d)); } else { IGPSPoint t = Utils.TrackUtil.getGpsLoc(activity, d); if (t != null) { results.Points.Add(new TrailResultPoint(new TrailGPSLocation(t, activity.Name, !lastIsRestlap), d)); } } } //Special for activities without any GPS info if (results.Count == 0 && activity.HasStartTime) { results.Points.Add(new TrailResultPoint(new TrailGPSLocation(activity.Name, true), activity.StartTime)); results.Points.Add(new TrailResultPoint(new TrailGPSLocation(activity.Name, true), activity.StartTime + activity.TotalTimeEntered)); } //A trail created from splits should not define elevation points foreach (TrailGPSLocation t in results.Points) { t.SetElevation(float.NaN); } return(results); }