/// <summary>
        /// Generates random TelemetryData.
        /// </summary>
        /// <param name="sampleCount">The sample count that is used to set the size of each TelemetryData.Parameter values' size.</param>
        /// <param name="sessionStart">Used to set the EpochNanos property of the TelemetryData. TelemetryData.Parameters
        /// share the same timestamps as they aligned to the same time.</param>
        /// <returns></returns>
        public static TelemetryData GenerateData(int sampleCount, DateTime sessionStart)
        {
            var data = new TelemetryData()
            {
                EpochNanos      = sessionStart.ToTelemetryTime(),
                TimestampsNanos = new long[sampleCount],
                Parameters      = new TelemetryParameterData[1] // The sample AtlasConfiguration has only 1 parameter
            };

            // The sample AtlasConfiguration has only 1 parameter, so data.Parameters[0] must be initialized only.
            data.Parameters[0] = new TelemetryParameterData()
            {
                AvgValues = new double[sampleCount],    // The data will be stored in the AvgValues array, so this must be initialized
                Statuses  = new DataStatus[sampleCount] // Status is stored for each data, so Statuses array must be initialized
            };

            var randomRangeWalker = new RandomRangeWalker(0, 1); // Used to generated random data

            for (int i = 0; i < sampleCount; i++)
            {
                var nextData = randomRangeWalker.GetNext();
                data.TimestampsNanos[i]         = i * Interval; // timestamps expressed in ns since the epoch, which is the start of the session
                data.Parameters[0].AvgValues[i] = nextData;
                data.Parameters[0].Statuses[i]  = DataStatus.Sample;
            }

            return(data);
        }
        /// <summary>
        /// Generates random TelemetrySamples.
        /// </summary>
        /// <param name="sampleCount">The sample count that is used to set the size of each TelemetrySamples.Values' size.</param>
        /// <param name="sessionStart">Used to set the EpochNanos property of the TelemetrySamples.</param>
        /// <returns></returns>
        public static TelemetrySamples GenerateSamples(int sampleCount, DateTime sessionStart)
        {
            var sample = new TelemetryParameterSamples()
            {
                EpochNanos      = sessionStart.ToTelemetryTime(),
                TimestampsNanos = new long[sampleCount],
                Values          = new double[sampleCount]
            };

            var randomRangeWalker = new RandomRangeWalker(0, 1); // Used to generated random data

            for (int i = 0; i < sampleCount; i++)
            {
                var nextSample = randomRangeWalker.GetNext();
                sample.TimestampsNanos[i] = i * Interval;
                sample.Values[i]          = nextSample;
            }

            var data = new TelemetrySamples()
            {
                Parameters = new Dictionary <string, TelemetryParameterSamples>()
                {
                    { ParameterId, sample } // If you had more samples to send for other parameters, this is where you would add them
                }
            };

            return(data);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates random TelemetrySamples.
        /// </summary>
        /// <param name="sampleCount">The sample count that is used to set the size of each TelemetrySamples.Values' size.</param>
        /// <param name="sessionStart">Used to set the EpochNanos property of the TelemetrySamples.</param>
        /// <returns></returns>
        public static TelemetrySamples GenerateSamples(int sampleCount, DateTime sessionStart)
        {
            var vcarSamples = new TelemetryParameterSamples()
            {
                EpochNanos      = sessionStart.ToTelemetryTime(),
                TimestampsNanos = new long[sampleCount],
                Values          = new double[sampleCount]
            };

            var gearSamples = new TelemetryParameterSamples()
            {
                EpochNanos      = sessionStart.ToTelemetryTime(),
                TimestampsNanos = new long[sampleCount],
                Values          = new double[sampleCount]
            };

            var randomRangeWalker = new RandomRangeWalker(0, 1); // Used to generated random data

            for (int i = 0; i < sampleCount; i++)
            {
                var nextSample = randomRangeWalker.GetNext();

                // each data has own timestamps, frequencies
                vcarSamples.TimestampsNanos[i] = i * Interval;
                vcarSamples.Values[i]          = nextSample * 300;
                gearSamples.TimestampsNanos[i] = i * Interval;
                gearSamples.Values[i]          = nextSample;
            }

            var max    = vcarSamples.Values.Max();
            var modVal = max / 7 + 1; // Assuming a car has 8 gears, we are splitting the samples to 8 equal ranges and adding 1 to it, so it will be 1 .. 8

            for (int i = 0; i < sampleCount; i++)
            {
                gearSamples.TimestampsNanos[i] = vcarSamples.TimestampsNanos[i];
                gearSamples.Values[i]          = Math.Round(vcarSamples.Values[i] / modVal);
            }
            var data = new TelemetrySamples()
            {
                Parameters = new Dictionary <string, TelemetryParameterSamples>()
                {
                    { VcarParameterId, vcarSamples },
                    { GearParameterId, gearSamples } // If you had more samples to send for other parameters, this is where you would add them
                }
            };

            return(data);
        }