本文整理汇总了C#中Controller.EnqueueEpoch方法的典型用法代码示例。如果您正苦于以下问题:C# Controller.EnqueueEpoch方法的具体用法?C# Controller.EnqueueEpoch怎么用?C# Controller.EnqueueEpoch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Controller
的用法示例。
在下文中一共展示了Controller.EnqueueEpoch方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OutputPipelineContinuity
public void OutputPipelineContinuity(
[Values(1000, 5000, 10000, 15000, 20000)] double sampleRate,
[Values(0.1, 0.5, 1, 5)] double blockDurationSeconds
)
{
const double epochDuration = 2; //seconds
var srate = new Measurement((decimal) sampleRate, "Hz");
var daq = new TestDAQController();
var outStream = new DAQOutputStream("OUT")
{
SampleRate = srate,
MeasurementConversionTarget = "V"
};
var inStream = new DAQInputStream("IN")
{
SampleRate = srate,
MeasurementConversionTarget = "V"
};
var controller = new Controller() { Clock = daq, DAQController = daq };
var dev = new UnitConvertingExternalDevice("dev", "co", controller, new Measurement(0, "V"))
{
Clock = daq,
MeasurementConversionTarget = "V",
OutputSampleRate = srate,
InputSampleRate = srate
};
dev.BindStream(outStream).BindStream(inStream);
// Setup Epoch
var e = new Epoch("OutputPipelineContinuity");
var nSamples = (int)TimeSpan.FromSeconds(epochDuration).Samples(srate);
IList<IMeasurement> stimData = (IList<IMeasurement>) Enumerable.Range(0, nSamples)
.Select(i => new Measurement((decimal) (8 * Math.Sin(((double)i) / (nSamples / 10.0))), "V") as IMeasurement)
.ToList();
IOutputData stimOutputData = new OutputData(stimData, srate);
var stim = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) new Dictionary<string, object>(),
stimOutputData);
e.Stimuli[dev] = stim;
e.Responses[dev] = new Response();
e.Backgrounds[dev] = new Background(new Measurement(0, "V"), srate);
controller.EnqueueEpoch(e);
var blockSpan = TimeSpan.FromSeconds(blockDurationSeconds);
foreach (var stimBlock in stim.DataBlocks(blockSpan))
{
var cons = stimOutputData.SplitData(blockSpan);
var expected = cons.Head.Data;
stimOutputData = cons.Rest;
Assert.That(stimBlock.Data, Is.EqualTo(expected));
}
}
示例2: ShouldTruncateResponseAtEpochBoundary
public void ShouldTruncateResponseAtEpochBoundary()
{
var c = new Controller();
var e = new Epoch(UNUSED_PROTOCOL);
var dev1 = new UnitConvertingExternalDevice("dev2", "co", c, new Measurement(0, "V"));
var sampleRate = new Measurement(1, "Hz");
var samples = new List<IMeasurement> { new Measurement(1, "V"), new Measurement(2, "V"), new Measurement(3, "V") };
var data = new OutputData(samples,
sampleRate, true);
e.Stimuli[dev1] = new RenderedStimulus((string) "ID1",
(IDictionary<string, object>) new Dictionary<string, object>(),
(IOutputData) data);
e.Responses[dev1] = new Response();
c.EnqueueEpoch(e);
c.NextEpoch();
c.PushInputData(dev1, new InputData(samples.Concat(samples).ToList(),
sampleRate,
DateTimeOffset.Now)
.DataWithStreamConfiguration(streamFake, new Dictionary<string, object>())
.DataWithExternalDeviceConfiguration(devFake, new Dictionary<string, object>()));
Assert.That(((TimeSpan)e.Responses[dev1].Duration), Is.EqualTo((TimeSpan)e.Duration));
}
示例3: PullsOutputData
public void PullsOutputData()
{
var c = new Controller();
IExternalDevice dev = new UnitConvertingExternalDevice(UNUSED_DEVICE_NAME, UNUSED_DEVICE_MANUFACTURER, c, UNUSED_BACKGROUND);
const int srate = 1000;
IList<IMeasurement> data = (IList<IMeasurement>) Enumerable.Range(0, srate * 2).Select(i => new Measurement(i, "V") as IMeasurement).ToList();
var sampleRate = new Measurement(srate, "Hz");
IOutputData data1 = new OutputData(data, sampleRate, false);
var e = new Epoch("");
e.Stimuli[dev] = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) new Dictionary<string, object>(),
data1);
e.Background[dev] = new Epoch.EpochBackground(new Measurement(0, "V"), sampleRate);
c.EnqueueEpoch(e);
TimeSpan d1 = TimeSpan.FromSeconds(0.75);
c.EnqueueEpoch(e);
c.NextEpoch();
var pull1 = c.PullOutputData(dev, d1);
var pull2 = c.PullOutputData(dev, d1);
var samples = (int)d1.Samples(new Measurement(srate, "Hz"));
Assert.AreEqual(data.Take(samples).ToList(),
pull1.Data);
Assert.AreEqual(data.Skip(samples).Take(samples).ToList(),
pull2.Data);
var pull3 = c.PullOutputData(dev, d1);
Assert.AreEqual(data.Skip(2 * samples)
.Take(samples)
.Concat(Enumerable.Range(0, srate - samples).Select(i => e.Background[dev].Background))
.ToList(),
pull3.Data);
}
示例4: ShouldSupplyEpochBackgroundForExternalDevicesWithoutStimuli
public void ShouldSupplyEpochBackgroundForExternalDevicesWithoutStimuli()
{
var c = new Controller();
var dev1 = new UnitConvertingExternalDevice("dev1", "co", c, new Measurement(0, "V"));
var dev2 = new UnitConvertingExternalDevice("dev2", "co", c, new Measurement(0, "V"));
int baseSamples = 1000;
IList<IMeasurement> data = (IList<IMeasurement>)Enumerable.Range(0, baseSamples)
.Select(i => new Measurement(i, "V") as IMeasurement)
.ToList();
Measurement sampleRate = new Measurement(baseSamples, "Hz");
var config = new Dictionary<string, object>();
IOutputData data1 = new OutputData(data, sampleRate, true);
var e = new Epoch("");
e.Stimuli[dev1] = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) config, data1);
var backgroundMeasurement = new Measurement(3.2m, "V");
e.Background[dev2] = new Epoch.EpochBackground(backgroundMeasurement, sampleRate);
c.EnqueueEpoch(e);
c.NextEpoch();
var out1 = c.PullOutputData(dev1, e.Duration);
Assert.NotNull(out1);
var out2 = c.PullOutputData(dev2, e.Duration);
Assert.NotNull(out2);
Assert.AreEqual((TimeSpan)e.Duration, out2.Duration);
Assert.AreEqual(backgroundMeasurement, out2.Data.First());
}
示例5: NextEpochThrowsIfCannotDequeue
public void NextEpochThrowsIfCannotDequeue()
{
var c = new Controller();
var e = new Epoch(UNUSED_PROTOCOL);
var dev1 = new UnitConvertingExternalDevice("dev2", "co", c, new Measurement(0, "V"));
var sampleRate = new Measurement(1, "Hz");
var samples = new List<IMeasurement> { new Measurement(1, "V"), new Measurement(2, "V"), new Measurement(3, "V") };
var data = new OutputData(samples,
sampleRate, true);
e.Stimuli[dev1] = new RenderedStimulus((string) "ID1",
(IDictionary<string, object>) new Dictionary<string, object>(),
(IOutputData) data);
e.Responses[dev1] = new Response();
c.EnqueueEpoch(e);
c.NextEpoch();
Assert.Throws<SymphonyControllerException>(() => c.NextEpoch());
}
示例6: NextEpochShouldFireNextEpochEvent
public void NextEpochShouldFireNextEpochEvent()
{
var c = new Controller();
c.Clock = new FakeClock();
var e = new Epoch(UNUSED_PROTOCOL);
var dev1 = new UnitConvertingExternalDevice("dev2", "co", c, new Measurement(0, "V"));
var sampleRate = new Measurement(1, "Hz");
var samples = new List<IMeasurement> { new Measurement(1, "V"), new Measurement(2, "V"), new Measurement(3, "V") };
var data = new OutputData(samples,
sampleRate, true);
e.Stimuli[dev1] = new RenderedStimulus((string) "ID1",
(IDictionary<string, object>) new Dictionary<string, object>(),
(IOutputData) data);
e.Responses[dev1] = new Response();
c.EnqueueEpoch(e);
bool evt = false;
c.NextEpochRequested += (sender, args) => evt = true;
c.NextEpoch();
Assert.True(evt);
}
示例7: NexEpochShouldDequeueEpoch
public void NexEpochShouldDequeueEpoch()
{
var c = new Controller();
var e = new Epoch(UNUSED_PROTOCOL);
var dev1 = new UnitConvertingExternalDevice("dev2", "co", c, new Measurement(0, "V"));
var sampleRate = new Measurement(1, "Hz");
var samples = new List<IMeasurement> { new Measurement(1, "V"), new Measurement(2, "V"), new Measurement(3, "V") };
var data = new OutputData(samples,
sampleRate, true);
e.Stimuli[dev1] = new RenderedStimulus((string) "ID1",
(IDictionary<string, object>) new Dictionary<string, object>(),
(IOutputData) data);
e.Responses[dev1] = new Response();
c.EnqueueEpoch(e);
Assert.That(c.CurrentEpoch, Is.Null);
c.NextEpoch();
Assert.That(c.CurrentEpoch, Is.EqualTo(e));
}
示例8: ContinuousAcquisition
public void ContinuousAcquisition(
[Values(1000, 10000, 20000, 50000)] double sampleRate,
[Values(20)] int nEpochs)
{
Converters.Clear();
HekaDAQInputStream.RegisterConverters();
HekaDAQOutputStream.RegisterConverters();
Assert.That(HekaDAQController.AvailableControllers().Count(), Is.GreaterThan(0));
foreach (var daq in HekaDAQController.AvailableControllers())
{
const double epochDuration = 1; //s
try
{
daq.InitHardware();
daq.SampleRate = new Measurement((decimal)sampleRate, "Hz");
var controller = new Controller { Clock = daq.Clock, DAQController = daq };
var dev0 = new UnitConvertingExternalDevice("Device0", "Manufacturer", controller, new Measurement(0, "V"))
{
MeasurementConversionTarget = "V",
Clock = daq.Clock,
OutputSampleRate = daq.SampleRate,
InputSampleRate = daq.SampleRate
};
dev0.BindStream((IDAQOutputStream)daq.GetStreams("ao0").First());
dev0.BindStream((IDAQInputStream)daq.GetStreams("ai0").First());
var dev1 = new UnitConvertingExternalDevice("Device1", "Manufacturer", controller, new Measurement(0, "V"))
{
MeasurementConversionTarget = "V",
Clock = daq.Clock,
OutputSampleRate = daq.SampleRate,
InputSampleRate = daq.SampleRate
};
dev1.BindStream((IDAQOutputStream)daq.GetStreams("ao1").First());
dev1.BindStream((IDAQInputStream)daq.GetStreams("ai1").First());
var nDAQStarts = 0;
daq.Started += (evt, args) =>
{
nDAQStarts++;
};
var completedEpochs = new Queue<Epoch>();
controller.CompletedEpoch += (evt, args) =>
{
completedEpochs.Enqueue(args.Epoch);
if (completedEpochs.Count >= nEpochs)
{
controller.RequestStop();
}
};
var epochs = new Queue<Epoch>();
var nSamples = (int)TimeSpan.FromSeconds(epochDuration).Samples(daq.SampleRate);
// Triangle wave
var data = Enumerable.Range(0, nSamples/2)
.Select(k => new Measurement(k/(nSamples/2.0/10.0), "V") as IMeasurement)
.ToList();
var stimData = data.Concat(Enumerable.Reverse(data)).ToList();
var fakeEpochPersistor = new FakeEpochPersistor();
bool start = true;
for (int j = 0; j < nEpochs; j++)
{
var e = new Epoch("HekaIntegration" + j);
e.Stimuli[dev0] = new RenderedStimulus("Stim",
new Dictionary<string, object>(),
new OutputData(stimData, daq.SampleRate));
e.Responses[dev0] = new Response();
e.SetBackground(dev1, new Measurement(1, "V"), daq.SampleRate);
e.Responses[dev1] = new Response();
epochs.Enqueue(e);
controller.EnqueueEpoch(e);
if (start)
{
controller.StartAsync(fakeEpochPersistor);
start = false;
}
}
while (controller.IsRunning)
{
Thread.Sleep(1);
}
controller.WaitForCompletedEpochTasks();
var stopTime = controller.Clock.Now;
//.........这里部分代码省略.........
示例9: RunEpochThrowsWhenRunningSimultaneousEpochs
public void RunEpochThrowsWhenRunningSimultaneousEpochs()
{
Converters.Register("V", "V",
// just an identity conversion for now, to pass Validate()
(IMeasurement m) => m);
var c = new Controller { DAQController = new SimpleDAQController() };
c.DAQController.Clock = c.DAQController as IClock;
var sampleRate = new Measurement(1, "Hz");
var e = new Epoch(UNUSED_PROTOCOL);
var dev = new UnitConvertingExternalDevice("dev", "co", c, new Measurement(0, "V"))
{
MeasurementConversionTarget = "V",
Clock = c.Clock,
OutputSampleRate = sampleRate
};
var outStream = new DAQOutputStream("out")
{
MeasurementConversionTarget = "V",
Clock = c.Clock
};
dev.BindStream(outStream);
e.Stimuli[dev] = new DelegatedStimulus("ID1", "units", sampleRate, new Dictionary<string, object>(),
(parameters, duration) => null,
objects => Option<TimeSpan>.None());
bool started = false;
c.Started += (evt, args) =>
{
started = true;
};
c.EnqueueEpoch(e);
c.StartAsync(null);
while (!started)
{
Thread.Sleep(1);
}
Assert.That(() => c.RunEpoch(e, new FakeEpochPersistor()), Throws.Exception.TypeOf<SymphonyControllerException>());
}