/// <summary> /// Writes all or part of this data object to XML. If this data object owns other /// data objects that will also be written, this method may leave some XML elements /// open, which will be closed with a later call to <i>WriteXmlFooter</i>. /// </summary> /// <param name="writer">An open XML writer. The writer will be left open by this method /// after writing.</param> /// <returns>Returns <b>true</b> if successful; <b>false</b> otherwise.</returns> public bool WriteXmlHeader(XmlTextWriter writer) { writer.WriteStartElement("Condition"); writer.WriteAttributeString("block", XmlConvert.ToString(_block)); writer.WriteAttributeString("index", XmlConvert.ToString(_index)); writer.WriteAttributeString("circular", XmlConvert.ToString(_circular)); writer.WriteAttributeString("metronome", XmlConvert.ToString(this.UsedMetronome)); writer.WriteAttributeString("trials", XmlConvert.ToString(this.NumTrials)); writer.WriteAttributeString("completed", XmlConvert.ToString(this.NumCompletedTrials)); writer.WriteAttributeString("practice", XmlConvert.ToString(this.NumTrials - this.NumTestTrials)); writer.WriteAttributeString("test", XmlConvert.ToString(this.NumTestTrials)); writer.WriteAttributeString("MTPct", XmlConvert.ToString(_mtpct)); writer.WriteAttributeString("MTPred", XmlConvert.ToString(_mtpred)); writer.WriteAttributeString("MT", XmlConvert.ToString(this.MT)); writer.WriteAttributeString("A", XmlConvert.ToString(_a)); writer.WriteAttributeString("W", XmlConvert.ToString(_w)); writer.WriteAttributeString("ID", XmlConvert.ToString(Math.Round(this.ID, 4))); writer.WriteAttributeString("Ae_1d", XmlConvert.ToString(Math.Round(this.GetAe(false), 4))); writer.WriteAttributeString("SD_1d", XmlConvert.ToString(Math.Round(this.GetSD(false), 4))); writer.WriteAttributeString("We_1d", XmlConvert.ToString(Math.Round(this.GetWe(false), 4))); writer.WriteAttributeString("IDe_1d", XmlConvert.ToString(Math.Round(this.GetIDe(false), 4))); writer.WriteAttributeString("TP_1d", XmlConvert.ToString(Math.Round(this.GetTP(false), 4))); writer.WriteAttributeString("Ae_2d", XmlConvert.ToString(Math.Round(this.GetAe(true), 4))); writer.WriteAttributeString("SD_2d", XmlConvert.ToString(Math.Round(this.GetSD(true), 4))); writer.WriteAttributeString("We_2d", XmlConvert.ToString(Math.Round(this.GetWe(true), 4))); writer.WriteAttributeString("IDe_2d", XmlConvert.ToString(Math.Round(this.GetIDe(true), 4))); writer.WriteAttributeString("TP_2d", XmlConvert.ToString(Math.Round(this.GetTP(true), 4))); writer.WriteAttributeString("MTe", XmlConvert.ToString(this.GetMTe(ExcludeOutliersType.None))); writer.WriteAttributeString("MTe_sx", XmlConvert.ToString(this.GetMTe(ExcludeOutliersType.Spatial))); writer.WriteAttributeString("MTe_tx", XmlConvert.ToString(this.GetMTe(ExcludeOutliersType.Temporal))); writer.WriteAttributeString("errors", XmlConvert.ToString(this.GetNumErrors(ExcludeOutliersType.None))); writer.WriteAttributeString("errors_sx", XmlConvert.ToString(this.GetNumErrors(ExcludeOutliersType.Spatial))); writer.WriteAttributeString("errors_tx", XmlConvert.ToString(this.GetNumErrors(ExcludeOutliersType.Temporal))); writer.WriteAttributeString("errorPct", XmlConvert.ToString(Math.Round(GetErrorRate(ExcludeOutliersType.None), 4))); writer.WriteAttributeString("errorPct_sx", XmlConvert.ToString(Math.Round(GetErrorRate(ExcludeOutliersType.Spatial), 4))); writer.WriteAttributeString("errorPct_tx", XmlConvert.ToString(Math.Round(GetErrorRate(ExcludeOutliersType.Temporal), 4))); writer.WriteAttributeString("spatialOutliers", XmlConvert.ToString(this.NumSpatialOutliers)); writer.WriteAttributeString("temporalOutliers", XmlConvert.ToString(this.NumTemporalOutliers)); // write each trial out in turn. do not write out the special start-area trial at index 0. for (int i = 1; i < _trials.Count; i++) { TrialData td = _trials[i]; td.WriteXmlHeader(writer); } writer.WriteEndElement(); // </Condition> return(true); }
/// <summary> /// Shows all the information for a trial-level node highlighted in the treeview. /// </summary> /// <param name="node">The highlighted node in the left treeview, assumed to represent an individual trial.</param> private void ShowTrialInfo(TreeNode node) { // // Get the trial and its condition from the 'Tag' field from the selected node. // _tdata = (TrialData)node.Tag; _cdata = (ConditionData)node.Parent.Tag; // // Get the resampled and smoothed velocity, acceleration, and jerk profiles. // MovementData.Profiles resampled = _tdata.Movement.CreateResampledProfiles(); MovementData.Profiles smoothed = _tdata.Movement.CreateSmoothedProfiles(); // // Clear any series in the graphs. // grfDistance.ClearSeries(); grfVelocity.ClearSeries(); grfAcceleration.ClearSeries(); grfJerk.ClearSeries(); // // Graph the resampled distance to the target over time. // List <PointF> rdist = new List <PointF>(resampled.Position.Count); for (int i = 0; i < resampled.Position.Count; i++) { long t = resampled.Position[i].Time - resampled.Position[0].Time; double dx = GeotrigEx.Distance(resampled.Position[i], _tdata.TargetCenterFromStart); rdist.Add(new PointF(t, (float)dx)); } Graph.Series rd = new Graph.Series("resampled distance", Color.Salmon, Color.Salmon, false, true); rd.AddPoints(rdist); // // Graph the smoothed distance from the target over time. // List <PointF> sdist = new List <PointF>(smoothed.Position.Count); for (int i = 0; i < smoothed.Position.Count; i++) { long t = smoothed.Position[i].Time - smoothed.Position[0].Time; double dx = GeotrigEx.Distance(smoothed.Position[i], _tdata.TargetCenterFromStart); sdist.Add(new PointF(t, (float)dx)); } Graph.Series sd = new Graph.Series("smoothed distance", Color.MediumBlue, Color.MediumBlue, false, true); sd.AddPoints(sdist); grfDistance.AddSeries(rd); grfDistance.AddSeries(sd); // // Graph the velocity. // Graph.Series rv = new Graph.Series("resampled velocity", Color.Salmon, Color.Salmon, false, true); rv.AddPoints(resampled.Velocity); Graph.Series sv = new Graph.Series("smoothed velocity", Color.MediumBlue, Color.MediumBlue, false, true); sv.AddPoints(smoothed.Velocity); grfVelocity.AddSeries(rv); grfVelocity.AddSeries(sv); // // Graph the acceleration. // Graph.Series aaxis = new Graph.Series("zero line", Color.Gray, Color.Gray, false, true); aaxis.AddPoint(0f, 0f); aaxis.AddPoint(resampled.Acceleration[resampled.Acceleration.Count - 1].X, 0f); Graph.Series ra = new Graph.Series("resampled acceleration", Color.Salmon, Color.Salmon, false, true); ra.AddPoints(resampled.Acceleration); Graph.Series sa = new Graph.Series("smoothed acceleration", Color.MediumBlue, Color.MediumBlue, false, true); sa.AddPoints(smoothed.Acceleration); grfAcceleration.AddSeries(aaxis); grfAcceleration.AddSeries(ra); grfAcceleration.AddSeries(sa); // // Graph the jerk. // Graph.Series jaxis = new Graph.Series("zero line", Color.Gray, Color.Gray, false, true); jaxis.AddPoint(0f, 0f); jaxis.AddPoint(resampled.Jerk[resampled.Jerk.Count - 1].X, 0f); Graph.Series rj = new Graph.Series("resampled jerk", Color.Salmon, Color.Salmon, false, true); rj.AddPoints(resampled.Jerk); Graph.Series sj = new Graph.Series("smoothed jerk", Color.MediumBlue, Color.MediumBlue, false, true); sj.AddPoints(smoothed.Jerk); grfJerk.AddSeries(jaxis); grfJerk.AddSeries(rj); grfJerk.AddSeries(sj); // // Now show the trial-level XML in the web control. // XmlTextWriter writer = null; string tmpXml = String.Format("{0}{1}.xml", Path.GetTempPath(), Path.GetRandomFileName()); try { writer = new XmlTextWriter(tmpXml, Encoding.UTF8); writer.Formatting = Formatting.Indented; _tdata.WriteXmlHeader(writer); } catch (Exception ex) { Console.WriteLine(ex); tmpXml = String.Empty; } finally { if (writer != null) { writer.Close(); } if (tmpXml != String.Empty) { webXml.Navigate(tmpXml); rtxXml.LoadFile(tmpXml, RichTextBoxStreamType.PlainText); _tmpXml.Add(tmpXml); } } // // Invalidate everything that needs to be repainted based on the node just selected. // pnlTrial.Invalidate(); grfDistance.Invalidate(); grfVelocity.Invalidate(); grfAcceleration.Invalidate(); grfJerk.Invalidate(); }