/// <summary> /// Removes the trial from this session. The index must be in bounds for this /// method to succeed. /// </summary> /// <param name="index"></param> /// <returns></returns> public TrialData RemoveAt(int index) { TrialData td = null; if (_trials != null && 0 <= index && index < _trials.Count) { td = _trials[index]; _trials.RemoveAt(index); } return(td); }
/// <summary> /// Writes a CSV file representing a character-level error table for this session. /// </summary> /// <param name="writer">The stream writer to write the file.</param> /// <param name="useInputStream">A boolean indicating whether the input stream should /// be considered or only the presented and transcribed strings.</param> /// <returns>True if successful; false otherwise.</returns> public bool WriteCharacterErrorTable(StreamWriter writer, bool useInputStream) { bool success = true; try { CharacterErrorTable table = !useInputStream ? new CharacterErrorTable() : new CharacterErrorTableEx(); // polymorphism! for (int i = 0; i < _trials.Count; i++) { TrialData td = _trials[i]; List <string> Plist, Tlist; if (!useInputStream) { int nAlign = td.ComputeAlignments(out Plist, out Tlist); for (int j = 0; j < nAlign; j++) { table.RecordEntries(Plist[j], Tlist[j], null, nAlign); } } else { List <string> ISlist; int nAlign = td.ComputeAlignments(out Plist, out Tlist, out ISlist); for (int j = 0; j < nAlign; j++) { table.RecordEntries(Plist[j], Tlist[j], ISlist[j], nAlign); } } } table.CalculateErrorProbabilities(); table.WriteToCsv(writer, false); } catch (IOException ioex) { Console.WriteLine(ioex); success = false; } catch (Exception ex) { Console.WriteLine(ex); success = false; } finally { if (writer != null) { writer.Close(); } } return(success); }
/// <summary> /// Writes a CSV file representing a character-level confusion matrix for this session. /// </summary> /// <param name="writer">The stream writer to write the file.</param> /// <param name="useInputStream">A boolean indicating whether the input stream should /// be considered or only the presented and transcribed strings.</param> /// <returns>True if successful; false otherwise.</returns> public bool WriteConfusionMatrix(StreamWriter writer, bool useInputStream) { bool success = true; try { ConfusionMatrix matrix = !useInputStream ? new ConfusionMatrix() : new ConfusionMatrixEx(); // polymorphism! for (int i = 0; i < _trials.Count; i++) { TrialData td = _trials[i]; List <string> Plist, Tlist; if (!useInputStream) { int nAlign = td.ComputeAlignments(out Plist, out Tlist); for (int j = 0; j < nAlign; j++) { matrix.RecordEntries(Plist[j], Tlist[j], null, nAlign); } } else { List <string> ISlist; int nAlign = td.ComputeAlignments(out Plist, out Tlist, out ISlist); for (int j = 0; j < nAlign; j++) { matrix.RecordEntries(Plist[j], Tlist[j], ISlist[j], nAlign); } } } matrix.WriteToCsv(writer); } catch (IOException ioex) { Console.WriteLine(ioex); success = false; } catch (Exception ex) { Console.WriteLine(ex); success = false; } finally { if (writer != null) { writer.Close(); } } return(success); }
/// <summary> /// Stops the current test in progress, closing the test log and /// clearing appropriate fields. /// </summary> /// <param name="sender">The sender of this event.</param> /// <param name="e">The arguments for this event.</param> private void mniStopTest_Click(object sender, EventArgs e) { // important to disable this up front to prevent network // characters from getting through after a test is done. rtxTranscribed.Enabled = false; rtxPresented.Enabled = false; cmdNext.Enabled = false; if (_sd != null) { if (_td != null) { if (_td.NumEntries > 0) // ignore an empty last trial { _td.Transcribed = rtxTranscribed.Text; Debug.Assert(_td.VerifyStream(), "Input stream and transcribed string mismatch!"); _td.IsTesting = mniTestFlag.Checked; _sd.Add(_td); // add the final trial } _td = null; // clear since test is over } XmlTextWriter xWriter = new XmlTextWriter(_fileNoExt + ".xml", Encoding.UTF8); _sd.WriteXmlHeader(xWriter); _sd.WriteXmlFooter(xWriter); ResultsForm frm = new ResultsForm(_sd, Path.GetFileName(_fileNoExt + ".xml")); frm.ShowDialog(this); _sd = null; // clear the session } rtxPresented.Clear(); rtxTranscribed.Clear(); UpdateStatusBar(); // send to client we're done as '\0' if (_o.ReceiveOnNet && _o.SendPres && _listener != null && _listener.IsConnected) { char zero = '\0'; _listener.Send(zero.ToString()); } }
/// <summary> /// Menu handler for the Test > Next menu item. This menu item is /// synonymous in function with the cmdNext button. This function /// essentially banks the previous task and initiates the next one. /// </summary> /// <param name="sender">The sender of this event.</param> /// <param name="e">The arguments for this event.</param> private void mniNextPhrase_Click(object sender, EventArgs e) { if (_o.AutoStop && (_td != null && _td.TrialNo == _o.StopAfter)) { MessageBox.Show(this, "Test complete!", "Test Complete", MessageBoxButtons.OK, MessageBoxIcon.Information); mniStopTest_Click(this, EventArgs.Empty); // shows graphs if (_o.AutoQuit) { DialogResult dr = MessageBox.Show(this, "The application will now exit.", "Exit", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dr == DialogResult.OK) { this.Close(); // exit app } } } else // no auto-stopping { if (_td == null) // Start (not Next) was clicked for first trial { cmdNext.Text = "Next"; rtxPresented.Enabled = true; rtxTranscribed.Enabled = true; } else // submit the end of the previous trial { _td.Transcribed = rtxTranscribed.Text; Debug.Assert(_td.VerifyStream(), "The input stream and transcribed string do not match."); _td.IsTesting = mniTestFlag.Checked; _sd.Add(_td); // add the last task if (_o.AutoSwitch && _td.TrialNo == _o.SwitchAfter) { mniTestFlag.Checked = true; mniPracticeFlag.Checked = false; } } // set up the next phrase string presented = _phrases.GetRandomPhrase(_o.NoCapitals); rtxPresented.Text = presented; rtxTranscribed.Clear(); rtxTranscribed.Enabled = true; rtxTranscribed.Focus(); // create the new trial data _td = new TrialData(_td == null ? 1 : _td.TrialNo + 1, presented); // update the status bar panes UpdateStatusBar(); // send this phrase over the network if (_o.ReceiveOnNet && _o.SendPres && _listener != null && _listener.IsConnected) { _listener.Send(presented); } } }