예제 #1
0
        public override string HandleDataTable(UXFDataTable table, string experiment, string ppid, int sessionNum, string dataName, UXFDataType dataType, int optionalTrialNum = 0)
        {
            string ext = Path.GetExtension(dataName);

            dataName = Path.GetFileNameWithoutExtension(dataName);

            if (dataType.GetDataLevel() == UXFDataLevel.PerTrial)
            {
                dataName = string.Format("{0}_T{1:000}", dataName, optionalTrialNum);
            }

            string[] lines = table.GetCSVLines();

            string directory = GetSessionPath(experiment, ppid, sessionNum);

            if (sortDataIntoFolders && dataType != UXFDataType.TrialResults)
            {
                directory = Path.Combine(directory, dataType.ToLower());
            }
            Directory.CreateDirectory(directory);
            string name     = string.IsNullOrEmpty(ext) ? string.Format("{0}.csv", dataName) : string.Format("{0}{1}", dataName, ext);
            string savePath = Path.Combine(directory, name);

            if (verboseDebug)
            {
                Utilities.UXFDebugLogFormat("Queuing save of file: {0}", savePath);
            }

            ManageInWorker(() => { File.WriteAllLines(savePath, lines); });
            return(GetRelativePath(storagePath, savePath));;
        }
예제 #2
0
        public override string HandleDataTable(UXFDataTable table, string experiment, string ppid, int sessionNum, string dataName, UXFDataType dataType, int optionalTrialNum = 0)
        {
            if (dataType.GetDataLevel() == UXFDataLevel.PerTrial)
            {
                dataName = string.Format("{0}_T{1:000}", dataName, optionalTrialNum);
            }

            string[] lines = table.GetCSVLines();

            string directory = GetSessionPath(experiment, ppid, sessionNum);

            if (sortDataIntoFolders && dataType != UXFDataType.TrialResults)
            {
                directory = Path.Combine(directory, dataType.ToLower());
            }
            Directory.CreateDirectory(directory);
            string savePath = Path.Combine(directory, string.Format("{0}.csv", dataName));

            if (verboseDebug)
            {
                Debug.LogFormat("Queuing save of file: {0}", savePath);
            }

            ManageInWorker(() => { File.WriteAllLines(savePath, lines); });
            return(savePath);
        }
        public override string HandleDataTable(UXFDataTable table, string experiment, string ppid, int sessionNum, string dataName, UXFDataType dataType, int optionalTrialNum = 0)
        {
            // get data as text
            string[] lines = table.GetCSVLines();
            string   text  = string.Join("\n", lines);

            string ext = Path.GetExtension(dataName);

            dataName = Path.GetFileNameWithoutExtension(dataName);

            if (dataType.GetDataLevel() == UXFDataLevel.PerTrial)
            {
                dataName = string.Format("{0}_T{1:000}", dataName, optionalTrialNum);
            }

            string directory = GetSessionPathRelative(experiment, ppid, sessionNum);

            if (dataType != UXFDataType.TrialResults)
            {
                directory = Path.Combine(directory, dataType.ToLower());
            }

            string name     = string.IsNullOrEmpty(ext) ? string.Format("{0}.csv", dataName) : string.Format("{0}{1}", dataName, ext);
            string savePath = Path.Combine(directory, name);

            savePath = savePath.Replace('\\', '/');

            // here we send our data request
            AuthenticatedRequest(savePath, text);

            // return a string representing the location of the data. Will be stored in the trial_results output.
            return(savePath);
        }
        /// <summary>
        /// Ends the experiment session.
        /// </summary>
        public void End()
        {
            if (hasInitialised)
            {
                isEnding = true;
                if (InTrial)
                {
                    try { CurrentTrial.End(); }
                    catch (Exception e) { Debug.LogException(e); }
                }

                SaveResults();

                try { preSessionEnd.Invoke(this); }
                catch (Exception e) { Debug.LogException(e); }

                if (storeSessionSettings)
                {
                    // copy Settings to session folder
                    SaveJSONSerializableObject(new Dictionary <string, object>(settings.baseDict), "settings", dataType: UXFDataType.Settings);
                }

                if (storeParticipantDetails)
                {
                    // copy participant details to session folder
                    // we convert to a DataTable because we know the dictionary will be "flat" (one value per key)

                    UXFDataTable ppDetailsTable = new UXFDataTable(participantDetails.Keys.ToArray());
                    var          row            = new UXFDataRow();
                    foreach (var kvp in participantDetails)
                    {
                        row.Add((kvp.Key, kvp.Value));
                    }
                    ppDetailsTable.AddCompleteRow(row);
                    var ppDetailsLines = ppDetailsTable.GetCSVLines();

                    SaveDataTable(ppDetailsTable, "participant_details", dataType: UXFDataType.ParticipantDetails);
                }

                // end DataHandlers - forces completion of tasks
                foreach (var dataHandler in ActiveDataHandlers)
                {
                    try { dataHandler.CleanUp(); }
                    catch (Exception e) { Debug.LogException(e); }
                }

                try { onSessionEnd.Invoke(this); }
                catch (Exception e) { Debug.LogException(e); }

                currentTrialNum = 0;
                currentBlockNum = 0;
                blocks          = new List <Block>();
                _hasInitialised = false;

                Utilities.UXFDebugLog("Ended session.");
                isEnding = false;
            }
        }
예제 #5
0
        /// <summary>
        /// Initialises a Session
        /// </summary>
        /// <param name="experimentName">A name for the experiment</param>
        /// <param name="participantId">A unique ID associated with a participant</param>
        /// <param name="baseFolder">Location where data should be stored</param>
        /// <param name="sessionNumber">A number for the session (optional: default 1)</param>
        /// <param name="participantDetails">Dictionary of information about the participant to be used within the experiment (optional: default null)</param>
        /// <param name="settings">A Settings instance (optional: default empty settings)</param>
        public void Begin(string experimentName, string participantId, int sessionNumber = 1, Dictionary <string, object> participantDetails = null, Settings settings = null)
        {
            this.experimentName = experimentName;
            ppid   = participantId;
            number = sessionNumber;

            if (participantDetails == null)
            {
                participantDetails = new Dictionary <string, object>();
            }
            this.participantDetails = participantDetails;

            if (settings == null)
            {
                settings = Settings.empty;
            }
            this.settings = settings;

            // Initialise DataHandlers
            foreach (var dataHandler in ActiveDataHandlers)
            {
                dataHandler.Initialise(this);
                dataHandler.SetUp();
            }
            _hasInitialised = true;

            // raise the session events
            onSessionBegin.Invoke(this);

            if (storeSessionSettings)
            {
                // copy Settings to session folder
                SaveJSONSerializableObject(new Dictionary <string, object>(settings.baseDict), "settings", dataType: UXFDataType.Settings);
            }

            if (storeParticipantDetails)
            {
                // copy participant details to session folder
                // we convert to a DataTable because we know the dictionary will be "flat" (one value per key)

                UXFDataTable ppDetailsTable = new UXFDataTable(participantDetails.Keys.ToArray());
                var          row            = new UXFDataRow();
                foreach (var kvp in participantDetails)
                {
                    row.Add((kvp.Key, kvp.Value));
                }
                ppDetailsTable.AddCompleteRow(row);
                var ppDetailsLines = ppDetailsTable.GetCSVLines();

                SaveDataTable(ppDetailsTable, "participant_details", dataType: UXFDataType.ParticipantDetails);
            }
        }