public void UpdateRow(TrailResult tr, TrailGPSLocation t)
 {
     this.TrailGPS = t;
     if (tr != null && m_resultPointIndex < tr.TrailPointDateTime.Count)
     {
         SetDistance(tr, tr.TrailPointDateTime[m_resultPointIndex]);
     }
 }
Exemple #2
0
        private void addPausesAsResults(IList <ChildTrailResult> splits, int lastNormalSplit, ICollection <IValueRange <DateTime> > pauses, PauseType pauseType)
        {
            foreach (IValueRange <DateTime> v in pauses)
            {
                //Pauses could extend outside the borders
                DateTime lower = v.Lower;
                if (lower == DateTime.MinValue)
                {
                    lower = m_subResultInfo.Points[0].Time;
                }
                DateTime upper = v.Upper;
                if (upper == DateTime.MaxValue)
                {
                    upper = m_subResultInfo.Points[m_subResultInfo.Points.Count - 1].Time;
                }

                //skip very short pauses
                TimeSpan duration = upper - lower;
                if (duration < TimeSpan.FromSeconds(1) &&
                    (this.StartTime - lower < TimeSpan.FromSeconds(1) ||
                     upper - this.EndTime < TimeSpan.FromSeconds(1)))
                {
                    continue;
                }

                //Match the pause to a split
                for (int j = 0; j <= lastNormalSplit; j++)
                {
                    if (splits[j].m_subResultInfo.Points[0].Time > DateTime.MinValue &&
                        splits[j].m_subResultInfo.Points[1].Time > DateTime.MinValue &&
                        //pause is started within this split
                        (splits[j].m_subResultInfo.Points[0].Time <= lower && lower <= splits[j].m_subResultInfo.Points[1].Time ||
                         //(First) lap, ends in the split
                         /*splits[j].*/ m_subResultInfo.Points[0].Time <= upper && upper < splits[j].m_subResultInfo.Points[1].Time ||
                         //For splits we want pauses also before after first normal split
                         this.Trail.IsSplits && (
                             upper < splits[j].m_subResultInfo.Points[0].Time ||
                             j == lastNormalSplit && splits[j].m_subResultInfo.Points[1].Time < lower)))
                    {
                        TrailResultInfo  t  = new TrailResultInfo(this.m_subResultInfo.Activity, this.m_subResultInfo.Reverse);
                        TrailGPSLocation tl = new TrailGPSLocation(PausedChildTrailResult.PauseName(pauseType), false);
                        t.Points.Add(new TrailResultPoint(tl, lower, duration));
                        t.Points.Add(new TrailResultPoint(tl, upper, TimeSpan.Zero));

                        PausedChildTrailResult tr = new PausedChildTrailResult(this, splits[j], -1, t, pauseType);
                        if (pauseType == PauseType.RestLap)
                        {
                            if (this.m_lapPauseMapping.ContainsKey(v))
                            {
                                tr.m_LapInfo = this.m_lapPauseMapping[v];
                            }
                        }
                        splits.Add(tr);
                        break;
                    }
                }
            }
        }
Exemple #3
0
 public TrailResultPoint(TrailResultPoint t, TrailGPSLocation loc)
     : base(loc)
 {
     this.m_time = t.Time;
     //this.m_name = t.Name;
     this.DistDiff       = t.DistDiff;
     this.Duration       = t.Duration;
     this.LapInfo        = t.LapInfo;
     this.PoolLengthInfo = t.PoolLengthInfo;
     this.Order          = t.Order;
     foreach (TrailResultPoint t2 in t.SubPoints)
     {
         this.SubPoints.Add(t2);
     }
 }
Exemple #4
0
        /*****************************************************************************/
        //static utilities to get the areas for a set of points (not always a complete trail)

        //Get location bounds for a set of points
        public static int LocationBounds(IList <TrailGPSLocation> trailgps, IList <IGPSBounds> locationBounds, float radius)
        {
            int noNonReq = 0;

            foreach (TrailGPSLocation l in trailgps)
            {
                if (!l.Required)
                {
                    noNonReq++;
                }
                locationBounds.Add(TrailGPSLocation.getGPSBounds(new List <TrailGPSLocation> {
                    l
                }, radius));
            }
            return(noNonReq);
        }
Exemple #5
0
 private static void AddElevationPoints(Data.Trail trail)
 {
     if (!trail.Generated)
     {
         foreach (TrailGPSLocation t in trail.TrailLocations)
         {
             if (!trail.Generated && !float.IsNaN(t.ElevationMeters))
             {
                 TrailGPSLocation l = new TrailGPSLocation(t);
                 l.Name = trail.Name + " " + GpsRunningPlugin.Util.UnitUtil.Elevation.ToString(l.Radius, "u");
                 //Set the trail radius to one of the points
                 ElevationPointsTrail.Radius = l.Radius;
                 ElevationPointsTrail.TrailLocations.Add(l);
             }
         }
     }
 }
 private EditTrailRow(TrailGPSLocation loc, TrailResult tr, int i)
     : this(loc)
 {
     this.m_resultPointIndex = i;
     if (tr != null && tr.TrailPointDateTime.Count > 0)
     {
         DateTime d = DateTime.MinValue;
         if (tr.TrailPointDateTime != null &&
             tr.TrailPointDateTime.Count > m_resultPointIndex && m_resultPointIndex >= 0)
         {
             d = tr.TrailPointDateTime[m_resultPointIndex];
         }
         SetDistance(tr, d);
         if (this.m_resultPointIndex < tr.SubResultInfo.Count)
         {
             this.m_diff = tr.PointDiff(this.m_resultPointIndex);
         }
     }
 }
Exemple #7
0
        //Note: Faster to keep this static then
        public static float DistanceMetersToPointSimple(TrailGPSLocation trailp, IGPSPoint point)
        {
#if NO_SIMPLE_DISTANCE
            return(trailp.DistanceMetersToPoint(point));
#else
            //Use the trailp lat instead of average lat
            if (trailp._cosmean == invalidLatLon)
            {
                trailp._cosmean = (float)Math.Cos(trailp.latitudeDegrees * DegToRad);
            }
            float dlat   = point.LatitudeDegrees - trailp.latitudeDegrees;
            float dlon   = point.LongitudeDegrees - trailp.longitudeDegrees;
            float result = dlat * dlat + dlon * dlon * trailp._cosmean;

#if SQUARE_DISTANCE
            return(result);
#else
            return(EarthRadius * DegToRad * (float)Math.Sqrt(result));
#endif
#endif
        }
Exemple #8
0
        private Trail Copy(Guid id)
        {
            Trail result = new Trail(id, false)
            {
                Name = this.Name,

                //Do not copy "auto" attributes
                m_radius           = this.Radius,
                MinDistance        = this.MinDistance,
                MaxRequiredMisses  = this.MaxRequiredMisses,
                BiDirectional      = this.BiDirectional,
                IsNameMatch        = this.IsNameMatch,
                IsCompleteActivity = this.IsCompleteActivity,
                IsURFilter         = this.IsURFilter,
                //result.IsAutoTryAll = this.IsAutoTryAll;
                IsTemporary = this.IsTemporary,
                Parent      = this.Parent
            };

            foreach (Trail t in this.Children)
            {
                result.Children.Add(t);
            }

            if (!this.m_generated)
            {
                result.TrailPriority = this.TrailPriority;
            }
            result.DefaultRefActivity = this.DefaultRefActivity;

            result.m_trailLocations = new List <TrailGPSLocation>();
            foreach (TrailGPSLocation t in this.TrailLocations)
            {
                TrailGPSLocation t2 = new TrailGPSLocation(t);
                result.m_trailLocations.Add(t2);
            }

            return(result);
        }
Exemple #9
0
        public TrailResultInfo CopyFromReference(IActivity activity)
        {
            TrailResultInfo result = new TrailResultInfo(activity, this.Reverse);

            foreach (TrailResultPoint p in Points)
            {
                TrailGPSLocation loc;
                ZoneFiveSoftware.Common.Data.GPS.IGPSPoint t = Utils.TrackUtil.getGpsLoc(activity, p.Time);
                if (t != null)
                {
                    loc = new TrailGPSLocation(t, p.Name, p.Required);
                }
                else
                {
                    loc = new TrailGPSLocation(p.Name, p.Required);
                }

                TrailResultPoint p2 = new TrailResultPoint(p, loc);
                p2.LapInfo        = null;
                p2.PoolLengthInfo = null;
                result.Points.Add(p2);
            }
            return(result);
        }
Exemple #10
0
 public TrailResultPoint(TrailGPSLocation trailLocation, DateTime time, TimeSpan duration, ILapInfo lapInfo)
     : this(trailLocation, time, duration)
 {
     this.LapInfo = lapInfo;
 }
 public EditTrailRow(TrailGPSLocation loc)
 {
     m_gpsLoc = loc;
 }
Exemple #12
0
 public SplitGPSLocation(TrailGPSLocation t, System.Drawing.Color c) : base(t)
 {
     this.PointColor = c;
 }
Exemple #13
0
 public TrailGPSLocation(TrailGPSLocation trailLocation)
     : this(trailLocation.LatitudeDegrees, trailLocation.LongitudeDegrees, trailLocation.ElevationMeters, trailLocation._name, trailLocation._required, trailLocation._radius)
 {
 }
Exemple #14
0
        public static Trail ReadOptions(XmlDocument xmlDoc, XmlNamespaceManager nsmgr, XmlElement node)
        {
            Guid Id;

            if (node.Attributes[XmlTags.sId] == null || String.IsNullOrEmpty(node.Attributes[XmlTags.sId].Value))
            {
                Id = System.Guid.NewGuid();
            }
            else
            {
                try
                {
                    Id = new Guid(node.Attributes[XmlTags.sId].Value.ToString());
                }
                catch (Exception)
                {
                    Id = System.Guid.NewGuid();
                }
            }
            Trail trail = new Trail(Id, false)
            {
                Name = node.Attributes[XmlTags.sName].Value.ToString()
            };

            //Hidden possibility to get trails matching everything while activities are seen
            //if (trail.Name.EndsWith("MatchAll"))
            //{
            //    trail.IsSplits = true;
            //}
            if (node.Attributes[XmlTags.sRadius] != null)
            {
                trail.Radius = Settings.ParseFloat(node.Attributes[XmlTags.sRadius].Value);
            }
            if (node.Attributes[XmlTags.sDefaultRefActivity] != null)
            {
                trail.m_DefaultRefActivityString = node.Attributes[XmlTags.sDefaultRefActivity].Value;
            }

            if (node.Attributes[XmlTags.sMinDistance] != null)
            {
                trail.MinDistance = (Int16)XmlConvert.ToInt16(node.Attributes[XmlTags.sMinDistance].Value);
            }
            if (node.Attributes[XmlTags.sMaxRequiredMisses] != null)
            {
                trail.MaxRequiredMisses = (Int16)XmlConvert.ToInt16(node.Attributes[XmlTags.sMaxRequiredMisses].Value);
            }
            if (node.Attributes[XmlTags.sBiDirectional] != null)
            {
                //Output prior to 1.0.604 is not xml parsable (only if trail modified manually)
                trail.BiDirectional = XmlConvert.ToBoolean(node.Attributes[XmlTags.sBiDirectional].Value.ToLower());
            }
            if (node.Attributes[XmlTags.sNameMatch] != null)
            {
                trail.IsNameMatch = XmlConvert.ToBoolean(node.Attributes[XmlTags.sNameMatch].Value);
            }
            if (node.Attributes[XmlTags.sCompleteActivity] != null)
            {
                trail.IsCompleteActivity = XmlConvert.ToBoolean(node.Attributes[XmlTags.sCompleteActivity].Value);
            }
            if (node.Attributes[XmlTags.sURFilter] != null)
            {
                trail.IsURFilter = XmlConvert.ToBoolean(node.Attributes[XmlTags.sURFilter].Value);
            }
            //if (node.Attributes[xmlTags.sAutoTryAll] != null)
            //{
            //    trail.IsAutoTryAll = XmlConvert.ToBoolean(node.Attributes[xmlTags.sAutoTryAll].Value);
            //}
            if (node.Attributes[XmlTags.sTrailPriority] != null)
            {
                trail.TrailPriority = (Int16)XmlConvert.ToInt16(node.Attributes[XmlTags.sTrailPriority].Value);
            }

            trail.TrailLocations.Clear();
            foreach (XmlNode TrailGPSLocationNode in node.SelectNodes(XmlTags.sTrailGPSLocation))
            {
                trail.TrailLocations.Add(TrailGPSLocation.FromXml(TrailGPSLocationNode));
                if (string.IsNullOrEmpty(trail.TrailLocations[trail.TrailLocations.Count - 1].Name))
                {
                    //Name the trail points
                    trail.TrailLocations[trail.TrailLocations.Count - 1].Name =
                        "#" + trail.TrailLocations.Count;
                }
            }
            //Set radius - not stored per trail point
            trail.Radius = trail.m_radius;

            return(trail);
        }
Exemple #15
0
 //public TrailResultPoint(DateTime time, string name, bool active, float distDiff)
 //{
 //    this.m_time = time;
 //    this.m_name = name;
 //    this.Active = active;
 //    this.DistDiff = distDiff;
 //}
 //public TrailResultPoint(DateTime time, string name, bool active)
 //    : this(time, name, active, 0)
 //{
 //}
 //public TrailResultPoint(DateTime time, string name)
 //    : this(time, name, true, 0)
 //{
 //}
 public TrailResultPoint(TrailGPSLocation trailLocation, DateTime time, float distDiff)
     : base(trailLocation)
 {
     this.m_time   = time;
     this.DistDiff = distDiff;
 }
Exemple #16
0
 public TrailResultPoint(TrailGPSLocation trailLocation, DateTime time, TimeSpan duration, IPoolLengthInfo lapInfo, int subresultIndex)
     : this(trailLocation, time, duration)
 {
     this.PoolLengthInfo = lapInfo;
     this.Order          = subresultIndex;
 }
Exemple #17
0
        public static float checkPass(float radius, IGPSPoint r1, float dt1, IGPSPoint r2, float dt2, TrailGPSLocation trailp, out float d)
        {
#if SQUARE_DISTANCE
            const int sqrt2 = 2;
#else
            //Optimise, accuracy is down to percent
            const float sqrt2 = 1.4142135623730950488016887242097F;
#endif
            d = float.MaxValue;
            float factor = -1;
            if (r1 == null || r2 == null || trailp == null)
            {
                return(factor);
            }

            //Check if the line goes via the "circle" if the sign changes
            //Also need to check close points that fit in a 45 deg tilted "square" where sign may not change

            //Optimise for all conditions tested - property access takes some time
            float tplat = trailp.latitudeDegrees;
            float tplon = trailp.longitudeDegrees;
            float r1lat = r1.LatitudeDegrees;
            float r1lon = r1.LongitudeDegrees;
            float r2lat = r2.LatitudeDegrees;
            float r2lon = r2.LongitudeDegrees;
            if (r1lat > tplat && r2lat < tplat ||
                r1lat < tplat && r2lat > tplat ||
                r1lon > tplon && r2lon < tplon ||
                r1lon < tplon && r2lon > tplon ||
                dt1 < radius * sqrt2 && dt2 < radius * sqrt2)
            {
                //Law of cosines - get a1, angle at r1, the first point
                float d12 = TrailGPSLocation.DistanceMetersToPointGpsSimple(r1, r2);
#if SQUARE_DISTANCE
                float a1_0 = (float)((dt1 + d12 - dt2) / (2 * Math.Sqrt(dt1 * d12)));
#else
                float a1_0 = (dt1 * dt1 + d12 * d12 - dt2 * dt2) / (2 * dt1 * d12);
#endif

                //Point is in circle if closest point is between r1&r2 and it is in circle (neither r1 nor r2 is)
                //This means the angle a1 must be +/- 90 degrees : cos(a1)>=0
                if (a1_0 > -0.001)
                {
                    //Rounding errors w GPS measurements
                    a1_0 = Math.Min(a1_0, 1);
                    a1_0 = Math.Max(a1_0, -1);
                    float a1 = (float)Math.Acos(a1_0);
                    //x is closest point to t on r1-r2
                    //Dist from r1 to x
                    float d1x = (float)Math.Abs(dt1 * a1_0); //a1_0 = (float)Math.Cos(a1);
                    //Dist from t1 to x
                    float dtx = dt1 * (float)Math.Sin(a1);
                    if (d1x < d12 && dtx < radius)
                    {
                        d      = dtx;
                        factor = (float)(d1x / d12);
                        //Return factor, to return best aproximation from r1
                    }
                }
            }
            return(factor);
        }
Exemple #18
0
 public TrailResultPoint(TrailGPSLocation trailLocation, DateTime time, TimeSpan duration)
     : this(trailLocation, time)
 {
     this.Duration = duration;
 }
Exemple #19
0
 public TrailResultPoint(TrailGPSLocation trailLocation, DateTime time)
     : this(trailLocation, time, 0)
 {
 }