Skip to content

Commit 66c159e

Browse files
committed
blank settings in CSV are not assigned
1 parent f66aa32 commit 66c159e

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

Assets/UXF/Scripts/Etc/SessionExtensions.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ namespace UXF
99
public static class SessionExtensions
1010
{
1111

12-
public static void TryBuildFromTable(this Session session, UXFDataTable table)
12+
/// <summary>
13+
/// Build the experiment using a UXFDataTable.
14+
/// The table is used to generate trials row-by-row, assigning a setting per column.
15+
/// </summary>
16+
/// <param name="session"></param>
17+
/// <param name="table"></param>
18+
public static void BuildFromTable(this Session session, UXFDataTable table)
1319
{
1420
if (table == null) throw new ArgumentNullException("table");
1521
if (session == null) throw new ArgumentNullException("session");
@@ -51,7 +57,13 @@ public static void TryBuildFromTable(this Session session, UXFDataTable table)
5157
// add all the columns to the settings for the trial
5258
foreach (var kvp in row)
5359
{
60+
// skip block_num
5461
if (kvp.Key == "block_num") continue;
62+
63+
// empty values do not assign a setting
64+
if (kvp.Value.ToString() == string.Empty) continue;
65+
66+
// add trial setting
5567
newTrial.settings.SetValue(kvp.Key, kvp.Value);
5668
}
5769

Assets/UXF/Scripts/SessionBuilders/CSVExperimentBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void BuildExperiment(Session session)
4545
// this adds a new trial to the session for each row in the table
4646
// the trial will be created with the settings from the values from the table
4747
// if "block_num" is specified in the table, the trial will be added to the block with that number
48-
session.TryBuildFromTable(table);
48+
session.BuildFromTable(table);
4949
}
5050
}
5151

Assets/UXF/Tests/Editor/TestBuildingFromCSV.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,39 @@ public void BuildTableFromCSV()
127127
}
128128
}
129129

130+
[Test]
131+
public void BuildFromTableWithBlankEntries()
132+
{
133+
UXFDataTable table = new UXFDataTable("some_text");
134+
135+
var row1 = new UXFDataRow();
136+
row1.Add(("some_text", "trial_string"));
137+
table.AddCompleteRow(row1);
138+
139+
var row2 = new UXFDataRow();
140+
row2.Add(("some_text", "")); // blank entry
141+
table.AddCompleteRow(row2);
142+
143+
session.BuildFromTable(table);
144+
145+
// set a session setting. session needs to be started to create session settings
146+
session.Begin("test", "test_ppid");
147+
session.settings.SetValue("some_text", "session_string");
148+
149+
// should be 2 trials
150+
Assert.AreEqual(2, session.Trials.Count());
151+
152+
// pull out the text
153+
string trial1text = session.GetTrial(1).settings.GetString("some_text");
154+
string trial2text = session.GetTrial(2).settings.GetString("some_text");
155+
156+
// check that the trial setting is correct
157+
Assert.AreEqual("trial_string", trial1text);
158+
159+
// check that the blank entry was ignored in place of the session setting
160+
Assert.AreEqual("session_string", trial2text);
161+
}
162+
130163
}
131164

132165
}

0 commit comments

Comments
 (0)