当前位置: 首页>>代码示例>>C#>>正文


C# Series.LookupIndex方法代码示例

本文整理汇总了C#中Series.LookupIndex方法的典型用法代码示例。如果您正苦于以下问题:C# Series.LookupIndex方法的具体用法?C# Series.LookupIndex怎么用?C# Series.LookupIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Series的用法示例。


在下文中一共展示了Series.LookupIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SnapToNearest

        //public Selection(DateTime t1, DateTime t2)
        //{
        //    this.t1 = t1;
        //    this.t2 = t2;
        //    this.ymin = double.MinValue;
        //    this.ymax = double.MaxValue;
        //}
        /// <summary>
        /// 
        /// </summary>
        public void SnapToNearest(Series s)
        {
            int idx1 = s.LookupIndex(t1, true);
            int idx2 = s.LookupIndex(t2, true);

            if (idx1 < 0 || idx2 < 0)
            {
            throw new Exception("Error trying to snap to nearest point");
            }
            t1 = s[idx1].DateTime;
            t2 = s[idx2].DateTime;
        }
开发者ID:usbr,项目名称:Pisces,代码行数:22,代码来源:Selection.cs

示例2: LookupIndex

        public void LookupIndex()
        {
            Series s = new Series();
            s.Add("2006-01-01", 0);
            s.Add("2006-01-02", 1);
            s.Add("2006-01-03", 2);
            s.Add("2006-01-04", 3);
            s.Add("2006-01-05", 4);

            int i = s.LookupIndex(DateTime.Parse("2006-01-03 12:22 AM"));

            Assert.AreEqual(3, i);

            i = s.LookupIndex(DateTime.Parse("2006-01-03 12:22 AM"),true);

            Assert.AreEqual(2, i);
        }
开发者ID:usbr,项目名称:Pisces,代码行数:17,代码来源:TestLookupIndex.cs

示例3: SimpleAverageForDay

        private static Point SimpleAverageForDay(Series s, DateTime t, int requiredNumberOfPoints)
        {
            t = t.Date;
            DateTime tomorrow = t.AddDays(1);
            int index = s.LookupIndex(t);
            if (index < 0) //|| !s.WithinRange(t))
            {
                // throw new Exception("cannot find the date for an average");
                return new Point(t, Point.MissingValueFlag, PointFlag.Missing);
            }
            Point rval = new Point(t, 0);
            int count = 0;
            double val = 0;
            while (index < s.Count)
            {
                // integrate through the day.
                Point point = s[index];
                if (point.DateTime >= tomorrow)
                {
                    break;
                }
                if (!point.IsMissing && !point.FlaggedBad)
                {
                    val += point.Value;
                    count++;
                }
                index++;
            }

            if (count == 0)
                return new Point(t.Date, Point.MissingValueFlag, PointFlag.Missing);
            else if( count <requiredNumberOfPoints)
                return new Point(t.Date, Point.MissingValueFlag, PointFlag.Missing);
            else
                return new Point(t.Date, val / count, PointFlag.Computed);
        }
开发者ID:usbr,项目名称:Pisces,代码行数:36,代码来源:Math.Statistics.Daily.cs

示例4: Interpolate

        /// <summary>
        /// Interpolate value at specified time.
        /// </summary>
        /// <param name="s">Series containing values to interpolate from</param>
        /// <param name="t">DateTime to interpolate at</param>
        /// <param name="AllowExtrapolate">Allow extrapolation outside Series s</param>
        /// <param name="index">index to t or next index in series</param>
        /// <returns></returns>
        public static double Interpolate(Series s, DateTime t, bool AllowExtrapolate, int index)
        {
            if (!s.WithinRange(t) && !AllowExtrapolate)
            {
                string msg = "can not interpolate outside range (" + s.MinDateTime + " --> " + s.MaxDateTime
                  + ")\n  requested date is " + t;

                throw new ArgumentOutOfRangeException(msg);
            }
            int currentIndex = 0;
            if (index >= 0) // use input index to save lookup.
            {
                currentIndex = index;
            }
            else
            {
                currentIndex = s.LookupIndex(t);
            }

            int i = currentIndex;
            if (i < 0)
            {  // must allow [i-1]
                // this should not happen since we called WithinRange() above
                throw new Exception("cannot interpolate with outside array bounds.  error#2");
            }

            Point point = s[i];

            // first test for exact match.
            if (point.DateTime == t)
            {
                return point.Value;
            }

            Point pointM1 = s[i - 1];

            if (point.IsMissing || pointM1.IsMissing)
            {
                throw new Exception("Error: cannot interpolate when point is marked as missing");
            }

            if (point.DateTime >= t)
            {
                if (point.DateTime == t)
                {
                    return point.Value;
                }
                // interpolate.
                double y2 = System.Convert.ToDouble(point.Value);
                double y1 = System.Convert.ToDouble(pointM1.Value);
                DateTime date1 = System.Convert.ToDateTime(pointM1.DateTime);
                double rval = Interpolate(t, date1, point.DateTime, y1, y2);
                return rval;
            }

            if (true)
            {
                Console.WriteLine("Error:  cannot interpolate");
                throw new Exception("cannot interpolate error #3 did not find proper time. ");
            }
            //	return 0;
        }
开发者ID:usbr,项目名称:Pisces,代码行数:70,代码来源:Math.cs


注:本文中的Series.LookupIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。