Home > database > ensemble_form_table.m

ensemble_form_table

PURPOSE ^

Prints responses to questions on a form out in tabular format

SYNOPSIS ^

function outvar = ensemble_form_table(data_st,params)

DESCRIPTION ^

 Prints responses to questions on a form out in tabular format

 ensemble_form_table(data_st,params)

 05/01/07 Petr Janata
 23Nov2011 PJ - improved conn_id handling, fixed handling of array of
 forms

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function outvar = ensemble_form_table(data_st,params)
0002 % Prints responses to questions on a form out in tabular format
0003 %
0004 % ensemble_form_table(data_st,params)
0005 %
0006 % 05/01/07 Petr Janata
0007 % 23Nov2011 PJ - improved conn_id handling, fixed handling of array of
0008 % forms
0009 outvar = [];
0010 
0011 try conn_id = params.conn_id; catch
0012     if isfield(params,'mysql')
0013         conn_id = params.mysql.conn_id;
0014     else
0015         try conn_id = params.ensemble.conn_id; catch
0016             conn_id = [];
0017         end
0018     end
0019 end
0020 
0021 % Make sure we have compqids
0022 data_st = ensemble_check_compqid(data_st);
0023 
0024 % Set column indexing variable
0025 cols = set_var_col_const(data_st.vars);
0026 
0027 form_ids = unique(data_st.data{cols.form_id});
0028 nforms = length(form_ids);
0029 
0030 % Extract form metadata
0031 form_data = mysql_extract_metadata('table','form', ...
0032     'form_id',form_ids, ...
0033     'conn_id', conn_id);
0034 
0035 dataformat = mysql_extract_metadata('table','data_format','conn_id',conn_id);
0036 
0037 % Generate subject masks
0038 [sub_mask_mtx, subids] = make_mask_mtx(data_st.data{cols.subject_id});
0039 nsub = length(subids);
0040 
0041 for iform = 1:nforms
0042   form_id = form_data(iform).form_id;
0043   form_mask = data_st.data{cols.form_id} == form_id;
0044   
0045   % Format things so that we can call ensemble_display_table
0046   table_data = ensemble_init_data_struct;
0047   table_data.vars = {'data','column_labels','column_formats'};
0048   tblcols = set_var_col_const(table_data.vars);
0049 
0050   for isub = 1:nsub
0051     
0052     nquest = length(form_data(iform).question);
0053     for iq = 1:nquest
0054       q = form_data(iform).question(iq);
0055       compqid = q.compqid;
0056       qid_mask = data_st.data{cols.compqid} == compqid;
0057       
0058       table_data.data{tblcols.column_labels}{iq} = q.question_text;
0059       
0060       % Make a composite mask
0061       compmask = form_mask & qid_mask & sub_mask_mtx(:,isub);
0062       if ~any(compmask)
0063                 continue
0064       end
0065       
0066       % Determine what type of data the question is
0067       df_idx = find([dataformat.data_format_id]==q.data_format_id);
0068       qtype = dataformat(df_idx).type;
0069       switch qtype
0070     case 'enum'
0071       qvals = dataformat(df_idx).enum_values;
0072       qdata = data_st.data{cols.response_enum}(compmask);
0073     switch q.html_field_type
0074       case 'checkbox'
0075         qdata = logical(data2bitmask(qdata));
0076       otherwise
0077         qdata = enum2data(qdata);
0078     end
0079       table_data.data{tblcols.data}{iq}{isub} = qvals(qdata); 
0080     case {'varchar','text'}
0081       table_data.data{tblcols.data}{iq}(isub) = ...
0082           data_st.data{cols.response_text}(compmask);
0083     case {'int16','int32','int64','double'}
0084       table_data.data{tblcols.data}{iq}(isub) = ...
0085           str2double(data_st.data{cols.response_text}(compmask));
0086     otherwise
0087       table_data.data{tblcols.data}{iq}{isub} = ...
0088           data_st.data{cols.response_text}(compmask);
0089       end
0090       
0091       % Set the column format
0092       switch qtype
0093     case {'enum','varchar','text'}
0094       table_data.data{tblcols.column_formats}{iq} = '%s';
0095     case {'int16','int32','int64'}
0096       table_data.data{tblcols.column_formats}{iq} = '%d';
0097     otherwise
0098       table_data.data{tblcols.column_formats}{iq} = '%1.4f';
0099       end
0100     end % for iquest =
0101     
0102   end % for isub=
0103   
0104   % Call the table display function
0105   ensemble_display_table(table_data, params);
0106   
0107 end % for iform=

Generated on Sat 24-Aug-2019 04:00:39 by m2html © 2003