예제 #1
0
        public IEnumerable <View> RunTrial(int index, bool isStudy, StudyTestPair stp, StreamWriter logWriter,
                                           StreamWriter logWriterV, //List<EEGDataEntry> currentTrialEntries,
                                           RandomizedQueue <StudyTestPair> studySoon,
                                           RandomizedQueue <StudyTestPair> testSoon, RandomizedQueue <StudyTestPair> testLate)
        {
            //yield return new RestView(this.settings.BlinkTime);
            int trialnumber = index + 1;

            yield return(new TextView("Trial number: " + trialnumber, this.settings.BlinkTime, GUIUtils.Constants.DISPLAY_FONT_LARGE));

            yield return(new FixationView(this.settings.FixationTime));

            IViewResult result;
            View        vocabView;

            if (isStudy)
            {
                vocabView = new TextView(stp.test + Environment.NewLine + stp.answer, settings.DisplayTime, GUIUtils.Constants.DISPLAY_FONT_LARGE);
            }
            else
            {
                vocabView = new VocabView(stp.test, stp.answer, settings.DisplayTime, settings.DelayTime, false, out result);
            }

            yield return(vocabView);

            //The user controls which group the stimulus goes into after the trial
            StudyTestPair toAdd = stp; //new StudyTestPair(stp.test, stp.answer, stp.number);

            if (!isStudy)
            {
                yield return(new TextView((bool)vocabView.Result.Value ? "Correct" : "Incorrect", settings.FeedbackTime, GUIUtils.Constants.DISPLAY_FONT_LARGE));

                int toWrite = (bool)vocabView.Result.Value ? 1 : 0;
                logWriter.WriteLine(toAdd.number + ", " + toWrite);
                string[]   options = { "Study Soon", "Test Soon", "Test Later" };
                ChoiceView choice  = new ChoiceView(options);
                yield return(choice);

                if ((string)choice.Result.Value == options[0])
                {
                    studySoon.Add(toAdd);
                }
                else if ((string)choice.Result.Value == options[1])
                {
                    testSoon.Add(toAdd);
                }
                else
                {
                    testLate.Add(toAdd);
                }
                logWriterV.WriteLine("User Answer: " + vocabView.Result.Value);
                logWriterV.WriteLine("User Choice: " + choice.Result.Value);
            }
            else
            {
                testSoon.Add(toAdd);
                logWriterV.WriteLine("Study Trial");
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        /// <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);
                                }
                        }
                    }
        }
예제 #5
0
        /// <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);
                        }
                }
        }
예제 #6
0
        public IEnumerable <View> RunTrial(int index, StudyTestPair stim, StreamWriter dataWriter, StreamWriter logWriter, List <EEGDataEntry> currentTrialEntries,
                                           RandomizedQueue <StudyTestPair> study, RandomizedQueue <StudyTestPair> quiz, RandomizedQueue <StudyTestPair> done)
        {
            yield return(new RestView(this.settings.BlinkTime));

            yield return(new FixationView(this.settings.FixationTime));

            IViewResult result;

            logWriter.WriteLine("Trial: " + index);
            stim.times++;
            var vocabView = new VocabView(stim.test, stim.answer, settings.DisplayTime, settings.DelayTime, false, out result);

            vocabView.DoOnDeploy(c => this.dataSource.Marker = index + 1);
            bool noWrite = false;
            //For MATLAB use.
            //double[] judge = {1};
            //double[] zro = {0};
            //double[] newcomplevel = {-1};
            double confidence = 0;
            int    judge      = 1;
            //TODO: PUT THIS IN THE GUI
            double threshold = .4;

            vocabView.DoOnFinishing(() =>
            {
                this.dataSource.Marker = EEGDataEntry.MARKER_DEFAULT;
                lock (currentTrialEntries)
                {
                    var trialsDuringDelay = currentTrialEntries.Where(e => e.RelativeTimeStamp <= settings.DelayTime);
                    if (this.settings.ArtifactDetectionSettings.HasMotionArtifact(trialsDuringDelay))
                    {
                        noWrite = true;
                        numArtifacts++;
                    }
                    else
                    {
                        int numentries = 0;
                        foreach (var entry in trialsDuringDelay)
                        {
                            if (this.settings.SaveTrialData)
                            {
                                dataWriter.WriteLine(entry + ", {0}", stim.index);
                            }
                            numentries++;
                        }

                        //MATLAB REFERENCE
                        //double[,] data2matlab = new double[numentries,15];
                        //double[,] zeros = new double[numentries,15];
                        //int i = 0;
                        //MATLAB REFERENCE - converting the data to matlab format

                        /*foreach (var entry in trialsDuringDelay)
                         * {
                         *  //data2matlab[i, 0] = entry.RelativeTimeStamp;
                         *  //zeros[i, 0] = 0;
                         *
                         *  //int j = 1;
                         *  //foreach (var set in entry.Data)
                         *  //{
                         *  //    data2matlab[i,j] = set;
                         *  //    zeros[i,j] = 0.0;
                         *  //    j++;
                         *  //}
                         *  //i++;
                         * }*/
                        //MATLAB REFERENCE - perform prediction
                        //matlab.PutFullMatrix("data", "base", data2matlab, zeros);
                        //double[] complev = { stim.complevel };
                        //double[] zero = { 0 };
                        //matlab.PutFullMatrix("rating", "base", complev, zero);
                        //matlab.Execute("cd c:\\Users\\Nicole\\Documents\\Matlab\\Thesis\\Adapt"); //might be unnecessary
                        //matlab.Execute("[result rating] = adaptive(data, false, classifier, rating);");
                        //matlab.GetFullMatrix("result", "base", judge, zro);
                        //matlab.GetFullMatrix("rating", "base", newcomplevel, zro);

                        //The calculation of where to place the item is based on the difference between the 3rd presentation
                        //and the fourth presentation.  If an insufficient drop occurs, the competition level is saved as the
                        //reference competition level until a drop does occur. The pre-drop competition level is saved
                        //so that if the competition goes up in the future the correct judgement can be made.
                        classifier.Predict(trialsDuringDelay.AsIArray(), out confidence);
                        if (stim.times < 4)
                        {
                            stim.complevel = confidence;
                        }
                        else
                        {
                            if (stim.complevel - confidence > threshold)
                            {
                                judge = 1;
                            }
                            else
                            {
                                judge          = 0;
                                stim.complevel = confidence;
                            }
                        }
                    }
                    currentTrialEntries.Clear();
                }
            });
            yield return(vocabView);

            if (!noWrite)
            {
                if ((bool)result.Value)
                {
                    if (judge == 0)
                    {
                        quiz.Add(stim);
                    }
                    else
                    {
                        done.Add(stim);
                    }
                }
                else
                {
                    study.Add(stim);
                }
            }
            else
            {
                if ((bool)result.Value)
                {
                    quiz.Add(stim);
                }
                else
                {
                    study.Add(stim);
                }
            }
            if (numArtifacts > 10)
            {
                numArtifacts = 0;
                yield return(new TextView("Please keep face movements to a minimum", settings.InstructionTime, GUIUtils.Constants.DISPLAY_FONT_LARGE));
            }
        }
예제 #7
0
        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));
                        }
                    }
                }
            }
        }
예제 #8
0
        /// <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);
                        }
                    }
                }
        }
예제 #9
0
        /// <summary>
        /// Builds the application view for the Adaptive Application
        /// </summary>
        public void BuildAdaptiveView()
        {
            this.SuspendLayout();
            this.Text = GUIUtils.Strings.APP_NAME;
            this.Size = new System.Drawing.Size(1500, 750);

            //Settings panels
            var config = ConfigurationPanel.Create<AdaptiveSettings>();
            //var artifactConfig = ConfigurationPanel.Create<ArtifactDetectionSettings>();
            var stimulipanel = new AdaptiveSelectorPanel() { Dock = DockStyle.Fill };
            // classifier settings
            var classifierPanel = new ClassificationSchemePanel() { Dock = DockStyle.Fill };

            //Headset Connected?
            EmotivStatusCheckerPanel statusChecker = new EmotivStatusCheckerPanel() { Dock = DockStyle.Fill };

            // start button
            var startButton = GUIUtils.CreateFlatButton("Start Experiment", b =>
            {
                var settings = (AdaptiveSettings)config.GetConfiguredObject();
                //settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject();
                settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)classifierPanel.ArtifactDetectionSettings;
                var test = this.ReadAdaptStimuli(stimulipanel.TestFile);
                var ans = this.ReadAdaptStimuli(stimulipanel.AnsFile);
                var presentation = this.ReadCompetitionStimuli(stimulipanel.PresentationFile);
                var class1 = this.ReadCompetitionStimuli(stimulipanel.Class1File);
                var class2 = this.ReadCompetitionStimuli(stimulipanel.Class2File);
                //Make study-test pairs for practice phase
                RandomizedQueue<MCAEmotiv.GUI.Adaptive.StudyTestPair> stp = new RandomizedQueue<MCAEmotiv.GUI.Adaptive.StudyTestPair>();
                for (int i = 0; i < test.Count; i++)
                {
                    stp.Add(new MCAEmotiv.GUI.Adaptive.StudyTestPair(test[i], ans[i], i));
                }
                //To Do: Add a dialog box so that the user knows whether the headset is connected
                IEEGDataSource dataSource;
                if (statusChecker.HeadsetConnected)
                {
                    dataSource = EmotivDataSource.Instance;
                }
                else
                    dataSource = new MockEEGDataSource();

                var classifiers = classifierPanel.SelectedClassifiers;
                this.Animate(new AdaptiveProvider(stp, presentation, class1, class2, settings, dataSource, classifiers.Where(c => c.Settings.FeatureCount > 0).ToIArray()));
            });

            //Dialog boxes for saving and loading experiment settings
            var saveDialog = new SaveFileDialog()
            {
                Title = "Save experiment settings",
                Filter = "Experiment settings files|*.adaptsettings",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
            };
            var openDialog = new OpenFileDialog()
            {
                Title = "Select the saved experiment settings (.adaptsettings) file",
                Filter = "Experiment settings files|*.adaptsettings",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                Multiselect = false
            };

            // button table for saving and loading experiment settings
            var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Fill,
            GUIUtils.CreateFlatButton("Save", b =>
            {
                var settings = (AdaptiveSettings)config.GetConfiguredObject();
                settings.TestFile = stimulipanel.TestFile;
                settings.AnsFile = stimulipanel.AnsFile;
                settings.PresentationFile = stimulipanel.PresentationFile;
                settings.Class1File = stimulipanel.Class1File;
                settings.Class2File = stimulipanel.Class2File;
                //settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject();
                settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)classifierPanel.ArtifactDetectionSettings;
                //ISSUE HERE
                //settings.ClassificationSettings = (ClassificationScheme) classifierPanel
                saveDialog.FileName = string.IsNullOrWhiteSpace(settings.ExperimentName) ? "my experiment" : settings.ExperimentName;
                if (saveDialog.ShowDialog() != DialogResult.OK)
                    return;

                bool saved = settings.TrySerializeToFile(saveDialog.FileName);
                GUIUtils.Alert((saved ? "Saved" : "Failed to save")
                    + " experiment info to " + saveDialog.FileName,
                    (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error));

                string directory = Path.GetDirectoryName(saveDialog.FileName);
                if (Directory.Exists(directory))
                    saveDialog.InitialDirectory = directory;
            }, null, "Save experiment configuration information"),
            GUIUtils.CreateFlatButton("Load", b =>
            {
                if (openDialog.ShowDialog() != DialogResult.OK)
                    return;

                AdaptiveSettings settings;

                if (Utils.TryDeserializeFile(openDialog.FileName, out settings))
                {
                    config.SetConfiguredObject(settings);
                    stimulipanel.TestFile = settings.TestFile;
                    stimulipanel.AnsFile = settings.AnsFile;
                    stimulipanel.PresentationFile = settings.PresentationFile;
                    stimulipanel.Class1File = settings.Class1File;
                    stimulipanel.Class2File = settings.Class2File;
                    //NEED TO DO EACH CLASSIFIERPANEL PROPERTY ONE BY ONE :(
                    //artifactConfig.SetConfiguredObject(settings.ArtifactDetectionSettings);
                    //classifierPanel.SetConfiguredObject(settings.ArtifactDetectionSettings);

                }
                else
                    GUIUtils.Alert("Failed to load experiment info from " + openDialog.FileName, MessageBoxIcon.Error);

            }, null, "Load a previously saved experiment settings file"));

            //Put together the GUI
            var rows = GUIUtils.CreateTable(new[] { .5, .35, .15 }, Direction.Vertical);
            var col1 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);
            var col2 = GUIUtils.CreateTable(new[] { .5, .5}, Direction.Horizontal);
            var col3 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);

            //col2.Controls.Add(artifactConfig, 1, 0);
            col1.Controls.Add(startButton, 1, 0);
            col1.Controls.Add(statusChecker, 0, 0);
            col2.Controls.Add(config, 0, 0);
            col2.Controls.Add(classifierPanel, 1, 0);
            col3.Controls.Add(stimulipanel, 1, 0);
            col3.Controls.Add(buttonTable, 0, 0);
            rows.Controls.Add(col3, 0, 1);
            rows.Controls.Add(col1, 0, 2);
            rows.Controls.Add(col2, 0, 0);

            this.Controls.Add(rows);

            this.ResumeLayout(false);
        }
예제 #10
0
        /// <summary>
        /// Builds the application view for the User Control Vocabulary Application
        /// </summary>
        public void BuildUserCtrlView()
        {
            this.SuspendLayout();
            this.Text = GUIUtils.Strings.APP_NAME;
            this.Size = new System.Drawing.Size(1500, 750);

            //Settings panel
            var config = ConfigurationPanel.Create<UserCtrlSettings>();
            var stimulipanel = new UserCtrlSelectorPanel() { Dock = DockStyle.Fill };

            // start button
            var startButton = GUIUtils.CreateFlatButton("Start Experiment", b =>
            {
                var settings = (UserCtrlSettings)config.GetConfiguredObject();
                var presentation = this.ReadUserStimuli(stimulipanel.PresentationFile);
                var test = this.ReadUserStimuli(stimulipanel.TestFile);
                var ans = this.ReadUserStimuli(stimulipanel.AnsFile);
                var comp = this.ReadCompetitionStimuli(stimulipanel.CompFile);
                var class1 = this.ReadCompetitionStimuli(stimulipanel.Class1File);
                var class2 = this.ReadCompetitionStimuli(stimulipanel.Class2File);
                //Make study-test pairs for the practice phase
                RandomizedQueue<MCAEmotiv.GUI.UserControlVocab.StudyTestPair> stp = new RandomizedQueue<MCAEmotiv.GUI.UserControlVocab.StudyTestPair>();
                for (int i = 0; i < test.Count; i++)
                {
                    stp.Add(new MCAEmotiv.GUI.UserControlVocab.StudyTestPair(test[i], ans[i], i));
                }
                if (presentation == null)
                    return;
                this.Animate(new UserCtrlProvider(presentation, comp, class1, class2, stp, settings));
            });

            //Dialog boxes for saving and loading experiment settings
            var saveDialog = new SaveFileDialog()
            {
                Title = "Save experiment settings",
                Filter = "Experiment settings files|*.usersettings",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
            };
            var openDialog = new OpenFileDialog()
            {
                Title = "Select the saved experiment settings (.usersettings) file",
                Filter = "Experiment settings files|*.usersettings",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                Multiselect = false
            };

            // button table for saving and loading experiment settings
            var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Fill,
            GUIUtils.CreateFlatButton("Save", b =>
            {
                var settings = (UserCtrlSettings)config.GetConfiguredObject();
                settings.PresentationFile = stimulipanel.PresentationFile;
                settings.TestFile = stimulipanel.TestFile;
                settings.AnsFile = stimulipanel.AnsFile;
                settings.CompFile = stimulipanel.CompFile;
                settings.Class1File = stimulipanel.Class1File;
                settings.Class2File = stimulipanel.Class2File;
                saveDialog.FileName = string.IsNullOrWhiteSpace(settings.ExperimentName) ? "my experiment" : settings.ExperimentName;
                if (saveDialog.ShowDialog() != DialogResult.OK)
                    return;

                bool saved = settings.TrySerializeToFile(saveDialog.FileName);
                GUIUtils.Alert((saved ? "Saved" : "Failed to save")
                    + " experiment info to " + saveDialog.FileName,
                    (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error));

                string directory = Path.GetDirectoryName(saveDialog.FileName);
                if (Directory.Exists(directory))
                    saveDialog.InitialDirectory = directory;
            }, null, "Save experiment configuration information"),
            GUIUtils.CreateFlatButton("Load", b =>
            {
                if (openDialog.ShowDialog() != DialogResult.OK)
                    return;

                UserCtrlSettings settings;

                if (Utils.TryDeserializeFile(openDialog.FileName, out settings))
                {
                    config.SetConfiguredObject(settings);
                    stimulipanel.PresentationFile = settings.PresentationFile;
                    stimulipanel.TestFile = settings.TestFile;
                    stimulipanel.AnsFile = settings.AnsFile;
                    stimulipanel.CompFile = settings.CompFile;
                    stimulipanel.Class1File = settings.Class1File;
                    stimulipanel.Class2File = settings.Class2File;
                }
                else
                    GUIUtils.Alert("Failed to load experiment info from " + openDialog.FileName, MessageBoxIcon.Error);

            }, null, "Load a previously saved experiment settings file"));

            //Put together the GUI
            var rows = GUIUtils.CreateTable(new[] { .5, .35, .15 }, Direction.Vertical);
            var col3 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);

            col3.Controls.Add(stimulipanel, 1, 0);
            col3.Controls.Add(buttonTable, 0, 0);
            rows.Controls.Add(col3, 0, 1);
            rows.Controls.Add(startButton, 0, 2);
            rows.Controls.Add(config, 0, 0);

            this.Controls.Add(rows);

            this.ResumeLayout(false);
        }
예제 #11
0
        /// <summary>
        /// Builds the application view for the False Adaptive Application
        /// </summary>
        public void BuildFAdaptView()
        {
            this.SuspendLayout();
            this.Text = GUIUtils.Strings.APP_NAME;
            this.Size = new System.Drawing.Size(1500, 750);

            //Settings panels
            var config = ConfigurationPanel.Create<FalseAdaptSettings>();
            var artifactConfig = ConfigurationPanel.Create<ArtifactDetectionSettings>();
            var stimulipanel = new FalseAdaptSelectorPanel() { Dock = DockStyle.Fill };

            //Headset Connected?
            EmotivStatusCheckerPanel statusChecker = new EmotivStatusCheckerPanel() { Dock = DockStyle.Fill };

            // start button
            var startButton = GUIUtils.CreateFlatButton("Start Experiment", b =>
            {
                var settings = (FalseAdaptSettings)config.GetConfiguredObject();
                settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject();
                var presentation = this.ReadFAStimuli(stimulipanel.PresentationFile);
                var comp = this.ReadCompetitionStimuli(stimulipanel.CompFile);
                var class1 = this.ReadCompetitionStimuli(stimulipanel.Class1File);
                var class2 = this.ReadCompetitionStimuli(stimulipanel.Class2File);
                var study = this.ReadUserStimuli(stimulipanel.StudyFile);
                //Make study-test pairs for practice phase
                RandomizedQueue<StudyTestTuple> stt = new RandomizedQueue<StudyTestTuple>();
                for (int i = 0; i < presentation.Count; i++)
                {
                    if (presentation[i] == "5")
                        stt.Add(new StudyTestTuple(presentation[i+1], presentation[i+1], true));
                    if (presentation[i] == "7")
                        stt.Add(new StudyTestTuple(presentation[i + 1], presentation[i + 2], false));
                }

                this.Animate(new FalseAdaptProvider(stt, comp, class1, class2, study, settings));
            });

            //Dialog boxes for saving and loading experiment settings
            var saveDialog = new SaveFileDialog()
            {
                Title = "Save experiment settings",
                Filter = "Experiment settings files|*.fasettings",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
            };
            var openDialog = new OpenFileDialog()
            {
                Title = "Select the saved experiment settings (.fasettings) file",
                Filter = "Experiment settings files|*.fasettings",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                Multiselect = false
            };

            // button table for saving and loading experiment settings
            var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Fill,
            GUIUtils.CreateFlatButton("Save", b =>
            {
                var settings = (FalseAdaptSettings)config.GetConfiguredObject();
                settings.PresentationFile = stimulipanel.PresentationFile;
                settings.StudyFile = stimulipanel.StudyFile;
                settings.CompFile = stimulipanel.CompFile;
                settings.Class1File = stimulipanel.Class1File;
                settings.Class2File = stimulipanel.Class2File;
                settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject();
                saveDialog.FileName = string.IsNullOrWhiteSpace(settings.ExperimentName) ? "my experiment" : settings.ExperimentName;
                if (saveDialog.ShowDialog() != DialogResult.OK)
                    return;

                bool saved = settings.TrySerializeToFile(saveDialog.FileName);
                GUIUtils.Alert((saved ? "Saved" : "Failed to save")
                    + " experiment info to " + saveDialog.FileName,
                    (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error));

                string directory = Path.GetDirectoryName(saveDialog.FileName);
                if (Directory.Exists(directory))
                    saveDialog.InitialDirectory = directory;
            }, null, "Save experiment configuration information"),
            GUIUtils.CreateFlatButton("Load", b =>
            {
                if (openDialog.ShowDialog() != DialogResult.OK)
                    return;

                FalseAdaptSettings settings;

                if (Utils.TryDeserializeFile(openDialog.FileName, out settings))
                {
                    config.SetConfiguredObject(settings);
                    stimulipanel.PresentationFile = settings.PresentationFile;
                    stimulipanel.StudyFile = settings.StudyFile;
                    stimulipanel.CompFile = settings.CompFile;
                    stimulipanel.Class1File = settings.Class1File;
                    stimulipanel.Class2File = settings.Class2File;
                    artifactConfig.SetConfiguredObject(settings.ArtifactDetectionSettings);
                }
                else
                    GUIUtils.Alert("Failed to load experiment info from " + openDialog.FileName, MessageBoxIcon.Error);

            }, null, "Load a previously saved experiment settings file"));

            //Put together the GUI
            var rows = GUIUtils.CreateTable(new[] { .5, .3, .2 }, Direction.Vertical);
            var col1 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);
            var col2 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);
            var col3 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);

            col2.Controls.Add(artifactConfig, 1, 0);
            col1.Controls.Add(startButton, 1, 0);
            col1.Controls.Add(statusChecker, 0, 0);
            col2.Controls.Add(config, 0, 0);
            col3.Controls.Add(stimulipanel, 1, 0);
            col3.Controls.Add(buttonTable, 0, 0);
            rows.Controls.Add(col3, 0, 1);
            rows.Controls.Add(col1, 0, 2);
            rows.Controls.Add(col2, 0, 0);

            this.Controls.Add(rows);

            this.ResumeLayout(false);
        }
예제 #12
0
        /// <summary>
        /// Builds the application view for the Adaptive Application
        /// </summary>
        public void BuildAdaptiveView()
        {
            this.SuspendLayout();
            this.Text = GUIUtils.Strings.APP_NAME;
            this.Size = new System.Drawing.Size(1500, 750);

            //Settings panels
            var config = ConfigurationPanel.Create <AdaptiveSettings>();
            //var artifactConfig = ConfigurationPanel.Create<ArtifactDetectionSettings>();
            var stimulipanel = new AdaptiveSelectorPanel()
            {
                Dock = DockStyle.Fill
            };
            // classifier settings
            var classifierPanel = new ClassificationSchemePanel()
            {
                Dock = DockStyle.Fill
            };

            //Headset Connected?
            EmotivStatusCheckerPanel statusChecker = new EmotivStatusCheckerPanel()
            {
                Dock = DockStyle.Fill
            };

            // start button
            var startButton = GUIUtils.CreateFlatButton("Start Experiment", b =>
            {
                var settings = (AdaptiveSettings)config.GetConfiguredObject();
                //settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject();
                settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)classifierPanel.ArtifactDetectionSettings;
                var test         = this.ReadAdaptStimuli(stimulipanel.TestFile);
                var ans          = this.ReadAdaptStimuli(stimulipanel.AnsFile);
                var presentation = this.ReadCompetitionStimuli(stimulipanel.PresentationFile);
                var class1       = this.ReadCompetitionStimuli(stimulipanel.Class1File);
                var class2       = this.ReadCompetitionStimuli(stimulipanel.Class2File);
                //Make study-test pairs for practice phase
                RandomizedQueue <MCAEmotiv.GUI.Adaptive.StudyTestPair> stp = new RandomizedQueue <MCAEmotiv.GUI.Adaptive.StudyTestPair>();
                for (int i = 0; i < test.Count; i++)
                {
                    stp.Add(new MCAEmotiv.GUI.Adaptive.StudyTestPair(test[i], ans[i], i));
                }
                //To Do: Add a dialog box so that the user knows whether the headset is connected
                IEEGDataSource dataSource;
                if (statusChecker.HeadsetConnected)
                {
                    dataSource = EmotivDataSource.Instance;
                }
                else
                {
                    dataSource = new MockEEGDataSource();
                }

                var classifiers = classifierPanel.SelectedClassifiers;
                this.Animate(new AdaptiveProvider(stp, presentation, class1, class2, settings, dataSource, classifiers.Where(c => c.Settings.FeatureCount > 0).ToIArray()));
            });

            //Dialog boxes for saving and loading experiment settings
            var saveDialog = new SaveFileDialog()
            {
                Title            = "Save experiment settings",
                Filter           = "Experiment settings files|*.adaptsettings",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
            };
            var openDialog = new OpenFileDialog()
            {
                Title            = "Select the saved experiment settings (.adaptsettings) file",
                Filter           = "Experiment settings files|*.adaptsettings",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                Multiselect      = false
            };

            // button table for saving and loading experiment settings
            var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Fill,
                                                         GUIUtils.CreateFlatButton("Save", b =>
            {
                var settings              = (AdaptiveSettings)config.GetConfiguredObject();
                settings.TestFile         = stimulipanel.TestFile;
                settings.AnsFile          = stimulipanel.AnsFile;
                settings.PresentationFile = stimulipanel.PresentationFile;
                settings.Class1File       = stimulipanel.Class1File;
                settings.Class2File       = stimulipanel.Class2File;
                //settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject();
                settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)classifierPanel.ArtifactDetectionSettings;
                //ISSUE HERE
                //settings.ClassificationSettings = (ClassificationScheme) classifierPanel
                saveDialog.FileName = string.IsNullOrWhiteSpace(settings.ExperimentName) ? "my experiment" : settings.ExperimentName;
                if (saveDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                bool saved = settings.TrySerializeToFile(saveDialog.FileName);
                GUIUtils.Alert((saved ? "Saved" : "Failed to save")
                               + " experiment info to " + saveDialog.FileName,
                               (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error));

                string directory = Path.GetDirectoryName(saveDialog.FileName);
                if (Directory.Exists(directory))
                {
                    saveDialog.InitialDirectory = directory;
                }
            }, null, "Save experiment configuration information"),
                                                         GUIUtils.CreateFlatButton("Load", b =>
            {
                if (openDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                AdaptiveSettings settings;

                if (Utils.TryDeserializeFile(openDialog.FileName, out settings))
                {
                    config.SetConfiguredObject(settings);
                    stimulipanel.TestFile         = settings.TestFile;
                    stimulipanel.AnsFile          = settings.AnsFile;
                    stimulipanel.PresentationFile = settings.PresentationFile;
                    stimulipanel.Class1File       = settings.Class1File;
                    stimulipanel.Class2File       = settings.Class2File;
                    //NEED TO DO EACH CLASSIFIERPANEL PROPERTY ONE BY ONE :(
                    //artifactConfig.SetConfiguredObject(settings.ArtifactDetectionSettings);
                    //classifierPanel.SetConfiguredObject(settings.ArtifactDetectionSettings);
                }
                else
                {
                    GUIUtils.Alert("Failed to load experiment info from " + openDialog.FileName, MessageBoxIcon.Error);
                }
            }, null, "Load a previously saved experiment settings file"));

            //Put together the GUI
            var rows = GUIUtils.CreateTable(new[] { .5, .35, .15 }, Direction.Vertical);
            var col1 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);
            var col2 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);
            var col3 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);

            //col2.Controls.Add(artifactConfig, 1, 0);
            col1.Controls.Add(startButton, 1, 0);
            col1.Controls.Add(statusChecker, 0, 0);
            col2.Controls.Add(config, 0, 0);
            col2.Controls.Add(classifierPanel, 1, 0);
            col3.Controls.Add(stimulipanel, 1, 0);
            col3.Controls.Add(buttonTable, 0, 0);
            rows.Controls.Add(col3, 0, 1);
            rows.Controls.Add(col1, 0, 2);
            rows.Controls.Add(col2, 0, 0);


            this.Controls.Add(rows);


            this.ResumeLayout(false);
        }
예제 #13
0
        /// <summary>
        /// Builds the application view for the User Control Vocabulary Application
        /// </summary>
        public void BuildUserCtrlView()
        {
            this.SuspendLayout();
            this.Text = GUIUtils.Strings.APP_NAME;
            this.Size = new System.Drawing.Size(1500, 750);

            //Settings panel
            var config       = ConfigurationPanel.Create <UserCtrlSettings>();
            var stimulipanel = new UserCtrlSelectorPanel()
            {
                Dock = DockStyle.Fill
            };

            // start button
            var startButton = GUIUtils.CreateFlatButton("Start Experiment", b =>
            {
                var settings     = (UserCtrlSettings)config.GetConfiguredObject();
                var presentation = this.ReadUserStimuli(stimulipanel.PresentationFile);
                var test         = this.ReadUserStimuli(stimulipanel.TestFile);
                var ans          = this.ReadUserStimuli(stimulipanel.AnsFile);
                var comp         = this.ReadCompetitionStimuli(stimulipanel.CompFile);
                var class1       = this.ReadCompetitionStimuli(stimulipanel.Class1File);
                var class2       = this.ReadCompetitionStimuli(stimulipanel.Class2File);
                //Make study-test pairs for the practice phase
                RandomizedQueue <MCAEmotiv.GUI.UserControlVocab.StudyTestPair> stp = new RandomizedQueue <MCAEmotiv.GUI.UserControlVocab.StudyTestPair>();
                for (int i = 0; i < test.Count; i++)
                {
                    stp.Add(new MCAEmotiv.GUI.UserControlVocab.StudyTestPair(test[i], ans[i], i));
                }
                if (presentation == null)
                {
                    return;
                }
                this.Animate(new UserCtrlProvider(presentation, comp, class1, class2, stp, settings));
            });

            //Dialog boxes for saving and loading experiment settings
            var saveDialog = new SaveFileDialog()
            {
                Title            = "Save experiment settings",
                Filter           = "Experiment settings files|*.usersettings",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
            };
            var openDialog = new OpenFileDialog()
            {
                Title            = "Select the saved experiment settings (.usersettings) file",
                Filter           = "Experiment settings files|*.usersettings",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                Multiselect      = false
            };

            // button table for saving and loading experiment settings
            var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Fill,
                                                         GUIUtils.CreateFlatButton("Save", b =>
            {
                var settings = (UserCtrlSettings)config.GetConfiguredObject();
                settings.PresentationFile = stimulipanel.PresentationFile;
                settings.TestFile         = stimulipanel.TestFile;
                settings.AnsFile          = stimulipanel.AnsFile;
                settings.CompFile         = stimulipanel.CompFile;
                settings.Class1File       = stimulipanel.Class1File;
                settings.Class2File       = stimulipanel.Class2File;
                saveDialog.FileName       = string.IsNullOrWhiteSpace(settings.ExperimentName) ? "my experiment" : settings.ExperimentName;
                if (saveDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                bool saved = settings.TrySerializeToFile(saveDialog.FileName);
                GUIUtils.Alert((saved ? "Saved" : "Failed to save")
                               + " experiment info to " + saveDialog.FileName,
                               (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error));

                string directory = Path.GetDirectoryName(saveDialog.FileName);
                if (Directory.Exists(directory))
                {
                    saveDialog.InitialDirectory = directory;
                }
            }, null, "Save experiment configuration information"),
                                                         GUIUtils.CreateFlatButton("Load", b =>
            {
                if (openDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                UserCtrlSettings settings;

                if (Utils.TryDeserializeFile(openDialog.FileName, out settings))
                {
                    config.SetConfiguredObject(settings);
                    stimulipanel.PresentationFile = settings.PresentationFile;
                    stimulipanel.TestFile         = settings.TestFile;
                    stimulipanel.AnsFile          = settings.AnsFile;
                    stimulipanel.CompFile         = settings.CompFile;
                    stimulipanel.Class1File       = settings.Class1File;
                    stimulipanel.Class2File       = settings.Class2File;
                }
                else
                {
                    GUIUtils.Alert("Failed to load experiment info from " + openDialog.FileName, MessageBoxIcon.Error);
                }
            }, null, "Load a previously saved experiment settings file"));


            //Put together the GUI
            var rows = GUIUtils.CreateTable(new[] { .5, .35, .15 }, Direction.Vertical);
            var col3 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);

            col3.Controls.Add(stimulipanel, 1, 0);
            col3.Controls.Add(buttonTable, 0, 0);
            rows.Controls.Add(col3, 0, 1);
            rows.Controls.Add(startButton, 0, 2);
            rows.Controls.Add(config, 0, 0);


            this.Controls.Add(rows);


            this.ResumeLayout(false);
        }
예제 #14
0
        /// <summary>
        /// Builds the application view for the False Adaptive Application
        /// </summary>
        public void BuildFAdaptView()
        {
            this.SuspendLayout();
            this.Text = GUIUtils.Strings.APP_NAME;
            this.Size = new System.Drawing.Size(1500, 750);

            //Settings panels
            var config         = ConfigurationPanel.Create <FalseAdaptSettings>();
            var artifactConfig = ConfigurationPanel.Create <ArtifactDetectionSettings>();
            var stimulipanel   = new FalseAdaptSelectorPanel()
            {
                Dock = DockStyle.Fill
            };

            //Headset Connected?
            EmotivStatusCheckerPanel statusChecker = new EmotivStatusCheckerPanel()
            {
                Dock = DockStyle.Fill
            };

            // start button
            var startButton = GUIUtils.CreateFlatButton("Start Experiment", b =>
            {
                var settings = (FalseAdaptSettings)config.GetConfiguredObject();
                settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject();
                var presentation = this.ReadFAStimuli(stimulipanel.PresentationFile);
                var comp         = this.ReadCompetitionStimuli(stimulipanel.CompFile);
                var class1       = this.ReadCompetitionStimuli(stimulipanel.Class1File);
                var class2       = this.ReadCompetitionStimuli(stimulipanel.Class2File);
                var study        = this.ReadUserStimuli(stimulipanel.StudyFile);
                //Make study-test pairs for practice phase
                RandomizedQueue <StudyTestTuple> stt = new RandomizedQueue <StudyTestTuple>();
                for (int i = 0; i < presentation.Count; i++)
                {
                    if (presentation[i] == "5")
                    {
                        stt.Add(new StudyTestTuple(presentation[i + 1], presentation[i + 1], true));
                    }
                    if (presentation[i] == "7")
                    {
                        stt.Add(new StudyTestTuple(presentation[i + 1], presentation[i + 2], false));
                    }
                }

                this.Animate(new FalseAdaptProvider(stt, comp, class1, class2, study, settings));
            });

            //Dialog boxes for saving and loading experiment settings
            var saveDialog = new SaveFileDialog()
            {
                Title            = "Save experiment settings",
                Filter           = "Experiment settings files|*.fasettings",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
            };
            var openDialog = new OpenFileDialog()
            {
                Title            = "Select the saved experiment settings (.fasettings) file",
                Filter           = "Experiment settings files|*.fasettings",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                Multiselect      = false
            };

            // button table for saving and loading experiment settings
            var buttonTable = GUIUtils.CreateButtonTable(Direction.Horizontal, DockStyle.Fill,
                                                         GUIUtils.CreateFlatButton("Save", b =>
            {
                var settings = (FalseAdaptSettings)config.GetConfiguredObject();
                settings.PresentationFile          = stimulipanel.PresentationFile;
                settings.StudyFile                 = stimulipanel.StudyFile;
                settings.CompFile                  = stimulipanel.CompFile;
                settings.Class1File                = stimulipanel.Class1File;
                settings.Class2File                = stimulipanel.Class2File;
                settings.ArtifactDetectionSettings = (ArtifactDetectionSettings)artifactConfig.GetConfiguredObject();
                saveDialog.FileName                = string.IsNullOrWhiteSpace(settings.ExperimentName) ? "my experiment" : settings.ExperimentName;
                if (saveDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                bool saved = settings.TrySerializeToFile(saveDialog.FileName);
                GUIUtils.Alert((saved ? "Saved" : "Failed to save")
                               + " experiment info to " + saveDialog.FileName,
                               (saved ? MessageBoxIcon.Information : MessageBoxIcon.Error));

                string directory = Path.GetDirectoryName(saveDialog.FileName);
                if (Directory.Exists(directory))
                {
                    saveDialog.InitialDirectory = directory;
                }
            }, null, "Save experiment configuration information"),
                                                         GUIUtils.CreateFlatButton("Load", b =>
            {
                if (openDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                FalseAdaptSettings settings;

                if (Utils.TryDeserializeFile(openDialog.FileName, out settings))
                {
                    config.SetConfiguredObject(settings);
                    stimulipanel.PresentationFile = settings.PresentationFile;
                    stimulipanel.StudyFile        = settings.StudyFile;
                    stimulipanel.CompFile         = settings.CompFile;
                    stimulipanel.Class1File       = settings.Class1File;
                    stimulipanel.Class2File       = settings.Class2File;
                    artifactConfig.SetConfiguredObject(settings.ArtifactDetectionSettings);
                }
                else
                {
                    GUIUtils.Alert("Failed to load experiment info from " + openDialog.FileName, MessageBoxIcon.Error);
                }
            }, null, "Load a previously saved experiment settings file"));

            //Put together the GUI
            var rows = GUIUtils.CreateTable(new[] { .5, .3, .2 }, Direction.Vertical);
            var col1 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);
            var col2 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);
            var col3 = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Horizontal);

            col2.Controls.Add(artifactConfig, 1, 0);
            col1.Controls.Add(startButton, 1, 0);
            col1.Controls.Add(statusChecker, 0, 0);
            col2.Controls.Add(config, 0, 0);
            col3.Controls.Add(stimulipanel, 1, 0);
            col3.Controls.Add(buttonTable, 0, 0);
            rows.Controls.Add(col3, 0, 1);
            rows.Controls.Add(col1, 0, 2);
            rows.Controls.Add(col2, 0, 0);


            this.Controls.Add(rows);


            this.ResumeLayout(false);
        }