@@ -22,7 +22,7 @@ public class Session : MonoBehaviour
22
22
/// </summary>
23
23
[ Tooltip ( "Enable to automatically safely end the session when this object is destroyed (or the application stops running)." ) ]
24
24
public bool endOnDestroy = true ;
25
-
25
+
26
26
/// <summary>
27
27
/// List of blocks for this experiment
28
28
/// </summary>
@@ -71,6 +71,7 @@ public class Session : MonoBehaviour
71
71
[ Tooltip ( "Event(s) to trigger when a trial ends. Can pass the instance of the Trial as a dynamic argument" ) ]
72
72
public TrialEvent onTrialEnd = new TrialEvent ( ) ;
73
73
74
+
74
75
[ Header ( "Session information" ) ]
75
76
76
77
[ ReadOnly ]
@@ -171,7 +172,11 @@ public class Session : MonoBehaviour
171
172
172
173
List < string > baseHeaders = new List < string > { "experiment" , "ppid" , "session_num" , "trial_num" , "block_num" , "trial_num_in_block" , "start_time" , "end_time" } ;
173
174
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 ; }
175
180
176
181
177
182
/// <summary>
@@ -187,7 +192,11 @@ public class Session : MonoBehaviour
187
192
/// </summary>
188
193
public string path { get { return Path . Combine ( ppPath , folderName ) ; } }
189
194
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 ) ; } }
191
200
192
201
193
202
/// <summary>
@@ -198,7 +207,7 @@ public class Session : MonoBehaviour
198
207
/// <summary>
199
208
/// Stores combined list of headers for the behavioural output.
200
209
/// </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 ( ) ; } }
202
211
203
212
/// <summary>
204
213
/// Dictionary of objects for datapoints collected via the UI, or otherwise.
@@ -235,7 +244,7 @@ void InitFolder()
235
244
if ( ! System . IO . Directory . Exists ( ppPath ) )
236
245
System . IO . Directory . CreateDirectory ( ppPath ) ;
237
246
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" ) ;
239
248
else
240
249
System . IO . Directory . CreateDirectory ( path ) ;
241
250
}
@@ -248,16 +257,22 @@ void InitFolder()
248
257
public string SaveTrackerData ( Tracker tracker )
249
258
{
250
259
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
+ ) ;
252
269
253
270
List < string [ ] > dataCopy = tracker . GetDataCopy ( ) ;
254
271
255
- fileIOManager . ManageInWorker ( ( ) => fileIOManager . WriteCSV ( tracker . header , dataCopy , fpath ) ) ;
272
+ fileIOManager . ManageInWorker ( ( ) => fileIOManager . WriteCSV ( tracker . header , dataCopy , fileInfo ) ) ;
256
273
257
274
// 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 ;
261
276
262
277
}
263
278
@@ -279,11 +294,21 @@ public void CopyFileToSessionFolder(string filePath)
279
294
/// <param name="objectName">Name of the object (is used for file name)</param>
280
295
public void WriteDictToSessionFolder ( Dictionary < string , object > dict , string objectName )
281
296
{
297
+
282
298
if ( hasInitialised )
283
299
{
284
300
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 ) ) ;
287
312
}
288
313
else
289
314
{
@@ -345,7 +370,7 @@ public void Begin(string experimentName, string participantId, string baseFolder
345
370
onSessionBegin . Invoke ( this ) ;
346
371
347
372
// copy Settings to session folder
348
-
373
+
349
374
WriteDictToSessionFolder (
350
375
new Dictionary < string , object > ( settings . baseDict ) , // makes a copy
351
376
"settings" ) ;
@@ -369,13 +394,13 @@ public Block CreateBlock()
369
394
public Block CreateBlock ( int numberOfTrials )
370
395
{
371
396
if ( numberOfTrials > 0 )
372
- return new Block ( ( uint ) numberOfTrials , this ) ;
397
+ return new Block ( ( uint ) numberOfTrials , this ) ;
373
398
else
374
399
throw new Exception ( "Invalid number of trials supplied" ) ;
375
400
}
376
401
377
402
/// <summary>
378
- /// Get currently active trial.
403
+ /// Get currently active trial. When not in a trial, gets previous trial.
379
404
/// </summary>
380
405
/// <returns>Currently active trial.</returns>
381
406
public Trial GetTrial ( )
@@ -437,7 +462,7 @@ public void BeginNextTrial()
437
462
Trial PrevTrial ( )
438
463
{
439
464
try
440
- {
465
+ {
441
466
// non zero indexed
442
467
return trials . ToList ( ) [ currentTrialNum - 2 ] ;
443
468
}
@@ -463,7 +488,7 @@ Trial FirstTrial()
463
488
/// <returns></returns>
464
489
Trial LastTrial ( )
465
490
{
466
- var lastBlock = blocks [ blocks . Count - 1 ] ;
491
+ var lastBlock = blocks [ blocks . Count - 1 ] ;
467
492
return lastBlock . trials [ lastBlock . trials . Count - 1 ] ;
468
493
}
469
494
@@ -500,7 +525,7 @@ public void End()
500
525
// end logger
501
526
if ( logger != null )
502
527
logger . Finalise ( ) ;
503
-
528
+
504
529
blocks = new List < Block > ( ) ;
505
530
_hasInitialised = false ;
506
531
}
@@ -510,10 +535,18 @@ void SaveResults()
510
535
{
511
536
List < OrderedResultDict > results = trials . Select ( t => t . result ) . ToList ( ) ;
512
537
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
+ ) ;
514
547
515
548
// 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 ) ) ;
517
550
}
518
551
519
552
@@ -534,7 +567,7 @@ void OnDestroy()
534
567
End ( ) ;
535
568
}
536
569
}
537
-
570
+
538
571
/// <summary>
539
572
/// Convert a session number to a session name
540
573
/// </summary>
@@ -551,7 +584,7 @@ public static string SessionNumToName(int num)
551
584
/// Exception thrown in cases where we try to access a trial that does not exist.
552
585
/// </summary>
553
586
public class NoSuchTrialException : Exception
554
- {
587
+ {
555
588
public NoSuchTrialException ( )
556
589
{
557
590
}
0 commit comments