Home > database > ensemble_completion_info.m

ensemble_completion_info

PURPOSE ^

Returns completion statistics for a given data set.

SYNOPSIS ^

function [out_st] = ensemble_completion_info(data_st,params)

DESCRIPTION ^

 Returns completion statistics for a given data set.
 [out_st] = ensemble_completion_info(data_st,params);

 Returns various completion statistics that can be garnered from the data
 table provided in data_st.  The fields in the params structure control the
 behavior of this function.

 .filt - applies filtering based on fields in the exclude and include structures

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [out_st] = ensemble_completion_info(data_st,params)
0002 % Returns completion statistics for a given data set.
0003 % [out_st] = ensemble_completion_info(data_st,params);
0004 %
0005 % Returns various completion statistics that can be garnered from the data
0006 % table provided in data_st.  The fields in the params structure control the
0007 % behavior of this function.
0008 %
0009 % .filt - applies filtering based on fields in the exclude and include structures
0010 
0011 out_st.type = 'ensemble_completion_info';
0012 out_st.vars = {};
0013 out_st.data = {};
0014 
0015 % Apply any specified filtering to the input data
0016 if isfield(params,'filt')
0017   data_st = ensemble_filter(data_st, params.filt);
0018 end
0019 
0020 % Get the column constants
0021 INCOL = set_form_col_const(data_st.vars);
0022 
0023 % By default, organize information by session_id
0024 if isempty(INCOL.SESS_ID)
0025   fprintf('ensemble_completion_info: Could not find session_id variable\n');
0026   return
0027 end
0028 
0029 % Generate a list of output variables. This should be done dynamically based on
0030 % requested information to compute, but for now it is a fixed list
0031 out_vars = {'session_id','start_time','stop_time','elapsed_time','form_id'};
0032 outcol = set_var_col_const(out_vars);
0033 
0034 out_st.vars = out_vars;
0035 sesslist = unique(data_st.data{INCOL.SESS_ID});
0036 out_st.data{outcol.session_id} = sesslist;
0037 
0038 % Pull the data for each session
0039 nsess = length(sesslist);
0040 
0041 for isess = 1:nsess
0042   % Generate a session mask
0043   sess_mask = data_st.data{INCOL.SESS_ID} == sesslist(isess);
0044   sess_idxs = find(sess_mask);
0045   
0046   % Get the start time
0047   start_time = min(data_st.data{INCOL.DATE_TIME}(sess_mask));
0048   out_st.data{outcol.start_time}(isess) = start_time;
0049 
0050   % Get the stop time
0051   [stop_time, stop_idx] = max(data_st.data{INCOL.DATE_TIME}(sess_mask));
0052   out_st.data{outcol.stop_time}(isess) = stop_time;
0053   
0054   % Get the elapsed time
0055   elapsed_time = etime(datevec(stop_time),datevec(start_time));
0056   out_st.data{outcol.elapsed_time}(isess) = elapsed_time;
0057   
0058   % Get the form ID of the last form
0059   last_form_id = data_st.data{INCOL.FORM_ID}(sess_idxs(stop_idx));
0060   out_st.data{outcol.form_id}(isess) = last_form_id;
0061 
0062 end % for isess=
0063 
0064 % Calculate various summary statistics
0065 report.min_time = min(out_st.data{outcol.elapsed_time});
0066 report.max_time = max(out_st.data{outcol.elapsed_time});
0067 report.mean_time = mean(out_st.data{outcol.elapsed_time});
0068 report.std_time = std(out_st.data{outcol.elapsed_time});
0069 report.median_time = median(out_st.data{outcol.elapsed_time});
0070 
0071 %
0072 % Generate plots and tables if desired
0073 %
0074 if isfield(params,'display')
0075   if isfield(params.display, 'figs')
0076     figtypes = fieldnames(params.display.figs);
0077     ntypes = length(figtypes);
0078     for itype = 1:ntypes
0079       curtype = figtypes{itype};
0080       st = params.display.figs.(curtype);
0081       switch curtype
0082     case 'hist'  % histogram of elapsed times
0083       try hist_min = st.min_time; catch hist_min = 0; end
0084       try hist_max = st.max_time; catch hist_max = report.max_time; end
0085       try nbins = st.nbins; catch nbins=20; end
0086       try doplot = st.plot; catch doplot=1; end
0087       try tick_interval = st.tick_interval; catch tick_interval=15; end
0088       
0089       histscale = linspace(hist_min,hist_max,nbins);
0090       histdata = histc(out_st.data{outcol.elapsed_time}, histscale);
0091       histscale = histscale/60;
0092       report.hist.xscale = histscale;
0093       report.hist.data = histdata;
0094       
0095       if doplot
0096         figure
0097         bar(histscale,histdata)
0098         set(gca,'xtick',min(histscale):tick_interval:max(histscale), ...
0099         'xlim',[min(histscale) max(histscale)])
0100         report.hist.axes = gca;
0101       end
0102       end % switch curtype
0103     end % for itype = 1:ntypes
0104   end % if isfield(params.display, 'figs')
0105   
0106   if isfield(params.display, 'tables')
0107     if isfield(params.display.tables,'group_stats') && ...
0108       params.display.tables.group_stats
0109       fprintf('\nCompletion time statistics\n');
0110       fprintf('Minimum elapsed time (min): %1.2f\n', report.min_time/60);
0111       fprintf('Maximum elapsed time (min): %1.2f\n', report.max_time/60);
0112       fprintf('Mean elapsed time(min): %1.2f\n', report.mean_time/60);
0113       fprintf('Std. dev elapsed time(min): %1.2f\n', report.std_time/60);
0114       fprintf('Median elapsed time(min): %1.2f\n', report.median_time/60);
0115       
0116     end
0117   end % if isfield(params.display, 'tables')
0118 end % if isfield(params,'display')
0119 
0120 out_st.report = report;

Generated on Sat 25-May-2019 04:00:51 by m2html © 2003