Ejemplo n.º 1
0
        /// <summary>
        /// Begins the trial, updating the current trial and block number, setting the status to in progress, starting the timer for the trial, and beginning recording positions of every object with an attached tracker
        /// </summary>
        public void Begin()
        {
            if (session.InTrial)
            {
                session.CurrentTrial.End();
            }

            session.currentTrialNum = number;
            session.currentBlockNum = block.number;

            status    = TrialStatus.InProgress;
            startTime = Time.time;
            result    = new ResultsDictionary(session.Headers, true);

            result["experiment"]         = session.experimentName;
            result["ppid"]               = session.ppid;
            result["session_num"]        = session.number;
            result["trial_num"]          = number;
            result["block_num"]          = block.number;
            result["trial_num_in_block"] = numberInBlock;
            result["start_time"]         = startTime;

            foreach (Tracker tracker in session.trackedObjects)
            {
                try
                {
                    tracker.StartRecording();
                }
                catch (NullReferenceException)
                {
                    Utilities.UXFDebugLogWarning("An item in the Tracked Objects field of the UXF session if empty (null)!");
                }
            }
            session.onTrialBegin.Invoke(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes trial data (List of OrderedResultsDict) to file at fpath
        /// </summary>
        /// <param name="dictList"></param>
        /// <param name="fpath"></param>
        public void WriteTrials(List <ResultsDictionary> dictList, WriteFileInfo writeFileInfo)
        {
            // generate list of all headers possible
            // hashset keeps unique set of keys
            HashSet <string> headers = new HashSet <string>();

            foreach (ResultsDictionary dict in dictList)
            {
                if (dict != null)
                {
                    foreach (string key in dict.Keys)
                    {
                        headers.Add(key);
                    }
                }
            }

            // final output: array of rows (comma-separated strings)
            string[] csvRows = new string[dictList.Count + 1];

            // first row: headers
            csvRows[0] = string.Join(",", headers.ToArray());

            for (int i = 0; i < dictList.Count; i++)
            {
                ResultsDictionary dict = dictList[i];
                if (dict == null)
                {
                    continue;               // empty trial, try next loop iteration
                }
                // add all observations to the row, in correct order.
                // check if null, if so assign to empty string (?? operator)
                var row = headers
                          .Select(header =>
                {
                    object val;
                    try { val = dict[header]; }
                    catch (KeyNotFoundException) { val = string.Empty; }
                    if (val == null)
                    {
                        val = string.Empty;
                    }
                    return(val.ToString());
                }
                                  );

                // join to string & store in output
                csvRows[i + 1] = string.Join(",", row.ToArray());
            }

            File.WriteAllLines(writeFileInfo.FullPath, csvRows);
            executeOnMainThreadQueue.Enqueue(() => onWriteFile.Invoke(writeFileInfo));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Begins the trial, updating the current trial and block number, setting the status to in progress, starting the timer for the trial, and beginning recording positions of every object with an attached tracker
        /// </summary>
        public void Begin()
        {
            if (!session.hasInitialised)
            {
                throw new InvalidOperationException("Cannot begin trial, session is is not ready! Session has not been started yet with session.Begin() (or via the UI), or session has already ended.");
            }
            if (session.InTrial)
            {
                session.CurrentTrial.End();
            }

            session.currentTrialNum = number;
            session.currentBlockNum = block.number;

            status    = TrialStatus.InProgress;
            startTime = Time.time;
            result    = new ResultsDictionary(session.Headers, true);

            result["experiment"]         = session.experimentName;
            result["ppid"]               = session.ppid;
            result["session_num"]        = session.number;
            result["trial_num"]          = number;
            result["block_num"]          = block.number;
            result["trial_num_in_block"] = numberInBlock;
            result["start_time"]         = startTime;

            foreach (Tracker tracker in session.trackedObjects)
            {
                try
                {
                    tracker.StartRecording();
                }
                catch (NullReferenceException)
                {
                    Utilities.UXFDebugLogWarning("An item in the Tracked Objects field of the UXF session if empty (null)!");
                }
            }
            session.onTrialBegin.Invoke(this);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Begins the trial, updating the current trial and block number, setting the status to in progress, starting the timer for the trial, and beginning recording positions of every object with an attached tracker
        /// </summary>
        public void Begin()
        {
            session.currentTrialNum = number;
            session.currentBlockNum = block.number;

            status    = TrialStatus.InProgress;
            startTime = Time.time;
            result    = new ResultsDictionary(session.Headers, true);

            result["experiment"]         = session.experimentName;
            result["ppid"]               = session.ppid;
            result["session_num"]        = session.number;
            result["trial_num"]          = number;
            result["block_num"]          = block.number;
            result["trial_num_in_block"] = numberInBlock;
            result["start_time"]         = startTime;

            foreach (Tracker tracker in session.trackedObjects)
            {
                tracker.StartRecording();
            }
            session.onTrialBegin.Invoke(this);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Begins the trial, updating the current trial and block number, setting the status to in progress, starting the timer for the trial, and beginning recording positions of every object with an attached tracker
        /// </summary>
        public void Begin()
        {
            session.currentTrialNum = number;
            session.currentBlockNum = block.number;

            status    = TrialStatus.InProgress;
            startTime = Time.time;
            result    = new ResultsDictionary(session.Headers, session.adHocHeaderAdd);

            result["directory"]          = Extensions.CombinePaths(session.experimentName, session.ppid, session.FolderName).Replace('\\', '/');
            result["experiment"]         = session.experimentName;
            result["ppid"]               = session.ppid;
            result["session_num"]        = session.number;
            result["trial_num"]          = number;
            result["block_num"]          = block.number;
            result["trial_num_in_block"] = numberInBlock;
            result["start_time"]         = startTime;

            foreach (Tracker tracker in session.trackedObjects)
            {
                tracker.StartRecording();
            }
            session.onTrialBegin.Invoke(this);
        }
        /// <summary>
        /// Writes trial data (List of OrderedResultsDict) to file at fpath
        /// </summary>
        /// <param name="dictList"></param>
        /// <param name="fpath"></param>
        public void WriteTrials(List <ResultsDictionary> dictList, WriteFileInfo writeFileInfo)
        {
            // generate list of all headers possible
            // hashset keeps unique set of keys
            HashSet <string> headers = new HashSet <string>();

            foreach (ResultsDictionary dict in dictList)
            {
                if (dict != null)
                {
                    foreach (string key in dict.Keys)
                    {
                        headers.Add(key);
                    }
                }
            }

            // final output: array of rows (comma-separated strings)
            string[] csvRows = new string[dictList.Count + 1];

            // first row: headers
            csvRows[0] = string.Join(",", headers.ToArray());

            for (int i = 0; i < dictList.Count; i++)
            {
                ResultsDictionary dict = dictList[i];
                if (dict == null)
                {
                    continue;               // empty trial, try next loop iteration
                }
                // add all observations to the row, in correct order.
                // check if null, if so assign to empty string
                var row = headers
                          .Select(header =>
                {
                    object val;
                    try { val = dict[header]; }
                    catch (KeyNotFoundException) { val = string.Empty; }
                    if (val == null)
                    {
                        val = string.Empty;
                    }
                    string stringValue = val.ToString();

                    // check for commas
                    // commas not allowed in CSV format, as they are parsed as new rows
                    if (stringValue.Contains(','))
                    {
                        Debug.LogWarningFormat(
                            "Replacing comma characters (',') in value '{0}' (result[\"{1}\"] in trial {2}) with '_' character. Reason: Comma characters not allowed in values in CSV file.",
                            stringValue, header, i
                            );
                        stringValue = stringValue.Replace(',', '_');
                    }
                    return(stringValue);
                }
                                  );

                // join to string & store in output
                csvRows[i + 1] = string.Join(",", row.ToArray());
            }

            File.WriteAllLines(writeFileInfo.FullPath, csvRows);
            executeOnMainThreadQueue.Enqueue(() => onWriteFile.Invoke(writeFileInfo));
        }