예제 #1
0
        public static IEnumerable<TimeDoubleDataEntry> GenerateRandomData(
            DateTime startTime,
            TimeSpan timeRange,
            long numOfPoints,
            double maxValue,
            double minValue,
            double rippleFactor)
        {
            var points = new List<TimeDoubleDataEntry>();
            var point = new TimeDoubleDataEntry(startTime, 0);
            var stepSize = timeRange.TotalSeconds / numOfPoints;
            for (long i = 0; i < numOfPoints; i++)
            {
                // distance +- 5 from previous point
                var delta = Random.NextDouble() * rippleFactor;
                // pos or neg?
                if (Random.Next(0, 2) == 0)
                    delta = -delta;

                var y = point.Y + delta;
                if (y > maxValue)
                    y = maxValue;
                else if (y < minValue)
                    y = minValue;

                point = new TimeDoubleDataEntry(point.X.AddSeconds(stepSize), y);
                points.Add(point);
            }
            return points;
        }
 /// <summary>
 /// Gets a value for a given point in time.
 /// </summary>
 /// <param name="dateTime">The point in time.</param>
 /// <param name="leftValue">The value in a series that lies directly left of the time.</param>
 /// <param name="rightValue">The value in a series that lies directly right of the time.</param>
 /// <returns>The value.</returns>
 public double GetMiddleValue(DateTime dateTime, TimeDoubleDataEntry leftValue, TimeDoubleDataEntry rightValue)
 {
     return MathHelper.LinearInterpolation(
         leftValue.X.Ticks,
         leftValue.Y,
         rightValue.X.Ticks,
         rightValue.Y,
         dateTime.Ticks);
 }
        private IEnumerable<TimeDoubleDataEntry> CreatePoints(TimeSpan timeRange, bool append)
        {
            var points = new List<TimeDoubleDataEntry>();
            var point = append ? GetLastPointOrDefault() : GetFirstPointOrDefault();
            if (double.IsNaN(point.Y))
                point = new TimeDoubleDataEntry(point.X, Offset);
            var numOfSteps = (long)(NumberOfPointsPerSecond * timeRange.TotalSeconds);
            var stepSize = timeRange.TotalSeconds / numOfSteps;
            for (long i = 0; i < numOfSteps; i++)
            {
                // Abstand +- 5 vom vorherigen Punkt
                var delta = _random.NextDouble() * _yStepSize;
                // Pos oder Neg?
                if (_random.Next(0, 2) == 0)
                    delta = -delta;

                var y = point.Y + delta;
                if (y > MaxValue)
                    y = MaxValue;
                else if (y < MinValue)
                    y = MinValue;

                point = append
                    ? new TimeDoubleDataEntry(point.X.AddSeconds(stepSize), y)
                    : new TimeDoubleDataEntry(point.X.AddSeconds(-stepSize), y);
                points.Add(point);
            }
            return points;
        }