public PredictView(Runtime runtime, QuestionMode questionMode, IArrayView <EEGDataEntry> trial) : base() { var panel = this.RegisterDisposable(new Panel { Dock = DockStyle.Fill }); var displayList = runtime.Classifiers.Select(c => new Display() { Classifier = c.Settings.Name, Prediction = "predicting...", Confidence = c.Classifier.ComputesConfidence ? "predicting... " : "n/a", Accuracy = c.Accuracy }).ToList(); var grid = new DataGridView() { Dock = DockStyle.Fill, EditMode = DataGridViewEditMode.EditProgrammatically, DataSource = displayList, Font = GUIUtils.Constants.DISPLAY_FONT, AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill, ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize, }; panel.Controls.Add(grid); int count = runtime.Classifiers.Count; Stimulus selectedStimulus = null; Func <bool> succeeded = () => false; this.DoOnDeploy(c => { if (!string.IsNullOrWhiteSpace(this.Text)) { panel.Controls.Add(this.Text.ToLabel(DockStyle.Top, ContentAlignment.MiddleCenter)); } c.Controls.Add(panel); foreach (int index in (runtime.Classifiers.Count > 0 ? runtime.Classifiers.Indices() : (0).Enumerate())) { int i = index; ThreadPool.QueueUserWorkItem(ignored => { double confidence = 0; StimulusClass predicted; try { predicted = runtime.Classifiers[i].Predict(trial, out confidence) == runtime.Provider.StimulusClass1.Settings.Marker ? runtime.Provider.StimulusClass1 : runtime.Provider.StimulusClass2; } catch (Exception) { predicted = runtime.Provider.StimulusClass1; } this.Invoke(() => { if (displayList.Count > 0) { displayList[i].Prediction = predicted.Settings.Name; displayList[i].Confidence = runtime.Classifiers[i].Classifier.ComputesConfidence ? confidence.ToString() : "n/a"; grid.InvalidateRow(i); } if (--count > 0) { return; } // log prediction results foreach (var display in displayList) { runtime.LogLine(string.Format("Classifier {0} predicted {1} (accuracy so far = {2})", display.Classifier, display.Prediction, display.Accuracy)); } Panel choicePanel1 = new Panel() { Dock = DockStyle.Bottom }, choicePanel2 = new Panel() { Dock = DockStyle.Bottom, Visible = false }; var choicesSoFarLabel = new Label() { Dock = DockStyle.Bottom, TextAlign = ContentAlignment.MiddleCenter, Font = GUIUtils.Constants.DISPLAY_FONT, Visible = false }; var classChoice = new ChoiceView(new string[] { runtime.Provider.StimulusClass1.Settings.Name, runtime.Provider.StimulusClass2.Settings.Name }) { Text = "Which did you choose?" }; classChoice.DoOnFinishing(() => { if (!classChoice.Result.HasValue) { return; } choicePanel1.Enabled = false; bool picked1 = classChoice.Result.Value.Equals(runtime.Provider.StimulusClass1.Settings.Name); choicesSoFarLabel.Text = string.Format("(Choices so far: {0} {1}/{2} {3})", runtime.Class1TestPicks + (picked1 ? 1 : 0), runtime.Provider.StimulusClass1.Settings.Name, runtime.Class2TestPicks + (picked1 ? 0 : 1), runtime.Provider.StimulusClass2.Settings.Name); choicesSoFarLabel.Visible = true; selectedStimulus = picked1 ? runtime.CurrentTrial.Stimulus1 : runtime.CurrentTrial.Stimulus2; if (questionMode == QuestionMode.None) { succeeded = () => true; this.DeploySubView(new RestView(750), choicePanel1, true); } else { var choiceView = new ChoiceView(new string[] { selectedStimulus.Class.Settings.Answer1, selectedStimulus.Class.Settings.Answer2, GUIUtils.Strings.DONT_KNOW }); succeeded = () => questionMode == QuestionMode.AskAndVerify ? selectedStimulus.SubclassString.Equals(choiceView.Result.Value) : !GUIUtils.Strings.DONT_KNOW.Equals(choiceView.Result.Value); choicePanel2.Visible = true; this.DeploySubView(choiceView, choicePanel2); } }); this.DeploySubView(classChoice, choicePanel1, false); panel.Controls.Add(choicePanel1); panel.Controls.Add(choicesSoFarLabel); panel.Controls.Add(new Label() { Dock = DockStyle.Bottom }); panel.Controls.Add(choicePanel2); }); }); } }); this.DoOnFinishing(() => { if (succeeded()) { for (int i = 0; i < displayList.Count; i++) { runtime.Classifiers[i].RecordResult(selectedStimulus.Class.Settings.Marker, displayList[i].Prediction == runtime.Provider.StimulusClass1.Settings.Name ? runtime.Provider.StimulusClass1.Settings.Marker : runtime.Provider.StimulusClass2.Settings.Marker, 0); } runtime.CurrentTrial.UserPicked1 = (selectedStimulus == runtime.CurrentTrial.Stimulus1); runtime.CurrentTrial.Succeeded = true; runtime.LogLine("User chose " + selectedStimulus.Class.Settings.Name); } }); }
public VocabView(string testStimulus, string correctAns, int displayTimeMillis, int delayTimeMillis, bool mchoice, StreamWriter anslog, out IViewResult result) : base() { TextView test = new TextView(testStimulus, displayTimeMillis, GUIUtils.Constants.DISPLAY_FONT_LARGE); //-1 is infinite time //mchoice is a bool that indicates whether the vocab view should be multiple choice or not. I haven't actually handled this properly if (mchoice) { string[] answers = new string[1]; //Currently the only option is the correct answer answers[0] = correctAns; ChoiceView choice = new ChoiceView(answers); var timer = this.RegisterDisposable(new Timer() { Interval = delayTimeMillis, Enabled = false }); var rows = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Vertical); var testPanel = new Panel { Dock = DockStyle.Fill }; var choicePanel = new Panel { Dock = DockStyle.Fill, Enabled = false }; rows.Controls.Add(testPanel, 0, 0); timer.Tick += (sender, args) => { choicePanel.Enabled = true; rows.Controls.Add(choicePanel, 0, 1); timer.Enabled = false; }; this.DoOnDeploy(c => { c.Controls.Add(rows); this.DeploySubView(test, testPanel, causesOwnerToFinish: false); this.DeploySubView(choice, choicePanel, causesOwnerToFinish: true); timer.Enabled = true; }); this.DoOnFinishing(() => { var answer = choice.Result.HasValue ? choice.Result.Value : null; this.SetResult(((string)answer) == correctAns); }); result = this.Result; } //ISSUE: In the free response version, no matter what I try, I can't get the cursor to automatically be in the text box else { FreeResponseView frView = new FreeResponseView(); var timer = this.RegisterDisposable(new Timer() { Interval = delayTimeMillis, Enabled = false }); var rows = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Vertical); var testPanel = new Panel { Dock = DockStyle.Fill }; var frPanel = new Panel { Dock = DockStyle.Fill, Enabled = false }; rows.Controls.Add(testPanel, 0, 0); timer.Tick += (sender, args) => { frPanel.Enabled = true; rows.Controls.Add(frPanel, 0, 1); timer.Enabled = false; }; this.DoOnDeploy(c => { c.Controls.Add(rows); this.DeploySubView(test, testPanel, causesOwnerToFinish: false); this.DeploySubView(frView, frPanel, causesOwnerToFinish: true); timer.Enabled = true; }); this.DoOnFinishing(() => { if (frView.Result.HasValue) this.SetResult(((string) frView.Result.Value) == correctAns); else this.SetResult(false); anslog.WriteLine("User Answer: " + (string)frView.Result.Value); anslog.WriteLine("Correct Answer: " + correctAns); }); result = this.Result; } }
public ClassifyView(Stimulus stimulus, StimulusClass stimulusClass, out IViewResult result) : base() { var table = this.RegisterDisposable(GUIUtils.CreateTable(new double[] { .7, .1, .2 }, Direction.Vertical)); Panel topPanel = new Panel() { Dock = DockStyle.Fill }, bottomPanel = new Panel() { Dock = DockStyle.Fill }; table.Controls.Add(topPanel, 0, 0); var label = new Label() { Dock = DockStyle.Fill, AutoSize = true, TextAlign = ContentAlignment.MiddleCenter, Text = "Current selection: ", Font = GUIUtils.Constants.DISPLAY_FONT }; table.Controls.Add(label, 0, 1); table.Controls.Add(bottomPanel, 0, 2); var imageView = new ImageView(-1) { ImagePath = stimulus.PathOrText }; var choiceView = new ChoiceView(new string[] { stimulusClass.Settings.Answer1, stimulusClass.Settings.Answer2, GUIUtils.Strings.UNCLASSIFIED, SKIP, BACK }); this.DoOnDeploy(c => { this.DeploySubView(imageView, topPanel); topPanel.Controls.Add(new Label() { Text = GUIUtils.Strings.ImageExtensions.Contains(Path.GetExtension(stimulus.PathOrText)) ? Path.GetFileNameWithoutExtension(stimulus.PathOrText) : stimulus.PathOrText, Dock = DockStyle.Top, TextAlign = ContentAlignment.MiddleCenter, Font = GUIUtils.Constants.DISPLAY_FONT }); if (stimulus.Subclass == null) { label.Text += GUIUtils.Strings.UNCLASSIFIED; } else { label.Text += (bool)stimulus.Subclass ? stimulusClass.Settings.Answer1 : stimulusClass.Settings.Answer2; } this.DeploySubView(choiceView, bottomPanel); c.Controls.Add(table); }); this.DoOnFinishing(() => { if (!(bool)imageView.Result.Value) { this.SetResult(null); } else if (stimulusClass.Settings.Answer1.Equals(choiceView.Result.Value)) { this.SetResult(true); } else if (stimulusClass.Settings.Answer2.Equals(choiceView.Result.Value)) { this.SetResult(false); } else if (BACK.Equals(choiceView.Result.Value)) { this.SetResult(BACK); } else if (SKIP.Equals(choiceView.Result.Value)) { this.SetResult(SKIP); } else { this.SetResult(null); } }); result = this.Result; }
public VocabView(string testStimulus, string correctAns, int displayTimeMillis, int delayTimeMillis, bool mchoice, out IViewResult result) : base() { TextView test = new TextView(testStimulus, displayTimeMillis, GUIUtils.Constants.DISPLAY_FONT_LARGE); //-1 is infinite time if (mchoice) { string[] answers = new string[1]; //Currently the only option is the correct answer //To do: Randomly select a subset of answers OR do free response answers[0] = correctAns; ChoiceView choice = new ChoiceView(answers); var timer = this.RegisterDisposable(new Timer() { Interval = delayTimeMillis, Enabled = false }); var rows = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Vertical); var testPanel = new Panel { Dock = DockStyle.Fill }; var choicePanel = new Panel { Dock = DockStyle.Fill, Enabled = false }; rows.Controls.Add(testPanel, 0, 0); timer.Tick += (sender, args) => { choicePanel.Enabled = true; rows.Controls.Add(choicePanel, 0, 1); timer.Enabled = false; }; this.DoOnDeploy(c => { c.Controls.Add(rows); this.DeploySubView(test, testPanel, causesOwnerToFinish: false); this.DeploySubView(choice, choicePanel, causesOwnerToFinish: true); timer.Enabled = true; }); this.DoOnFinishing(() => { var answer = choice.Result.HasValue ? choice.Result.Value : null; this.SetResult(((string)answer) == correctAns); }); result = this.Result; } else { FreeResponseView frView = new FreeResponseView(); var timer = this.RegisterDisposable(new Timer() { Interval = delayTimeMillis, Enabled = false }); var rows = GUIUtils.CreateTable(new[] { .5, .5 }, Direction.Vertical); var testPanel = new Panel { Dock = DockStyle.Fill }; var frPanel = new Panel { Dock = DockStyle.Fill, Enabled = false }; rows.Controls.Add(testPanel, 0, 0); timer.Tick += (sender, args) => { frPanel.Enabled = true; rows.Controls.Add(frPanel, 0, 1); timer.Enabled = false; }; this.DoOnDeploy(c => { c.Controls.Add(rows); this.DeploySubView(test, testPanel, causesOwnerToFinish: false); this.DeploySubView(frView, frPanel, causesOwnerToFinish: true); timer.Enabled = true; }); this.DoOnFinishing(() => { if (frView.Result.HasValue && (string) frView.Result.Value != "") if (Compute((string)frView.Result.Value, correctAns) < 3) if ((correctAns == "MONKEY" && (string) frView.Result.Value == "DONKEY") || (correctAns == "DONKEY" && (string) frView.Result.Value == "MONKEY")) this.SetResult(false); else if (correctAns == "MANGO" || correctAns == "MAGGOT" || correctAns == "HORSE" || correctAns == "CORPSE") this.SetResult(Compute((string)frView.Result.Value, correctAns) < 2); else this.SetResult(true); else this.SetResult(false); else this.SetResult(false); }); result = this.Result; } }