public IEnumerable <View> RunTrial(string stimulus, int cls, StreamWriter dataWriter, StreamWriter logWriter, List <EEGDataEntry> currentTrialEntries) { //Rest yield return(new RestView(this.settings.BlinkTime)); //Fixate yield return(new FixationView(this.settings.FixationTime)); //Generate stimulus view var stimulusView = new TextView(stimulus, this.settings.DisplayTime, GUIUtils.Constants.DISPLAY_FONT_LARGE); stimulusView.DoOnDeploy(c => this.dataSource.Marker = cls); bool needToRerun = false; //HERE IT IS bool feedback = true; //If there was a motion artifact, we need to rerun the trial with a different stimulus from the same class stimulusView.DoOnFinishing(() => { this.dataSource.Marker = EEGDataEntry.MARKER_DEFAULT; lock (currentTrialEntries) { if (this.settings.ArtifactDetectionSettings.HasMotionArtifact(currentTrialEntries)) { logWriter.WriteLine("Motion Artifact Detected"); needToRerun = true; } else { if (this.settings.SaveTrialData) { foreach (var entry in currentTrialEntries) { dataWriter.WriteLine(entry); } } } currentTrialEntries.Clear(); } }); logWriter.WriteLine(stimulus); yield return(stimulusView); yield return(new TextView(stimulus + "*", settings.SpeakTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); //Rerun if needed if (needToRerun && feedback) { yield return(new TextView("You moved!", 1000, GUIUtils.Constants.DISPLAY_FONT_LARGE)); } //{ // var stimulusClass = (cls == 1) ? this.class1 : this.class2; // var stim = stimulusClass.Shuffled().First(s => s != stimulus); // foreach (var view in RunTrial(stim, cls, dataWriter, logWriter, currentTrialEntries)) // { // yield return view; // } //} }
public IEnumerable <View> RunCompTrial(string stimulus, int cls, StreamWriter dataWriter, StreamWriter logWriter, List <EEGDataEntry> currentTrialEntries) { //Rest yield return(new RestView(this.settings.BlinkTime)); //Fixate yield return(new FixationView(this.settings.FixationTime)); //Generate stimulus view var stimulusView = new TextView(stimulus, this.settings.DisplayTime, GUIUtils.Constants.DISPLAY_FONT_LARGE); stimulusView.DoOnDeploy(c => this.dataSource.Marker = cls); bool needToRerun = false; stimulusView.DoOnFinishing(() => { this.dataSource.Marker = EEGDataEntry.MARKER_DEFAULT; lock (currentTrialEntries) { if (this.settings.ArtifactDetectionSettings.HasMotionArtifact(currentTrialEntries)) { logWriter.WriteLine("Motion Artifact Detected"); needToRerun = true; } else { if (this.settings.SaveTrialData) { foreach (var entry in currentTrialEntries) { dataWriter.WriteLine(entry); } } //Add training trials to the classifier classifier.AddTrial(currentTrialEntries.AsIArray()); } currentTrialEntries.Clear(); } }); logWriter.WriteLine(stimulus); yield return(stimulusView); yield return(new TextView(stimulus + "*", settings.SpeakTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); //Check number of artifacts if (needToRerun) { if (cls == 1) { numArt1++; } if (cls == 2) { numArt2++; } numArt++; } if (numArt > 12) { numArt = 0; yield return(new TextView("Please keep face movements to a minimum", settings.InstructionTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); } }