private IEnumerable <View> GetViews(StreamWriter logWriter, StreamWriter anslog) { RandomizedQueue <StudyTestPair> usedPairs = new RandomizedQueue <StudyTestPair>(); var stimulusPairs = new RandomizedQueue <StudyTestPair>(); stimulusPairs.AddRange(this.stp); while (stimulusPairs.Count > 0) { StudyTestPair currstp = stimulusPairs.RemoveRandom(); usedPairs.Add(currstp); foreach (var view in RunTrial(currstp.test, currstp.answer, currstp.index, logWriter, anslog)) { yield return(view); } } stimulusPairs.AddRange(usedPairs); }
private IEnumerable <View> GetViews(ISynchronizeInvoke invoker, StreamWriter anslog, StreamWriter logWriter, StreamWriter dataWriter, int round, RandomizedQueue <string> pres) { var currentTrialEntries = new List <EEGDataEntry>(); //To do: Save the date/time earlier and use it for both this and the dataWriter. Put it in GetEnumerator and pass to GetViews using (var artifactListener = new EEGDataListener(invoker, null, data => { foreach (var entry in data) { if (entry.HasStimulusMarker()) { lock (currentTrialEntries) { currentTrialEntries.Add(entry); } } } }, null)) { this.dataSource.AddListener(artifactListener); //DIFFERENCE: Instead of getting blocks, we want to go through the entire set once for each test phase, but we //want items within that set to be random RandomizedQueue <StudyTestPair> usedPairs = new RandomizedQueue <StudyTestPair>(); var stimulusPairs = new RandomizedQueue <StudyTestPair>(); stimulusPairs.AddRange(this.stp); while (stimulusPairs.Count > 0) { StudyTestPair currstp = stimulusPairs.RemoveRandom(); usedPairs.Add(currstp); //logWriter.WriteLine("Question: " + currstp.index); foreach (var view in RunTrial(round, currstp.test, currstp.answer, currstp.index, dataWriter, logWriter, anslog, currentTrialEntries, pres)) { yield return(view); } } stimulusPairs.AddRange(usedPairs); } }
/// <summary> /// The enumerator implementation /// </summary> public override IEnumerator <View> GetEnumerator() { IViewResult result; Random numgen = new Random(); int a, b; RandomizedQueue <string> pres = new RandomizedQueue <string>(); RandomizedQueue <string> usedPres = new RandomizedQueue <string>(); pres.AddRange(presentation); using (var logWriter = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "krmon_log_" + settings.SubjectName + "_" + DateTime.Now.ToString("MM dd yyyy H mm ss") + ".txt"))) using (var anslog = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "krmon_anslog_" + settings.SubjectName + "_" + DateTime.Now.ToString("MM dd yyyy H mm ss") + ".txt"))) using (var dataWriter = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "krmon_data_" + settings.SubjectName + "_" + DateTime.Now.ToString("MM dd yyyy H mm ss") + ".csv"))) { //Alternating Study and Test Phases for (int i = 0; i < settings.NumRounds; i++) { yield return(new ChoiceView(new string[] { "Start Study Phase" }, out result) { Text = "Click When Ready" }); while (pres.Count > 0) { var stimulus = pres.RemoveRandom(); yield return(new TextView(stimulus, this.settings.PresentationTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); yield return(new RestView(this.settings.RestTime)); usedPres.Add(stimulus); } pres.AddRange(usedPres); usedPres.Clear(); a = numgen.Next(4, 13); b = numgen.Next(4, 13); yield return(new VocabView(string.Format("{0} x {1} = {2}", a, b, a * b), "Verify", settings.DisplayTime, settings.DelayTime, true, anslog, out result)); yield return(new ChoiceView(new string[] { "Start Test Phase" }, out result) { Text = "Click When Ready" }); var connected = true; // assume it's connected using (var invoker = new SingleThreadedInvoker()) using (var connectionListener = new EEGDataListener(invoker, s => connected = true, null, s => connected = false)) { // listen for a broken connection this.dataSource.AddListener(connectionListener); foreach (var view in this.GetViews(invoker, anslog, logWriter, dataWriter, i, pres)) { if (connected) { yield return(view); } else { GUIUtils.Alert("Lost connection to headset!"); break; } } this.dataSource.RemoveListener(connectionListener); } } } }
/// <summary> /// The enumerator implementation /// </summary> public override IEnumerator <View> GetEnumerator() { IViewResult result; Random numgen = new Random(); RandomizedQueue <StudyTestPair> study = new RandomizedQueue <StudyTestPair>(); RandomizedQueue <StudyTestPair> quiz = new RandomizedQueue <StudyTestPair>(); RandomizedQueue <StudyTestPair> done = new RandomizedQueue <StudyTestPair>(); string filename = "adapt_data_" + settings.SubjectName + "_" + DateTime.Now.ToString("MM dd yyyy H mm ss") + ".csv"; using (var logWriter = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "adapt_log_" + settings.SubjectName + "_" + DateTime.Now.ToString("MM dd yyyy H mm ss") + ".txt"))) //If using MATLAB reference, the datawriter path must match the location of your MATLAB code using (var dataWriter = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), filename))) { yield return(new ChoiceView(new string[] { "Ready for Training Study Phase" }, out result)); //Present competition stimuli for study for (int j = 0; j < presentation.Count; j++) { yield return(new TextView(presentation[j], this.settings.PresentationTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); yield return(new RestView(this.settings.RestTime)); } //Begin the practice phase yield return(new ChoiceView(new string[] { "Start Training EEG Recording" }, out result) { Text = "Click When Ready" }); var compconnected = true; // assume it's connected using (var compinvoker = new SingleThreadedInvoker()) using (var compconnectionListener = new EEGDataListener(compinvoker, s => compconnected = true, null, s => compconnected = false)) { // listen for a broken connection this.dataSource.AddListener(compconnectionListener); foreach (var view in this.GetCompViews(compinvoker, logWriter, dataWriter)) { if (compconnected) { yield return(view); } else { GUIUtils.Alert("Lost connection to headset!"); break; } } this.dataSource.RemoveListener(compconnectionListener); } //Check that the person has sufficient training data if (numArt1 > 24 || numArt2 > 24) { yield return(new TextView("Error: Weeping Angel", settings.InstructionTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); } //MATLAB REFERENCE //matlab.Execute("cd c:\\Users\\Nicole\\Documents\\Matlab\\Thesis\\Adapt"); //matlab.Execute("classifier = wekacomptrain('"+ filename + "');"); yield return(new ChoiceView(new string[] { "Start Study Phase" }, out result) { Text = "Click When Ready" }); while (pres.Count > 0) { var stimulus = pres.RemoveRandom(); yield return(new TextView(stimulus.test + "\n" + stimulus.answer, this.settings.PresentationTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); yield return(new RestView(this.settings.RestTime)); quiz.Add(stimulus); } yield return(new ChoiceView(new string[] { "Start Test Phase" }, out result) { Text = "Click When Ready" }); var connected = true; // assume it's connected using (var invoker = new SingleThreadedInvoker()) using (var connectionListener = new EEGDataListener(invoker, s => connected = true, null, s => connected = false)) { // listen for a broken connection this.dataSource.AddListener(connectionListener); foreach (var view in this.GetViews(invoker, logWriter, dataWriter, study, quiz, done, numgen)) { if (connected) { yield return(view); } else { GUIUtils.Alert("Lost connection to headset!"); break; } } this.dataSource.RemoveListener(connectionListener); } } }
private IEnumerable <View> GetViews(ISynchronizeInvoke invoker, StreamWriter logWriter, StreamWriter dataWriter, RandomizedQueue <StudyTestPair> study, RandomizedQueue <StudyTestPair> quiz, RandomizedQueue <StudyTestPair> done, Random numgen) { var currentTrialEntries = new List <EEGDataEntry>(); using (var artifactListener = new EEGDataListener(invoker, null, data => { foreach (var entry in data) { if (entry.HasStimulusMarker()) { lock (currentTrialEntries) { currentTrialEntries.Add(entry); } } } }, null)) { this.dataSource.AddListener(artifactListener); for (int index = 0; index < settings.NumRounds; index++) { double rand = numgen.NextDouble(); StudyTestPair stim; if (rand < .39) { if (!study.IsEmpty()) { stim = study.RemoveRandom(); quiz.Add(stim); logWriter.WriteLine("5"); logWriter.WriteLine(stim.test + "\\n" + stim.answer); yield return(new RestView(this.settings.BlinkTime)); yield return(new TextView(stim.test + "\n" + stim.answer, this.settings.PresentationTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); } else if (!quiz.IsEmpty()) { stim = quiz.RemoveRandom(); logWriter.WriteLine("7"); logWriter.WriteLine(stim.test); logWriter.WriteLine(stim.answer); foreach (var view in RunTrial(index, stim, dataWriter, logWriter, currentTrialEntries, study, quiz, done)) { yield return(view); } } else { stim = done.RemoveRandom(); logWriter.WriteLine("7"); logWriter.WriteLine(stim.test); logWriter.WriteLine(stim.answer); foreach (var view in RunTrial(index, stim, dataWriter, logWriter, currentTrialEntries, study, quiz, done)) { yield return(view); } } } else if (rand < .99) { if (!quiz.IsEmpty()) { stim = quiz.RemoveRandom(); logWriter.WriteLine("7"); logWriter.WriteLine(stim.test); logWriter.WriteLine(stim.answer); foreach (var view in RunTrial(index, stim, dataWriter, logWriter, currentTrialEntries, study, quiz, done)) { yield return(view); } } else if (!study.IsEmpty()) { stim = study.RemoveRandom(); quiz.Add(stim); logWriter.WriteLine("5"); logWriter.WriteLine(stim.test + "\\n" + stim.answer); yield return(new RestView(this.settings.BlinkTime)); yield return(new TextView(stim.test + "\n" + stim.answer, this.settings.PresentationTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); } else { stim = done.RemoveRandom(); logWriter.WriteLine("7"); logWriter.WriteLine(stim.test); logWriter.WriteLine(stim.answer); foreach (var view in RunTrial(index, stim, dataWriter, logWriter, currentTrialEntries, study, quiz, done)) { yield return(view); } } } else { if (!done.IsEmpty()) { stim = done.RemoveRandom(); logWriter.WriteLine("7"); logWriter.WriteLine(stim.test); logWriter.WriteLine(stim.answer); foreach (var view in RunTrial(index, stim, dataWriter, logWriter, currentTrialEntries, study, quiz, done)) { yield return(view); } } else if (!quiz.IsEmpty()) { stim = quiz.RemoveRandom(); logWriter.WriteLine("7"); logWriter.WriteLine(stim.test); logWriter.WriteLine(stim.answer); foreach (var view in RunTrial(index, stim, dataWriter, logWriter, currentTrialEntries, study, quiz, done)) { yield return(view); } } else { stim = study.RemoveRandom(); quiz.Add(stim); logWriter.WriteLine("5"); logWriter.WriteLine(stim.test + "\\n" + stim.answer); yield return(new RestView(this.settings.BlinkTime)); yield return(new TextView(stim.test + "\n" + stim.answer, this.settings.PresentationTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); } } } } }
/// <summary> /// The enumerator implementation /// </summary> public override IEnumerator <View> GetEnumerator() { IViewResult result; yield return(new ChoiceView(new string[] { "Start Training Phase" }, out result) { Text = "Click When Ready" }); for (int j = 0; j < comp.Count; j++) { yield return(new TextView(comp[j], settings.PresentationTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); yield return(new RestView(settings.RestTime)); } yield return(new ChoiceView(new string[] { "Begin Testing" }, out result) { Text = "Click When Ready" }); //Display each block of stimuli for (int j = 0; j < (settings.NumBlocks * 2); j++) { int limit = blocks[j].Count; for (int k = 0; k < limit; k++) { //Rest yield return(new RestView(this.settings.BlinkTime)); //Fixate yield return(new FixationView(this.settings.FixationTime)); var stimulus = blocks[j].RemoveRandom(); //Generate stimulus view yield return(new TextView(stimulus, settings.PresentationTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); yield return(new TextView(stimulus + "*", settings.PresentationTime / 2, GUIUtils.Constants.DISPLAY_FONT_LARGE)); } yield return(new ChoiceView(new string[] { "Ready for next block" }, out result)); } RandomizedQueue <string> pres = new RandomizedQueue <string>(); RandomizedQueue <string> usedPres = new RandomizedQueue <string>(); RandomizedQueue <StudyTestPair> studySoon = new RandomizedQueue <StudyTestPair>(); RandomizedQueue <StudyTestPair> testSoon = new RandomizedQueue <StudyTestPair>(); RandomizedQueue <StudyTestPair> testLate = new RandomizedQueue <StudyTestPair>(); pres.AddRange(presentation); testSoon.AddRange(stp); yield return(new ChoiceView(new string[] { "Start Initial Study Phase" }, out result) { Text = "Click When Ready" }); while (pres.Count > 0) { var stimulus = pres.RemoveRandom(); yield return(new TextView(stimulus, this.settings.PresentationTime, GUIUtils.Constants.DISPLAY_FONT_LARGE)); yield return(new RestView(this.settings.RestTime)); usedPres.Add(stimulus); } pres.AddRange(usedPres); using (var logWriterV = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "userctrl_logv_" + settings.SubjectName + "_" + DateTime.Now.ToString("MM dd yyyy H mm ss") + ".txt"))) using (var logWriter = new StreamWriter(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "userctrl_log_" + settings.SubjectName + "_" + DateTime.Now.ToString("MM dd yyyy H mm ss") + ".csv"))) { yield return(new ChoiceView(new string[] { "Start Practice Phase" }, out result) { Text = "Click When Ready" }); using (var invoker = new SingleThreadedInvoker()) { foreach (var view in this.GetViews(invoker, logWriterV, logWriter, studySoon, testSoon, testLate)) { yield return(view); } } } }
private IEnumerable <View> GetViews(ISynchronizeInvoke invoker, StreamWriter logWriterV, StreamWriter logWriter, RandomizedQueue <StudyTestPair> studySoon, RandomizedQueue <StudyTestPair> testSoon, RandomizedQueue <StudyTestPair> testLate) { //Presents stimuli from the three categories randomly with set probabilities Random numgen = new Random(); for (int index = 0; index < settings.NumTrials; index++) { double choice = numgen.NextDouble(); if (choice < 0.01) { if (!testLate.IsEmpty()) { StudyTestPair currstp = testLate.RemoveRandom(); logWriterV.WriteLine("Question: " + currstp.test); logWriterV.WriteLine("Correct Answer: " + currstp.answer); foreach (var view in RunTrial(index, false, currstp, logWriter, logWriterV, studySoon, testSoon, testLate)) { yield return(view); } } else if (!studySoon.IsEmpty()) { StudyTestPair study = studySoon.RemoveRandom(); logWriterV.WriteLine("Study Trial"); logWriterV.WriteLine(study.test); logWriterV.WriteLine(study.answer); foreach (var view in RunTrial(index, true, study, logWriter, logWriterV, studySoon, testSoon, testLate)) { yield return(view); } } else { StudyTestPair currstp = testSoon.RemoveRandom(); logWriterV.WriteLine("Question: " + currstp.test); logWriterV.WriteLine("Correct Answer: " + currstp.answer); foreach (var view in RunTrial(index, false, currstp, logWriter, logWriterV, studySoon, testSoon, testLate)) { yield return(view); } } } else if (choice < 0.4) { if (!studySoon.IsEmpty()) { StudyTestPair study = studySoon.RemoveRandom(); logWriterV.WriteLine("Study Trial"); logWriterV.WriteLine(study.test); logWriterV.WriteLine(study.answer); foreach (var view in RunTrial(index, true, study, logWriter, logWriterV, studySoon, testSoon, testLate)) { yield return(view); } } else if (!testSoon.IsEmpty()) { StudyTestPair currstp = testSoon.RemoveRandom(); logWriterV.WriteLine("Question: " + currstp.test); logWriterV.WriteLine("Correct Answer: " + currstp.answer); foreach (var view in RunTrial(index, false, currstp, logWriter, logWriterV, studySoon, testSoon, testLate)) { yield return(view); } } else { StudyTestPair currstp = testLate.RemoveRandom(); logWriterV.WriteLine("Question: " + currstp.test); logWriterV.WriteLine("Correct Answer: " + currstp.answer); foreach (var view in RunTrial(index, false, currstp, logWriter, logWriterV, studySoon, testSoon, testLate)) { yield return(view); } } } else { if (!testSoon.IsEmpty()) { StudyTestPair currstp = testSoon.RemoveRandom(); logWriterV.WriteLine("Question: " + currstp.test); logWriterV.WriteLine("Correct Answer: " + currstp.answer); foreach (var view in RunTrial(index, false, currstp, logWriter, logWriterV, studySoon, testSoon, testLate)) { yield return(view); } } else if (!studySoon.IsEmpty()) { StudyTestPair study = studySoon.RemoveRandom(); logWriterV.WriteLine("Study Trial"); logWriterV.WriteLine(study.test); logWriterV.WriteLine(study.answer); foreach (var view in RunTrial(index, true, study, logWriter, logWriterV, studySoon, testSoon, testLate)) { yield return(view); } } else { StudyTestPair currstp = testLate.RemoveRandom(); logWriterV.WriteLine("Question: " + currstp.test); logWriterV.WriteLine("Correct Answer: " + currstp.answer); foreach (var view in RunTrial(index, false, currstp, logWriter, logWriterV, studySoon, testSoon, testLate)) { yield return(view); } } } } }