@@ -22,7 +22,7 @@ public class Session : MonoBehaviour
2222 /// </summary>
2323 [ Tooltip ( "Enable to automatically safely end the session when this object is destroyed (or the application stops running)." ) ]
2424 public bool endOnDestroy = true ;
25-
25+
2626 /// <summary>
2727 /// List of blocks for this experiment
2828 /// </summary>
@@ -71,6 +71,7 @@ public class Session : MonoBehaviour
7171 [ Tooltip ( "Event(s) to trigger when a trial ends. Can pass the instance of the Trial as a dynamic argument" ) ]
7272 public TrialEvent onTrialEnd = new TrialEvent ( ) ;
7373
74+
7475 [ Header ( "Session information" ) ]
7576
7677 [ ReadOnly ]
@@ -171,7 +172,11 @@ public class Session : MonoBehaviour
171172
172173 List < string > baseHeaders = new List < string > { "experiment" , "ppid" , "session_num" , "trial_num" , "block_num" , "trial_num_in_block" , "start_time" , "end_time" } ;
173174
174- string basePath ;
175+ /// <summary>
176+ /// The path in which the experiment data are stored.
177+ /// </summary>
178+ /// <value></value>
179+ public string basePath { get ; private set ; }
175180
176181
177182 /// <summary>
@@ -187,7 +192,11 @@ public class Session : MonoBehaviour
187192 /// </summary>
188193 public string path { get { return Path . Combine ( ppPath , folderName ) ; } }
189194
190- private string folderName { get { return SessionNumToName ( number ) ; } }
195+ /// <summary>
196+ /// Name of the Session folder
197+ /// </summary>
198+ /// <returns></returns>
199+ public string folderName { get { return SessionNumToName ( number ) ; } }
191200
192201
193202 /// <summary>
@@ -198,7 +207,7 @@ public class Session : MonoBehaviour
198207 /// <summary>
199208 /// Stores combined list of headers for the behavioural output.
200209 /// </summary>
201- public List < string > headers { get { return baseHeaders . Concat ( settingsToLog ) . Concat ( customHeaders ) . Concat ( trackingHeaders ) . ToList ( ) ; } }
210+ public List < string > headers { get { return baseHeaders . Concat ( settingsToLog ) . Concat ( customHeaders ) . Concat ( trackingHeaders ) . ToList ( ) ; } }
202211
203212 /// <summary>
204213 /// Dictionary of objects for datapoints collected via the UI, or otherwise.
@@ -235,7 +244,7 @@ void InitFolder()
235244 if ( ! System . IO . Directory . Exists ( ppPath ) )
236245 System . IO . Directory . CreateDirectory ( ppPath ) ;
237246 if ( System . IO . Directory . Exists ( path ) )
238- Debug . LogWarning ( "Warning: Session already exists! Continuing will overwrite" ) ;
247+ Debug . LogWarning ( "Warning: Session already exists! Continuing will overwrite" ) ;
239248 else
240249 System . IO . Directory . CreateDirectory ( path ) ;
241250 }
@@ -248,16 +257,22 @@ void InitFolder()
248257 public string SaveTrackerData ( Tracker tracker )
249258 {
250259 string fname = string . Format ( "{0}_{1}_T{2:000}.csv" , tracker . objectName , tracker . measurementDescriptor , currentTrialNum ) ;
251- string fpath = Path . Combine ( path , fname ) ;
260+
261+ WriteFileInfo fileInfo = new WriteFileInfo (
262+ WriteFileType . Tracker ,
263+ this . basePath ,
264+ experimentName ,
265+ ppid ,
266+ folderName ,
267+ fname
268+ ) ;
252269
253270 List < string [ ] > dataCopy = tracker . GetDataCopy ( ) ;
254271
255- fileIOManager . ManageInWorker ( ( ) => fileIOManager . WriteCSV ( tracker . header , dataCopy , fpath ) ) ;
272+ fileIOManager . ManageInWorker ( ( ) => fileIOManager . WriteCSV ( tracker . header , dataCopy , fileInfo ) ) ;
256273
257274 // return relative path so it can be stored in behavioural data
258- Uri fullPath = new Uri ( fpath ) ;
259- Uri basePath = new Uri ( experimentPath ) ;
260- return basePath . MakeRelativeUri ( fullPath ) . ToString ( ) ;
275+ return fileInfo . RelativePath ;
261276
262277 }
263278
@@ -279,11 +294,21 @@ public void CopyFileToSessionFolder(string filePath)
279294 /// <param name="objectName">Name of the object (is used for file name)</param>
280295 public void WriteDictToSessionFolder ( Dictionary < string , object > dict , string objectName )
281296 {
297+
282298 if ( hasInitialised )
283299 {
284300 string fileName = string . Format ( "{0}.json" , objectName ) ;
285- string filePath = Path . Combine ( path , fileName ) ;
286- fileIOManager . ManageInWorker ( ( ) => fileIOManager . WriteJson ( filePath , dict ) ) ;
301+
302+ WriteFileInfo fileInfo = new WriteFileInfo (
303+ WriteFileType . Dictionary ,
304+ this . basePath ,
305+ experimentName ,
306+ ppid ,
307+ folderName ,
308+ fileName
309+ ) ;
310+
311+ fileIOManager . ManageInWorker ( ( ) => fileIOManager . WriteJson ( dict , fileInfo ) ) ;
287312 }
288313 else
289314 {
@@ -345,7 +370,7 @@ public void Begin(string experimentName, string participantId, string baseFolder
345370 onSessionBegin . Invoke ( this ) ;
346371
347372 // copy Settings to session folder
348-
373+
349374 WriteDictToSessionFolder (
350375 new Dictionary < string , object > ( settings . baseDict ) , // makes a copy
351376 "settings" ) ;
@@ -369,13 +394,13 @@ public Block CreateBlock()
369394 public Block CreateBlock ( int numberOfTrials )
370395 {
371396 if ( numberOfTrials > 0 )
372- return new Block ( ( uint ) numberOfTrials , this ) ;
397+ return new Block ( ( uint ) numberOfTrials , this ) ;
373398 else
374399 throw new Exception ( "Invalid number of trials supplied" ) ;
375400 }
376401
377402 /// <summary>
378- /// Get currently active trial.
403+ /// Get currently active trial. When not in a trial, gets previous trial.
379404 /// </summary>
380405 /// <returns>Currently active trial.</returns>
381406 public Trial GetTrial ( )
@@ -437,7 +462,7 @@ public void BeginNextTrial()
437462 Trial PrevTrial ( )
438463 {
439464 try
440- {
465+ {
441466 // non zero indexed
442467 return trials . ToList ( ) [ currentTrialNum - 2 ] ;
443468 }
@@ -463,7 +488,7 @@ Trial FirstTrial()
463488 /// <returns></returns>
464489 Trial LastTrial ( )
465490 {
466- var lastBlock = blocks [ blocks . Count - 1 ] ;
491+ var lastBlock = blocks [ blocks . Count - 1 ] ;
467492 return lastBlock . trials [ lastBlock . trials . Count - 1 ] ;
468493 }
469494
@@ -500,7 +525,7 @@ public void End()
500525 // end logger
501526 if ( logger != null )
502527 logger . Finalise ( ) ;
503-
528+
504529 blocks = new List < Block > ( ) ;
505530 _hasInitialised = false ;
506531 }
@@ -510,10 +535,18 @@ void SaveResults()
510535 {
511536 List < OrderedResultDict > results = trials . Select ( t => t . result ) . ToList ( ) ;
512537 string fileName = "trial_results.csv" ;
513- string filePath = Path . Combine ( path , fileName ) ;
538+
539+ WriteFileInfo fileInfo = new WriteFileInfo (
540+ WriteFileType . Trials ,
541+ this . basePath ,
542+ experimentName ,
543+ ppid ,
544+ folderName ,
545+ fileName
546+ ) ;
514547
515548 // in this case, write in main thread to block aborting
516- fileIOManager . ManageInWorker ( ( ) => fileIOManager . WriteTrials ( results , headers . ToArray ( ) , filePath ) ) ;
549+ fileIOManager . ManageInWorker ( ( ) => fileIOManager . WriteTrials ( results , headers . ToArray ( ) , fileInfo ) ) ;
517550 }
518551
519552
@@ -534,7 +567,7 @@ void OnDestroy()
534567 End ( ) ;
535568 }
536569 }
537-
570+
538571 /// <summary>
539572 /// Convert a session number to a session name
540573 /// </summary>
@@ -551,7 +584,7 @@ public static string SessionNumToName(int num)
551584 /// Exception thrown in cases where we try to access a trial that does not exist.
552585 /// </summary>
553586 public class NoSuchTrialException : Exception
554- {
587+ {
555588 public NoSuchTrialException ( )
556589 {
557590 }
0 commit comments