예제 #1
0
        void SaveCurrentTrialXML(Encoding encoding)
        {
            Trial t = _trials[_currentTrialIndex];

            StreamWriter writer = new StreamWriter(_outputFilePath, true);

            string toRecord = "<trial";

            // first record all parameters
            foreach (string p in _parameters)
            {
                toRecord += " " + p + "=\"" + t.GetParameterData(p) + "\"";
            }

            Dictionary <string, string> savedData = t.GetResultsData();

            if (savedData.Count > 0)
            {
                if (_resultsHeader != null)
                {
                    foreach (string rh in _resultsHeader)
                    {
                        toRecord += " " + rh + "=\"" + t.GetResultData(rh) + "\"";
                    }
                }
                //					// need to order data according to _results header
                //					string[] toWrite = new string[_results.Count];
                //					// order elements to write them in a formatted order in the record file
                //					foreach(KeyValuePair<string, string> p in savedData) { toWrite[_results.IndexOf(p.Key)] = p.Value; }
                //					// prepare formatted string to receive the data
                //					for(int i = 0; i < _results.Count; i++) { toRecord += " "+_results[i]+"=\"{"+i+"}\""; }
                //					toRecord = string.Format(toRecord, toWrite);
                //				}
                // order does not matter if the results header was provided
                else
                {
                    foreach (KeyValuePair <string, string> p in savedData)
                    {
                        toRecord += " " + p.Key + "=\"" + p.Value + "\"";
                    }
                }
            }
            // always save main timer (should be able to rename it)
            toRecord += " TaskCompletionTime=\"" + t.GetMainRawDuration() + "\"";
            // save all timers at the end
            if (_timersHeader != null)
            {
                foreach (string th in _timersHeader)
                {
                    toRecord += " " + th + "=\"" + t.GetTimerRawDuration(th) + "\"";
                }
            }

            toRecord += "/>";
            writer.WriteLine(toRecord);
            writer.Close();
        }
예제 #2
0
        /// <summary>
        /// Saves the current trial in a .csv file. If the file does not exist yet, it will be created and the header added at the beginning.
        /// </summary>
        /// <param name="encoding">Encoding of the file.</param>
        void SaveCurrentTrialCSV(Encoding encoding, char separation)
        {
            Trial t = _trials[_currentTrialIndex];

            bool created = !File.Exists(_outputFilePath);
            // let exception flows if needs be
            StreamWriter writer = new StreamWriter(_outputFilePath, true);

            // write header at beginning of the file
            if (created)
            {
                string first = string.Join(separation + "", _parameters);
                if (_resultsHeader != null)
                {
                    first += separation + string.Join(separation + "", _resultsHeader);
                }
                first += separation + "TaskCompletionTime";
                if (_timersHeader != null)
                {
                    first += separation + string.Join(separation + "", _timersHeader);
                }
                writer.WriteLine(first);
            }

            // save parameters of this trial first
            string toRecord = string.Join(separation + "", t.GetAllData());
            // save all results saved for this trial
            Dictionary <string, string> savedData = t.GetResultsData();

            if (savedData.Count > 0)
            {
                if (_resultsHeader != null)
                {
                    foreach (string rh in _resultsHeader)
                    {
                        toRecord += separation + t.GetResultData(rh);
                    }
                    //					// need to order data according to _results header
                    //					string[] toWrite = new string[_resultsHeader.Count];
                    //					// order elements to write them in a formatted order in the record file
                    //					int index = 0;
                    //					foreach(KeyValuePair<string, string> p in savedData) {
                    //						toWrite[_resultsHeader.IndexOf(p.Key)] = p.Value;
                    //						toRecord += separation+"{"+(index++)+"}";
                    //					}
                    //					toRecord = string.Format(toRecord, toWrite);
                }
                // order does not matter if the results header was provided
                else
                {
                    foreach (string v in savedData.Values)
                    {
                        toRecord += separation + v;
                    }
                }
            }
            // always save main timer
            toRecord += separation + "" + t.GetMainRawDuration();
            // save all timers at the end
            if (_timersHeader != null)
            {
                foreach (string th in _timersHeader)
                {
                    toRecord += separation + "" + t.GetTimerRawDuration(th);
                }
            }

            writer.WriteLine(toRecord);
            writer.Close();
        }