Home > database > legacy > extract_sess.m

extract_sess

PURPOSE ^

Extracts session information for a given session.

SYNOPSIS ^

function [table] = extract_sess(resp_tbl, sessids, conn_id)

DESCRIPTION ^

 Extracts session information for a given session.
 [table] = extract_sess(resp_tlb, sessids, conn_id);

 Extracts all data associated with a specific session or list of sessions from
 an experiment response table.

 Also retrieves associated question information.

 resp_tbl -- name of table to extract response data from. 
 sessids - vector of session IDs to extract.  If sessids is empty, all
           information is extracted.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [table] = extract_sess(resp_tbl, sessids, conn_id)
0002 % Extracts session information for a given session.
0003 % [table] = extract_sess(resp_tlb, sessids, conn_id);
0004 %
0005 % Extracts all data associated with a specific session or list of sessions from
0006 % an experiment response table.
0007 %
0008 % Also retrieves associated question information.
0009 %
0010 % resp_tbl -- name of table to extract response data from.
0011 % sessids - vector of session IDs to extract.  If sessids is empty, all
0012 %           information is extracted.
0013 %
0014 
0015 % 06/22/06 PJ - adapted from extract_resp_tbl.m
0016 
0017 global SQL_HOST DATABASE
0018 
0019 if nargin < 1
0020   fprintf('extract_sess: Name of response table not specified');
0021   table = struct([]);
0022   return
0023 end
0024 
0025 try sessids(1);
0026 catch  sessids = [];
0027 end
0028 
0029 % Connect to default host and database if no connection ID is specified
0030 try conn_id(1);
0031 catch   
0032   mysql_make_conn;
0033   conn_id = 0;
0034 end
0035 
0036 %
0037 % Determine which forms are associated with this experiment
0038 %
0039 
0040 nid = length(sessids)
0041 for iid = 1:nid
0042   curr_sessid = sessids(iid);
0043   
0044   sql_str = sprintf(['SELECT DISTINCT form.form_id, form_name FROM form,%s ' ...
0045     'WHERE form.form_id=%s.form_id AND %s.session_id=%d'], resp_tbl, resp_tbl, resp_tbl, curr_sessid);
0046   [form_ids,form_names] = mysql(conn_id,sql_str);  % get the form ids
0047 
0048 %  [form_names, idxs] = unique(form_names);
0049 %  form_ids = form_ids(idxs);
0050   
0051   table{iid}.forms.names = form_names;
0052   table{iid}.forms.ids = form_ids;
0053 
0054   %
0055   % Loop through all of the forms and extract the data
0056   %
0057 
0058   nforms = length(form_names);
0059   fprintf('Found %d forms\n', nforms);
0060   table{iid}.forms.data = cell(nforms,1);
0061   for iform = 1:nforms
0062     curr_form = form_names{iform};
0063     
0064     fprintf('Processing form: %s\n', curr_form);
0065     switch curr_form
0066       case 'PANAS Survey2'
0067     table{iid}.forms.data(iform) = extract_panas(expt, subids, resp_tbl, conn_id);
0068       otherwise
0069     fprintf('Using generic handling for form: %s\n', curr_form);
0070     table{iid}.forms.data(iform) = extract_formdata(resp_tbl, form_ids(iform), ...
0071         'conn_id', conn_id, ...
0072         'sessids', curr_sessid);
0073     end % switch curr_form
0074   end % for  iform=
0075 end % for iid
0076 
0077 if ~conn_id
0078   mysql(conn_id, 'close');
0079 end
0080 
0081 return

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