예제 #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
파일: EzExp.cs 프로젝트: bfrucha/ez_exp
        /// <summary>
        /// Get data for a given parameter of the experiment.
        /// </summary>
        /// <param name="parameter">Name of the parameter.</param>
        /// <returns>The data associated.</returns>
        public string GetParameterData(string parameter)
        {
            if (_currentExperiment == null)
            {
                throw new ExperimentNotCreatedException();
            }
            Trial t = _currentExperiment.GetCurrentTrial();

            return(t.GetParameterData(parameter));
        }
예제 #3
0
 /// <summary>
 /// Starts the current trial. A trial has to be loaded before calling this function (<see cref="UnityEzExp.Experiment.LoadNextTrial"/>).
 /// </summary>
 public void StartTrial()
 {
     if (_currentTrialIndex < 0)
     {
         throw new TrialNotLoadedException();
     }
     else if (_trials.Count <= _currentTrialIndex)
     {
         throw new AllTrialsPerformedException();
     }
     else
     {
         Trial t = _trials[_currentTrialIndex];
         t.StartTrial();
     }
 }
예제 #4
0
        /// <summary>
        /// Ends the current trial. A trial has to be started before calling this function (<see cref="UnityEzExp.Experiment.StartTrial"/>).
        /// Depending on <see cref="UnityEzExp.RecordBehavior"/>, the trial results might be recorded before ended.
        /// </summary>
        public void EndTrial()
        {
            if (_currentTrialIndex < 0)
            {
                throw new TrialNotLoadedException();
            }
            else if (_trials.Count <= _currentTrialIndex)
            {
                throw new AllTrialsPerformedException();
            }
            else
            {
                Trial t = _trials[_currentTrialIndex];
                t.EndTrial();

                if (_recordBehavior == RecordBehavior.SaveOnTrialEnd)
                {
                    SaveCurrentTrial(Encoding.UTF8);
                }
            }
        }
예제 #5
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();
        }