Skip to content

Commit ac14a43

Browse files
committed
addressed #38
1 parent 83a1102 commit ac14a43

File tree

5 files changed

+98
-60
lines changed

5 files changed

+98
-60
lines changed

Assets/UXF/Plugins/WebFunctions.jslib

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ mergeInto(LibraryManager.library, {
2222
elem.select();
2323
document.execCommand("copy");
2424
document.body.removeChild(elem);
25+
},
26+
27+
GetUserInfo: function() {
28+
var data = {
29+
"user_agent": navigator.userAgent,
30+
"screen_width": window.screen.width,
31+
"screen_height": window.screen.height
32+
}
33+
var returnStr = JSON.stringify(data);
34+
35+
var bufferSize = lengthBytesUTF8(returnStr) + 1;
36+
var buffer = _malloc(bufferSize);
37+
stringToUTF8(returnStr, buffer, bufferSize);
38+
return buffer;
2539
}
2640

2741
});

Assets/UXF/Prefabs/[UXF_Rig].prefab

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ RectTransform:
931931
m_LocalScale: {x: 1, y: 1, z: 1}
932932
m_Children:
933933
- {fileID: 80835919952702251}
934-
m_Father: {fileID: 1726072748377084874}
934+
m_Father: {fileID: 1726072748377084723}
935935
m_RootOrder: 1
936936
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
937937
m_AnchorMin: {x: 1, y: 0.5}
@@ -1037,7 +1037,7 @@ MonoBehaviour:
10371037
m_Script: {fileID: 11500000, guid: 330023be939756b41b52054a3d796152, type: 3}
10381038
m_Name:
10391039
m_EditorClassIdentifier:
1040-
inputField: {fileID: 1726072748377084797}
1040+
inputField: {fileID: 1726072748377084773}
10411041
--- !u!1 &1171537770349854272
10421042
GameObject:
10431043
m_ObjectHideFlags: 0
@@ -1572,10 +1572,10 @@ RectTransform:
15721572
m_LocalPosition: {x: 0, y: 0, z: 0}
15731573
m_LocalScale: {x: 1, y: 1, z: 1}
15741574
m_Children:
1575-
- {fileID: 2897568975779925142}
1576-
- {fileID: 4835438972542875672}
1577-
- {fileID: 1726072748377084723}
1578-
- {fileID: 7877310278013525258}
1575+
- {fileID: 2897568975779925135}
1576+
- {fileID: 4835438972542875703}
1577+
- {fileID: 1726072748377084700}
1578+
- {fileID: 7877310278013525285}
15791579
m_Father: {fileID: 4979987231477995344}
15801580
m_RootOrder: 0
15811581
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -2727,13 +2727,13 @@ MonoBehaviour:
27272727
m_CorrespondingSourceObject: {fileID: 0}
27282728
m_PrefabInstance: {fileID: 0}
27292729
m_PrefabAsset: {fileID: 0}
2730-
m_GameObject: {fileID: 2897568975779925079}
2730+
m_GameObject: {fileID: 2897568975779925080}
27312731
m_Enabled: 1
27322732
m_EditorHideFlags: 0
27332733
m_Script: {fileID: 11500000, guid: 348b50adaf435754aa3adb61b9d1155d, type: 3}
27342734
m_Name:
27352735
m_EditorClassIdentifier:
2736-
dropdown: {fileID: 2897568975779925192}
2736+
dropdown: {fileID: 2897568975779925216}
27372737
--- !u!1 &2901584607484809767
27382738
GameObject:
27392739
m_ObjectHideFlags: 0
@@ -3657,6 +3657,7 @@ MonoBehaviour:
36573657
m_EditorClassIdentifier:
36583658
active: 0
36593659
endSessionWhenTryCloseTab: 1
3660+
collectBrowserInfo: 1
36603661
credentials: {fileID: 0}
36613662
--- !u!1 &3681515423267968892
36623663
GameObject:
@@ -5282,13 +5283,13 @@ MonoBehaviour:
52825283
m_CorrespondingSourceObject: {fileID: 0}
52835284
m_PrefabInstance: {fileID: 0}
52845285
m_PrefabAsset: {fileID: 0}
5285-
m_GameObject: {fileID: 4835438972542875827}
5286+
m_GameObject: {fileID: 4835438972542875814}
52865287
m_Enabled: 1
52875288
m_EditorHideFlags: 0
52885289
m_Script: {fileID: 11500000, guid: 5747e520a80c72849886c32bbce2b181, type: 3}
52895290
m_Name:
52905291
m_EditorClassIdentifier:
5291-
inputField: {fileID: 4835438972542875715}
5292+
inputField: {fileID: 4835438972542875771}
52925293
--- !u!1 &4921505235379613987
52935294
GameObject:
52945295
m_ObjectHideFlags: 0
@@ -6321,7 +6322,7 @@ RectTransform:
63216322
m_LocalScale: {x: 1, y: 1, z: 1}
63226323
m_Children:
63236324
- {fileID: 6783585386340811927}
6324-
m_Father: {fileID: 4835438972542875873}
6325+
m_Father: {fileID: 4835438972542875672}
63256326
m_RootOrder: 1
63266327
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
63276328
m_AnchorMin: {x: 1, y: 0.5}
@@ -8371,7 +8372,7 @@ RectTransform:
83718372
m_LocalPosition: {x: 0, y: 0, z: 0}
83728373
m_LocalScale: {x: 1, y: 1, z: 1}
83738374
m_Children:
8374-
- {fileID: 7936957113956597242}
8375+
- {fileID: 7936957113956597187}
83758376
m_Father: {fileID: 6431357393539466631}
83768377
m_RootOrder: 0
83778378
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -8448,7 +8449,7 @@ RectTransform:
84488449
m_LocalScale: {x: 1, y: 1, z: 1}
84498450
m_Children:
84508451
- {fileID: 793044841086912741}
8451-
m_Father: {fileID: 2897568975779925121}
8452+
m_Father: {fileID: 2897568975779925182}
84528453
m_RootOrder: 1
84538454
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
84548455
m_AnchorMin: {x: 1, y: 0.5}
@@ -9230,10 +9231,10 @@ MonoBehaviour:
92309231
tsAndCsInitialState: 0
92319232
instructionsContentTransform: {fileID: 4267567203292169432}
92329233
sidebarContentTransform: {fileID: 2834388984357925155}
9233-
settingsElement: {fileID: 2897568975779925192}
9234-
localFilePathElement: {fileID: 4835438972542875715}
9235-
ppidElement: {fileID: 1726072748377084776}
9236-
sessionNumElement: {fileID: 7877310278013525329}
9234+
settingsElement: {fileID: 2897568975779925216}
9235+
localFilePathElement: {fileID: 4835438972542875771}
9236+
ppidElement: {fileID: 1726072748377084752}
9237+
sessionNumElement: {fileID: 7877310278013525353}
92379238
tsAndCsToggle: {fileID: 3684702312775877842}
92389239
textPrefab: {fileID: 6478900352697465694, guid: 15c278d5156bae1489e9a38ad279bee2,
92399240
type: 3}
@@ -9425,7 +9426,7 @@ PrefabInstance:
94259426
objectReference: {fileID: 0}
94269427
m_RemovedComponents: []
94279428
m_SourcePrefab: {fileID: 100100000, guid: 15c278d5156bae1489e9a38ad279bee2, type: 3}
9428-
--- !u!114 &1726072748377084797 stripped
9429+
--- !u!114 &1726072748377084773 stripped
94299430
MonoBehaviour:
94309431
m_CorrespondingSourceObject: {fileID: 114970555796053392, guid: 15c278d5156bae1489e9a38ad279bee2,
94319432
type: 3}
@@ -9437,13 +9438,13 @@ MonoBehaviour:
94379438
m_Script: {fileID: 575553740, guid: f70555f144d8491a825f0804e09c671c, type: 3}
94389439
m_Name:
94399440
m_EditorClassIdentifier:
9440-
--- !u!224 &1726072748377084874 stripped
9441+
--- !u!224 &1726072748377084723 stripped
94419442
RectTransform:
94429443
m_CorrespondingSourceObject: {fileID: 150454391267887718, guid: 15c278d5156bae1489e9a38ad279bee2,
94439444
type: 3}
94449445
m_PrefabInstance: {fileID: 1726072748377084863}
94459446
m_PrefabAsset: {fileID: 0}
9446-
--- !u!114 &1726072748377084776 stripped
9447+
--- !u!114 &1726072748377084752 stripped
94479448
MonoBehaviour:
94489449
m_CorrespondingSourceObject: {fileID: 6478900352697465694, guid: 15c278d5156bae1489e9a38ad279bee2,
94499450
type: 3}
@@ -9455,7 +9456,7 @@ MonoBehaviour:
94559456
m_Script: {fileID: 11500000, guid: e62d33c83c20a154a95029aefc30368d, type: 3}
94569457
m_Name:
94579458
m_EditorClassIdentifier:
9458-
--- !u!224 &1726072748377084723 stripped
9459+
--- !u!224 &1726072748377084700 stripped
94599460
RectTransform:
94609461
m_CorrespondingSourceObject: {fileID: 224762906418741188, guid: 15c278d5156bae1489e9a38ad279bee2,
94619462
type: 3}
@@ -9624,31 +9625,31 @@ PrefabInstance:
96249625
objectReference: {fileID: 0}
96259626
m_RemovedComponents: []
96269627
m_SourcePrefab: {fileID: 100100000, guid: 9e81924d28cd0d849a13e5abce816d3a, type: 3}
9627-
--- !u!224 &2897568975779925142 stripped
9628+
--- !u!224 &2897568975779925135 stripped
96289629
RectTransform:
96299630
m_CorrespondingSourceObject: {fileID: 224502893949471668, guid: 9e81924d28cd0d849a13e5abce816d3a,
96309631
type: 3}
96319632
m_PrefabInstance: {fileID: 2897568975779925013}
96329633
m_PrefabAsset: {fileID: 0}
9633-
--- !u!114 &2897568975779925192 stripped
9634+
--- !u!114 &2897568975779925216 stripped
96349635
MonoBehaviour:
96359636
m_CorrespondingSourceObject: {fileID: 8506875127483083998, guid: 9e81924d28cd0d849a13e5abce816d3a,
96369637
type: 3}
96379638
m_PrefabInstance: {fileID: 2897568975779925013}
96389639
m_PrefabAsset: {fileID: 0}
9639-
m_GameObject: {fileID: 2897568975779925079}
9640+
m_GameObject: {fileID: 2897568975779925080}
96409641
m_Enabled: 1
96419642
m_EditorHideFlags: 0
96429643
m_Script: {fileID: 11500000, guid: e62d33c83c20a154a95029aefc30368d, type: 3}
96439644
m_Name:
96449645
m_EditorClassIdentifier:
9645-
--- !u!1 &2897568975779925079 stripped
9646+
--- !u!1 &2897568975779925080 stripped
96469647
GameObject:
96479648
m_CorrespondingSourceObject: {fileID: 1969525990930008, guid: 9e81924d28cd0d849a13e5abce816d3a,
96489649
type: 3}
96499650
m_PrefabInstance: {fileID: 2897568975779925013}
96509651
m_PrefabAsset: {fileID: 0}
9651-
--- !u!224 &2897568975779925121 stripped
9652+
--- !u!224 &2897568975779925182 stripped
96529653
RectTransform:
96539654
m_CorrespondingSourceObject: {fileID: 1392091059206779690, guid: 9e81924d28cd0d849a13e5abce816d3a,
96549655
type: 3}
@@ -9781,31 +9782,31 @@ PrefabInstance:
97819782
objectReference: {fileID: 0}
97829783
m_RemovedComponents: []
97839784
m_SourcePrefab: {fileID: 100100000, guid: 15c278d5156bae1489e9a38ad279bee2, type: 3}
9784-
--- !u!224 &4835438972542875672 stripped
9785+
--- !u!224 &4835438972542875703 stripped
97859786
RectTransform:
97869787
m_CorrespondingSourceObject: {fileID: 224762906418741188, guid: 15c278d5156bae1489e9a38ad279bee2,
97879788
type: 3}
97889789
m_PrefabInstance: {fileID: 4835438972542875796}
97899790
m_PrefabAsset: {fileID: 0}
9790-
--- !u!1 &4835438972542875827 stripped
9791+
--- !u!1 &4835438972542875814 stripped
97919792
GameObject:
97929793
m_CorrespondingSourceObject: {fileID: 1033861776628790, guid: 15c278d5156bae1489e9a38ad279bee2,
97939794
type: 3}
97949795
m_PrefabInstance: {fileID: 4835438972542875796}
97959796
m_PrefabAsset: {fileID: 0}
9796-
--- !u!224 &4835438972542875873 stripped
9797+
--- !u!224 &4835438972542875672 stripped
97979798
RectTransform:
97989799
m_CorrespondingSourceObject: {fileID: 150454391267887718, guid: 15c278d5156bae1489e9a38ad279bee2,
97999800
type: 3}
98009801
m_PrefabInstance: {fileID: 4835438972542875796}
98019802
m_PrefabAsset: {fileID: 0}
9802-
--- !u!114 &4835438972542875715 stripped
9803+
--- !u!114 &4835438972542875771 stripped
98039804
MonoBehaviour:
98049805
m_CorrespondingSourceObject: {fileID: 6478900352697465694, guid: 15c278d5156bae1489e9a38ad279bee2,
98059806
type: 3}
98069807
m_PrefabInstance: {fileID: 4835438972542875796}
98079808
m_PrefabAsset: {fileID: 0}
9808-
m_GameObject: {fileID: 4835438972542875827}
9809+
m_GameObject: {fileID: 4835438972542875814}
98099810
m_Enabled: 1
98109811
m_EditorHideFlags: 0
98119812
m_Script: {fileID: 11500000, guid: e62d33c83c20a154a95029aefc30368d, type: 3}
@@ -9969,7 +9970,7 @@ PrefabInstance:
99699970
objectReference: {fileID: 0}
99709971
m_RemovedComponents: []
99719972
m_SourcePrefab: {fileID: 100100000, guid: 15c278d5156bae1489e9a38ad279bee2, type: 3}
9972-
--- !u!114 &7877310278013525329 stripped
9973+
--- !u!114 &7877310278013525353 stripped
99739974
MonoBehaviour:
99749975
m_CorrespondingSourceObject: {fileID: 6478900352697465694, guid: 15c278d5156bae1489e9a38ad279bee2,
99759976
type: 3}
@@ -9981,7 +9982,7 @@ MonoBehaviour:
99819982
m_Script: {fileID: 11500000, guid: e62d33c83c20a154a95029aefc30368d, type: 3}
99829983
m_Name:
99839984
m_EditorClassIdentifier:
9984-
--- !u!224 &7877310278013525258 stripped
9985+
--- !u!224 &7877310278013525285 stripped
99859986
RectTransform:
99869987
m_CorrespondingSourceObject: {fileID: 224762906418741188, guid: 15c278d5156bae1489e9a38ad279bee2,
99879988
type: 3}
@@ -10106,7 +10107,7 @@ PrefabInstance:
1010610107
objectReference: {fileID: 0}
1010710108
m_RemovedComponents: []
1010810109
m_SourcePrefab: {fileID: 100100000, guid: 7c12eedbd5f4e9742aecfaac8b2f1d72, type: 3}
10109-
--- !u!224 &7936957113956597242 stripped
10110+
--- !u!224 &7936957113956597187 stripped
1011010111
RectTransform:
1011110112
m_CorrespondingSourceObject: {fileID: 3747006573595346056, guid: 7c12eedbd5f4e9742aecfaac8b2f1d72,
1011210113
type: 3}

Assets/UXF/Scripts/DataHandling/WebAWSDynamoDB.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ namespace UXF
1616
public class WebAWSDynamoDB : DataHandler
1717
{
1818

19+
[Tooltip("Enable to intercept the closing of the browser tab or window and end the session, so that data is saved.")]
1920
public bool endSessionWhenTryCloseTab = true;
2021

22+
[Tooltip("Enable collect browser info from the participant, and store them in the session.participantDetails dictionary. (Key-value pairs are: \"screen_width\": int, \"screen_height\": int, \"user_agent\": string)")]
23+
public bool collectBrowserInfo = true;
24+
2125
[SubjectNerd.Utilities.EditScriptable]
2226
public AWSCredentials credentials;
2327

24-
2528
[DllImport("__Internal")]
2629
private static extern void DDB_Setup(string region, string identityPool, string callbackGameObjectName);
2730

@@ -40,6 +43,9 @@ public class WebAWSDynamoDB : DataHandler
4043
[DllImport("__Internal")]
4144
private static extern void DDB_Cleanup();
4245

46+
[DllImport("__Internal")]
47+
private static extern string GetUserInfo();
48+
4349
private const string primaryKey = "ppid_session_dataname";
4450
private const string sortKey = "trial_num";
4551

@@ -67,8 +73,27 @@ public override void SetUp()
6773
string newSortKey = dl == UXFDataLevel.PerTrial ? sortKey : string.Empty;
6874
DDB_CreateTable(tableName, primaryKey, newSortKey, gameObject.name);
6975
}
76+
77+
if (collectBrowserInfo) AddBrowserInfo();
7078
}
7179

80+
void AddBrowserInfo()
81+
{
82+
string data = GetUserInfo();
83+
Dictionary<string, object> userInfo = (Dictionary<string, object>) MiniJSON.Json.Deserialize(data);
84+
foreach (var kvp in userInfo)
85+
{
86+
if (!session.participantDetails.ContainsKey(kvp.Key))
87+
{
88+
session.participantDetails.Add(kvp.Key, kvp.Value);
89+
Debug.LogFormat("{0}: {1}", kvp.Key, kvp.Value);
90+
}
91+
else
92+
{
93+
Debug.LogErrorFormat("participantDetails already contains key \"{0}\"!", kvp.Key);
94+
}
95+
}
96+
}
7297

7398
public override bool CheckIfRiskOfOverwrite(string experiment, string ppid, int sessionNum, string rootPath = "")
7499
{

Assets/UXF/Scripts/Session.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -316,28 +316,6 @@ public void Begin(string experimentName, string participantId, int sessionNumber
316316

317317
// raise the session events
318318
onSessionBegin.Invoke(this);
319-
320-
if (storeSessionSettings)
321-
{
322-
// copy Settings to session folder
323-
SaveJSONSerializableObject(new Dictionary<string, object>(settings.baseDict), "settings", dataType: UXFDataType.Settings);
324-
}
325-
326-
if (storeParticipantDetails)
327-
{
328-
// copy participant details to session folder
329-
// we convert to a DataTable because we know the dictionary will be "flat" (one value per key)
330-
331-
UXFDataTable ppDetailsTable = new UXFDataTable(participantDetails.Keys.ToArray());
332-
var row = new UXFDataRow();
333-
foreach (var kvp in participantDetails) row.Add((kvp.Key, kvp.Value));
334-
ppDetailsTable.AddCompleteRow(row);
335-
var ppDetailsLines = ppDetailsTable.GetCSVLines();
336-
337-
SaveDataTable(ppDetailsTable, "participant_details", dataType: UXFDataType.ParticipantDetails);
338-
}
339-
340-
341319
}
342320

343321
/// <summary>
@@ -638,12 +616,32 @@ public void End()
638616
try { CurrentTrial.End(); }
639617
catch (Exception e) { Debug.LogException(e); }
640618
}
641-
619+
642620
SaveResults();
643621

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

625+
if (storeSessionSettings)
626+
{
627+
// copy Settings to session folder
628+
SaveJSONSerializableObject(new Dictionary<string, object>(settings.baseDict), "settings", dataType: UXFDataType.Settings);
629+
}
630+
631+
if (storeParticipantDetails)
632+
{
633+
// copy participant details to session folder
634+
// we convert to a DataTable because we know the dictionary will be "flat" (one value per key)
635+
636+
UXFDataTable ppDetailsTable = new UXFDataTable(participantDetails.Keys.ToArray());
637+
var row = new UXFDataRow();
638+
foreach (var kvp in participantDetails) row.Add((kvp.Key, kvp.Value));
639+
ppDetailsTable.AddCompleteRow(row);
640+
var ppDetailsLines = ppDetailsTable.GetCSVLines();
641+
642+
SaveDataTable(ppDetailsTable, "participant_details", dataType: UXFDataType.ParticipantDetails);
643+
}
644+
647645
// end DataHandler - forces completion of tasks
648646
foreach (var dataHandler in ActiveDataHandlers) dataHandler.CleanUp();
649647

0 commit comments

Comments
 (0)