Beispiel #1
0
        public bool IsWithinThreshold(int BarNumber, IAggregateLine CandidateLine)
        {
            decimal candidateVerticalDistanceAway = (decimal)Math.Abs((double)(this.GetValueAt(BarNumber) - CandidateLine.GetValueAt(BarNumber)));

            if ((candidateVerticalDistanceAway <= this.VerticalDistanceThreshold) &&
                ((decimal)Math.Abs((double)(this.Gradient - (CandidateLine as TrendLine).Gradient)) <= this.AbsoluteGradientThreshold))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Sets IsCongested and CongestedBoundary on the passed lines
        /// </summary>
        /// <param name="Lines"></param>
        /// <param name="BarNumber"></param>
        public void GetCongestion(ref AggregateLines Lines, int BarNumber)
        {
            Dictionary <BarrierDirection, List <IAggregateLine> > linesOfSameDirection = GetLinesOfSameDirection(Lines);

            foreach (BarrierDirection key in linesOfSameDirection.Keys)
            {
                decimal        currentLimit = Decimal.MinValue;
                IAggregateLine previousLine = null;

                bool isCongested          = false;
                bool isPreviousSetToLower = false;
                bool isPreviousSetToUpper = false;

                foreach (IAggregateLine line in linesOfSameDirection[key].OrderBy(b => b.GetValueAt(BarNumber)))
                {
                    isPreviousSetToLower = false;
                    isPreviousSetToUpper = false;
                    decimal lineCurrentValue = line.GetValueAt(BarNumber);

                    //if ((lineCurrentValue - line.ProximateDistance) <= currentLimit)
                    if ((lineCurrentValue - line.CongestionDistance) <= currentLimit)
                    {
                        if (!isCongested)
                        {
                            isPreviousSetToLower = true;
                        }

                        isCongested = true;
                    }
                    else
                    {
                        if (isCongested)
                        {
                            isPreviousSetToUpper = true;
                            isCongested          = false;
                        }
                    }

                    line.IsCongested       = isCongested;
                    line.CongestedBoundary = CongestionBoundary.NotSet;

                    if (isPreviousSetToLower)
                    {
                        previousLine.CongestedBoundary = CongestionBoundary.Lower;
                        previousLine.IsCongested       = true;
                    }

                    if (isPreviousSetToUpper)
                    {
                        previousLine.CongestedBoundary = CongestionBoundary.Upper;
                        previousLine.IsCongested       = true;
                    }

                    //currentLimit = lineCurrentValue + line.ProximateDistance;
                    currentLimit = lineCurrentValue + line.CongestionDistance;
                    previousLine = line;
                }

                // if the last line was congested then it becomes a boundary
                if (isCongested)
                {
                    previousLine.CongestedBoundary = CongestionBoundary.Upper;
                    previousLine.IsCongested       = true;
                }
            }
        }
 public bool IsWithinThreshold(int BarNumber, IAggregateLine CandidateLine)
 {
     return((Decimal)Math.Abs(this.GetValueAt(BarNumber) - CandidateLine.GetValueAt(BarNumber)) <= this.VerticalThreshold);
 }