Home > database > archived_scripts > extract_generic.m

extract_generic

PURPOSE ^

[data] = extract_generic(resp_tbl, form_id, extract_vars, subids, conn_id);

SYNOPSIS ^

function [data] = extract_generic(resp_tbl,form_id,extract_vars, subids, conn_id)

DESCRIPTION ^

 [data] = extract_generic(resp_tbl, form_id, extract_vars, subids, conn_id);

 Generic data extraction for data associated with a specfic form in an
 experiment response table in the database.

 extract_vars - cell string containing optional list of fields to extract

 subids - subjects to process

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [data] = extract_generic(resp_tbl,form_id,extract_vars, subids, conn_id)
0002 % [data] = extract_generic(resp_tbl, form_id, extract_vars, subids, conn_id);
0003 %
0004 % Generic data extraction for data associated with a specfic form in an
0005 % experiment response table in the database.
0006 %
0007 % extract_vars - cell string containing optional list of fields to extract
0008 %
0009 % subids - subjects to process
0010 %
0011 
0012 % 03/07/05 PJ
0013 
0014 global SQL_HOST DATABASE
0015 
0016 % Check for connection to database
0017 try conn_id(1);
0018 catch   
0019   mysql_make_conn;
0020   conn_id = 0;
0021 end
0022 
0023 try 
0024   extract_vars{1}; 
0025 catch
0026   extract_vars = {...
0027     'subject_id', ...
0028     'stimulus_id', ...
0029     'date_time', ...
0030     'question_id', ...
0031     'subquestion', ...
0032     'question_iteration', ...
0033     'response_id', ...
0034     'response_enum', ...
0035     'response_text' ...
0036     };
0037 end
0038     
0039 data.vars = extract_vars;
0040 
0041 try subids(1);
0042   subject_str = sprintf('subject_id="%s" OR ', subids{:});
0043   subject_str(end-3:end) = [];
0044   subject_str = sprintf('AND (%s)', subject_str);
0045 catch
0046   subject_str = '';
0047 end
0048   
0049 % Extract the data
0050 sql_str = sprintf('select %s from %s where form_id=%d %s ;', cell2str(extract_vars,','), resp_tbl, form_id, subject_str);
0051 [data.data{1:length(extract_vars)}] = mysql(conn_id,sql_str);
0052 
0053 % Resolve the question IDs to get the associated question text
0054 sql_str = sprintf(['SELECT question_text FROM question,%s WHERE' ...
0055       ' question.question_id=%s.question_id AND %s.form_id=%d %s ;'], resp_tbl, resp_tbl, resp_tbl, form_id, subject_str);
0056 [qtxt] = mysql(conn_id,sql_str);
0057 data.vars{end+1} = 'question_text';
0058 data.data{end+1} = qtxt;
0059 
0060 % Get the subquestion text
0061 sql_str = sprintf(['SELECT heading FROM' ...
0062       ' question_x_data_format,%s WHERE' ...
0063       ' question_x_data_format.question_id=%s.question_id AND' ...
0064       ' question_x_data_format.subquestion=%s.subquestion AND %s.form_id=%d %s;'], ...
0065     resp_tbl, resp_tbl, resp_tbl, resp_tbl, form_id, subject_str);
0066 [heading] = mysql(conn_id,sql_str);
0067 data.vars{end+1} = 'heading';
0068 data.data{end+1} = heading;
0069 
0070 if ~conn_id
0071   mysql(conn_id,'close');
0072 end
0073 
0074 return

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003