-
Notifications
You must be signed in to change notification settings - Fork 0
/
getLatestQuestParams.m
34 lines (32 loc) · 1.16 KB
/
getLatestQuestParams.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function questParams = getLatestQuestParams(sc)
% finds the latest quest data saved for subject sc
% sc is the hashed subject code
% TODO: use actual dates as opposed to session number to fetch the latest
% parameters, and check whether latest parameters were collected today or
% not.
filename = 'subj_metadata.json';
ds = loadjson(filename);
if isfield(ds, sc)
currDs = ds.(sc); % struct for this subject
sessionNames = fieldnames(currDs); % cell array of field names
numSessions = length(fieldnames(currDs));
questParams = [];
datesArray = cell(size(sessionNames));
% display the blocks completed by the subject and their date
for s = 1:numSessions
session = sessionNames{s};
% disp(session)
sessStruct = currDs.(session);
datesArray{s} = sessStruct.sessionTag;
if isfield(sessStruct, 'Quest')
if sessStruct.Quest.completed
% just override previous write to questParams to get the
% latest
questParams = sessStruct.Quest.QuestFit;
end
end
end
else
error('subject code not found in metadatafile')
end
end