/// <summary>
        /// Check if the marker is conform to the timing rules
        /// </summary>
        /// <param name="marker">the marker to be checked</param>
        /// <returns>true: is conform; false: is not conform</returns>
        public bool CheckConformance(MarkerDrop marker)
        {
            bool isConform = true;

            if (OpenAtMinute < CloseAtMinute)
            {
                if (marker.MarkerLocation.TimeStamp.Minute < OpenAtMinute)
                {
                    isConform = false;
                }
                if (marker.MarkerLocation.TimeStamp.Minute > CloseAtMinute)
                {
                    isConform = false;
                }
                if (marker.MarkerLocation.TimeStamp.Minute == CloseAtMinute && marker.MarkerLocation.TimeStamp.Second > 0)
                {
                    isConform = false;
                }
            }
            else if (OpenAtMinute > CloseAtMinute)
            {
                if ((marker.MarkerLocation.TimeStamp.Minute < OpenAtMinute) && (marker.MarkerLocation.TimeStamp.Minute > CloseAtMinute))
                {
                    isConform = false;
                }
                if (marker.MarkerLocation.TimeStamp.Minute == CloseAtMinute && marker.MarkerLocation.TimeStamp.Second > 0)
                {
                    isConform = false;
                }
            }


            return(isConform);
        }
        /// <summary>
        /// Check if the marker is conform to the distance rules to the other markers
        /// <para>will not check against itself</para>
        /// </summary>
        /// <param name="marker">the marker to be checked</param>
        /// <returns>true: is conform; false: is not conform</returns>
        public bool CheckConformance(MarkerDrop marker)
        {
            bool isConform = true;

            foreach (MarkerDrop markerDrop in MarkerDrops)
            {
                if (marker.Equals(markerDrop))
                {
                    continue;
                }
                double distanceToOtherMarker = CoordinateHelpers.Calculate2DDistance(marker.MarkerLocation, markerDrop.MarkerLocation);
                if (!double.IsNaN(MinimumDistance))
                {
                    if (distanceToOtherMarker < MinimumDistance)
                    {
                        isConform = false;
                    }
                }
                if (!double.IsNaN(MaximumDistance))
                {
                    if (distanceToOtherMarker > MaximumDistance)
                    {
                        isConform = false;
                    }
                }
            }
            return(isConform);
        }
        /// <summary>
        /// Check if the marker is conform to the distance rules to the declared goal
        /// </summary>
        /// <param name="marker">the marker to be checked</param>
        /// <returns>true: is conform; false: is not conform</returns>
        public bool CheckConformance(MarkerDrop marker)
        {
            bool   isConform      = true;
            double distanceToGoal = CoordinateHelpers.Calculate2DDistance(marker.MarkerLocation, Goal.GoalDeclared);

            if (!double.IsNaN(MinimumDistance))
            {
                if (distanceToGoal < MinimumDistance)
                {
                    isConform = false;
                }
            }
            if (!double.IsNaN(MaximumDistance))
            {
                if (distanceToGoal > MaximumDistance)
                {
                    isConform = false;
                }
            }
            return(isConform);
        }
Esempio n. 4
0
        ///// <summary>
        ///// Applies the specified rules to a marker drop and returns if its conform to the rules
        ///// </summary>
        ///// <param name="markerDrop">the marker to be checked</param>
        ///// <param name="markerValidationRules">the rules to be applied</param>
        ///// <returns>true: marker is valid; false: marker is invalid</returns>
        //public static bool IsMarkerValid(MarkerDrop markerDrop, List<IMarkerValidationRules> markerValidationRules)
        //{
        //    bool isValid = true;
        //    foreach (IMarkerValidationRules markerValidationRule in markerValidationRules)
        //    {
        //        isValid &= markerValidationRule.CheckConformance(markerDrop);
        //    }
        //    return isValid;
        //}

        /// <summary>
        /// Applies the specified rules to a marker drop and returns if its conform to the rules
        /// </summary>
        /// <param name="track">the track to be used</param>
        /// <param name="markerNumber">the target marker number</param>
        /// <param name="markerValidationRules">the rules to be applied</param>
        /// <returns>true: marker is valid; false: marker is invalid or doesn't exists</returns>
        public static bool IsMarkerValid(Track track, int markerNumber, List <IMarkerValidationRules> markerValidationRules)
        {
            bool       isValid    = true;
            MarkerDrop markerDrop = track.MarkerDrops.FirstOrDefault(x => x.MarkerNumber == markerNumber);

            if (markerDrop == null)
            {
                //Console.WriteLine($"No Marker '{FirstMarkerNumber}' found");
                Logger.Log(LogSeverityType.Error, $"No Marker '{markerNumber}' found");
                isValid = false;
            }
            else
            {
                if (markerValidationRules != null)
                {
                    foreach (IMarkerValidationRules markerValidationRule in markerValidationRules)
                    {
                        isValid &= markerValidationRule.CheckConformance(markerDrop);
                    }
                }
            }
            return(isValid);
        }
        /// <summary>
        /// Calculate the area of the triangle specified by the three markers in square meter
        /// </summary>
        /// <param name="track">the track to be used</param>
        /// <param name="useGPSAltitude">true: use GPS altitude;false: use barometric altitude</param>
        /// <param name="result">the area of the triangle in square meter</param>
        /// <returns>true:success;false:error</returns>
        public bool CalculateResults(Track track, bool useGPSAltitude, out double result)
        {
            string functionErrorMessage = $"Failed to calculate result for {this} and Pilot '#{track.Pilot.PilotNumber}{(!string.IsNullOrWhiteSpace(track.Pilot.FirstName)?$"({track.Pilot.FirstName},{track.Pilot.LastName})":"")}': ";

            result = 0.0;
            //MarkerDrop firstMarker = track.MarkerDrops.FirstOrDefault(x => x.MarkerNumber == FirstMarkerNumber);
            //if (firstMarker == null)
            //{
            //    //Console.WriteLine($"No Marker '{FirstMarkerNumber}' found");
            //    Log(LogSeverityType.Error, functionErrorMessage + $"No Marker '{FirstMarkerNumber}' found");
            //    return false;
            //}
            //if (!ValidationHelper.IsMarkerValid(firstMarker, MarkerValidationRules))
            //{
            //    //Console.WriteLine($"Marker '{FirstMarkerNumber}' is not valid");
            //    Log(LogSeverityType.Error, functionErrorMessage + $"Marker '{FirstMarkerNumber}' is invalid");
            //    return false;
            //}
            if (!ValidationHelper.IsMarkerValid(track, FirstMarkerNumber, MarkerValidationRules))
            {
                //Console.WriteLine($"Marker '{FirstMarkerNumber}' is not valid");
                Log(LogSeverityType.Error, functionErrorMessage + $"Marker '{FirstMarkerNumber}' is invalid or doesn't exists");
                return(false);
            }
            //MarkerDrop secondMarker = track.MarkerDrops.FirstOrDefault(x => x.MarkerNumber == SecondMarkerNumber);
            //if (secondMarker == null)
            //{
            //    //Console.WriteLine($"No Marker '{SecondMarkerNumber}' found");
            //    Log(LogSeverityType.Error, functionErrorMessage + $"No Marker '{SecondMarkerNumber}' found");
            //    return false;
            //}
            //if (!ValidationHelper.IsMarkerValid(secondMarker, MarkerValidationRules))
            //{
            //    //Console.WriteLine($"Marker '{SecondMarkerNumber}' is not valid");
            //    Log(LogSeverityType.Error, functionErrorMessage + $"Marker '{SecondMarkerNumber}' is invalid");
            //    return false;
            //}
            if (!ValidationHelper.IsMarkerValid(track, SecondMarkerNumber, MarkerValidationRules))
            {
                //Console.WriteLine($"Marker '{SecondMarkerNumber}' is not valid");
                Log(LogSeverityType.Error, functionErrorMessage + $"Marker '{SecondMarkerNumber}' is invalid or doesn't exists");
                return(false);
            }
            //MarkerDrop thirdMarker = track.MarkerDrops.FirstOrDefault(x => x.MarkerNumber == ThirdMarkerNumber);
            //if (thirdMarker == null)
            //{
            //    //Console.WriteLine($"No Marker '{ThirdMarkerNumber}' found");
            //    Log(LogSeverityType.Error, functionErrorMessage + $"No Marker '{ThirdMarkerNumber}' found");
            //    return false;
            //}
            //if (!ValidationHelper.IsMarkerValid(thirdMarker, MarkerValidationRules))
            //{
            //    //Console.WriteLine($"Marker '{ThirdMarkerNumber}' is not valid");
            //    Log(LogSeverityType.Error, functionErrorMessage + $"Marker '{ThirdMarkerNumber}' is invalid");
            //    return false;
            //}
            if (!ValidationHelper.IsMarkerValid(track, ThirdMarkerNumber, MarkerValidationRules))
            {
                //Console.WriteLine($"Marker '{ThirdMarkerNumber}' is not valid");
                Log(LogSeverityType.Error, functionErrorMessage + $"Marker '{ThirdMarkerNumber}' is invalid or doesn't exists");
                return(false);
            }
            MarkerDrop firstMarker  = track.MarkerDrops.FirstOrDefault(x => x.MarkerNumber == FirstMarkerNumber);
            MarkerDrop secondMarker = track.MarkerDrops.FirstOrDefault(x => x.MarkerNumber == SecondMarkerNumber);
            MarkerDrop thirdMarker  = track.MarkerDrops.FirstOrDefault(x => x.MarkerNumber == ThirdMarkerNumber);

            result = CoordinateHelpers.CalculateArea(firstMarker.MarkerLocation, secondMarker.MarkerLocation, thirdMarker.MarkerLocation);
            return(true);
        }