0001 function outdata = ensemble_get_student_id(indata,params)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 outdata = ensemble_init_data_struct();
0021 outdata.name = 'student_ids';
0022 outdata.type = 'student_ids';
0023 outdata.vars = {'subject_id','student_id'};
0024 outdata.data = {{} {}};
0025 ocol = set_var_col_const(outdata.vars);
0026
0027
0028 incol = set_var_col_const(indata.vars);
0029 if ~isfield(incol,'subject_id'), error('no subid found within indata'); end
0030 if ~isfield(incol,'response_text'), error('response text not found'); end
0031
0032
0033 if isfield(params,'student_id_qid') && ~isempty(params.student_id_qid)
0034 siqid = params.student_id_qid;
0035 else
0036 siqid = 558;
0037 end
0038 filt.include.all.question_id = siqid
0039 indata = ensemble_filter(indata,filt);
0040
0041
0042 if isempty(indata.data{1})
0043 error('no student IDs (question %d) found in the given dataset',siqid);
0044 end
0045
0046
0047 [sm,us] = make_mask_mtx(indata.data{incol.subject_id});
0048 ns = length(us);
0049 if any(sum(sm) > 1), warning('multiple records for some subjects'); end
0050
0051
0052 for is=1:ns
0053 subid = us{is};
0054 sids = indata.data{incol.response_text}(sm(:,is));
0055 if length(sids) > 1
0056 warning('multiple student ids found for %s, taking first',subid);
0057 sids = sids(1);
0058 end
0059 outdata = ensemble_add_data_struct_row(outdata,'subject_id',subid,...
0060 'student_id',sids);
0061 end