/// <summary> /// Generates random Events. /// </summary> /// <param name="EventsCount">The events count we want to generate.</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 List <Event> GenerateEvents(int eventsCount, DateTime sessionStart) { var interval = (long)(100000); // interval in nanoseconds between events var randomRangeWalker = new RandomRangeWalker(0, 1); // Used to generated random data var events = new List <Event>(); var timestamp = sessionStart.ToTelemetryTime(); for (int i = 0; i < eventsCount; i++) { var nextValue = randomRangeWalker.GetNext(); var @event = new Event { Id = EventId, Values = new[] { nextValue }, EpochNanos = sessionStart.ToTelemetryTime(), TimeNanos = timestamp }; events.Add(@event); timestamp += interval; } return(events); }
/// <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 var timestamp = sessionStart.ToTelemetryTime(); for (int i = 0; i < sampleCount; i++) { var nextData = randomRangeWalker.GetNext(); data.TimestampsNanos[i] = timestamp; // 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; timestamp += Interval; } 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); }
private void GenerateData(IOutputTopic topic, DataFormatClient dataFormatClient, string dataFormatId, string atlasConfigurationId) { const int steps = 12000; const int delay = (int)(1000 / Frequency); var random = new Random(); var start = DateTime.UtcNow; var epoch = start.ToTelemetryTime(); var output = new SessionTelemetryDataOutput(topic, dataFormatId, dataFormatClient); var outputFeed = output.DataOutput.BindDefaultFeed(); // declare a session output.SessionOutput.AddSessionDependency(DependencyTypes.DataFormat, dataFormatId); output.SessionOutput.AddSessionDependency(DependencyTypes.AtlasConfiguration, atlasConfigurationId); output.SessionOutput.SessionState = StreamSessionState.Open; output.SessionOutput.SessionStart = start.Date; output.SessionOutput.SessionIdentifier = "random_walk"; output.SessionOutput.SendSession(); // generate data points var data = outputFeed.MakeTelemetryData(1000000, epoch); var param = data.Parameters[0]; var rangeWalker = new RandomRangeWalker(0, 1); for (var step = 1; step <= steps; step++) { Thread.Sleep(delay); for (var i = 0; i < 1000000; i++) { // writing a single data point for simplicity, but you can send chunks of data // timestamps expressed in ns since the epoch (which is the start of the session) var elapsedNs = step * delay * 1000000L; data.TimestampsNanos[i] = elapsedNs; param.Statuses[i] = DataStatus.Sample; var value = rangeWalker.GetNext(); param.AvgValues[i] = value; output.SessionOutput.SessionDurationNanos = elapsedNs; //Logger.Info(NumberToBarString.Convert(value)); } outputFeed.EnqueueAndSendData(data); } output.SessionOutput.SessionState = StreamSessionState.Closed; output.SessionOutput.SendSession(); }