public void TestEventTimeHistorian() { IRandomChannel irc = m_rs.GetRandomChannel(); IExecutive exec = ExecFactory.Instance.CreateExecutive(); EventTimeHistorian myHistorian = new EventTimeHistorian(exec, 256); DateTime when = m_startDate; // We set up NUM_SAMPLES events with random (0->50) minute intervals. TimeSpan totalTimeSpan = TimeSpan.Zero; for (int i = 0; i < NUM_SAMPLES; i++) { exec.RequestEvent(DoEvent, when, 0.0, myHistorian, ExecEventType.Synchronous); double d = irc.NextDouble(); TimeSpan delta = TimeSpan.FromMinutes(d * 50.0); totalTimeSpan += delta; if (i < 30) { Console.WriteLine("Delta #" + i + ", " + delta.ToString()); } when += delta; } m_actualAverage = TimeSpan.FromTicks(totalTimeSpan.Ticks / NUM_SAMPLES); Console.WriteLine("Average timeSpan was " + m_actualAverage + "."); exec.Start(); Console.WriteLine("After {0} events, the average interval was {1}.", myHistorian.PastEventsReceived, myHistorian.GetAverageIntraEventDuration()); }
private void DoEvent(IExecutive exec, object userData) { EventTimeHistorian eth = ((EventTimeHistorian)userData); eth.LogEvent(); if (exec.Now > m_startDate) { m_numExecEventsFired++; TimeSpan aied = eth.GetAverageIntraEventDuration(); m_accumulatedDeviation += (m_actualAverage - aied); Console.WriteLine( "Average interval = " + aied + ", Average deviation = " + TimeSpan.FromTicks(m_accumulatedDeviation.Ticks / m_numExecEventsFired).TotalMinutes); } }