Plugins-sqlsummary

From Bcontrol

Revision as of 00:31, 16 April 2009 by Bwen (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

There are four functions supported by the sqlsummary plugin:

Contents

[edit] getSessID

getSessID returns the session id that is the unique id that identifies the current session in the mysql server. If no session id exists it gets one.

function x=getSessID(obj)
GetSoloFunctionArgs(obj);
if ~exist('sessid','var')
  SoloParamHandle(obj,'sessid','value',-1);
end
if value(sessid)==-1
 try	
   bdata('insert into sess_list () values ()');
   x=bdata('select last_insert_id()');
   sessid.value=x;
 catch
   sessid.value=-1;
 end
else
 x=value(sessid);
end

[edit] sendsummary

 sendsummary(obj);

will send a summary of your session to a mysql server.

 function [err]=sendsummary(obj, varargin)
 pairs = { ...
 		'hits'			get_val('hit_history');...
 		'sides'			get_val('previous_sides');...
 		'endtime'		datestr(now,13);...
 		'sessiondate'		datestr(now,29);...
 		'hostname'		get_val('SavingSection_hostname');...
 		'experimenter'		get_val('SavingSection_experimenter');...
 		'ratname'		get_val('SavingSection_ratname');...
 		'n_done_trials'		get_val('n_done_trials');...
 		'protocol'		class(obj);...
 		'protocol_data'		'NULL'
 		}; parseargs(varargin, pairs);
 %% Get the relevant SPH
 
 total_correct=nanmean(hits);
 right_correct=nanmean(hits(sides=='r'));
 left_correct=nanmean(hits(sides=='l'));
 percent_violations=mean(isnan(hits));

With no extra arguments sendsummary tries to generate a summary making the following assumptions:

  1. There is a SoloParamHandle named hit_history that contains a numeric array containing a 1 for every correct trial, a 0 for incorrect trials and NaN for trials that should not be treated as correct or incorrect.
  2. There is a SoloParamHandle named previous_sides that contains a string of l's and r's to indicate whether the correct response was towards the left or the right.
  3. That the @saveload plugin is being used.

You can still use this function if the above assumptions are false. In this case, pass in the appropriate information as parameters.

For example, you don't have an SPH called previous_sides but rather you store this information in sides_history and it is made up of -1's and 1's. In this case, write a little bit of code to transform your sides_history into a string of l's and r's and then send the string as an argument to sendsummary.

 lets={'l' 'c' 'r'};
 sides=cell2mat(lets(sides_history+2));
 sendsummary(obj, 'sides',sides)

The other feature worth noting is the protocol_data field. You can build any struct or cell array you like and pass it in. For example:

 pd.context=value(previous_cntxt);
 pd.blocks=value(block_history);
 pd.sides=value(previous_sides);
 pd.gotit=value(gotit_history);
 pd.hit=value(hit_history);
 pd.RT=value(RT);
 sendsummary(obj,'protocol_data',pd)

The advantage of this is that you can then write code that grabs the protocol_data for a specific set of sessions and runs through some analysis without having to load the entire data file for each session. This could significantly simplify analysis of behavior and replace hunt. The only constraint is that you cannot use sparse matrices in this field. This is a limitation of mym.


NOTE: Currently this functionality is only supported for the Brody Lab. Users outside of the brody lab must set up a mysql server for their lab and replace the bdata.p file found in ExperPort/MySQLUtility using bdata_template.m.

Jerlich 20:23, 29 December 2007 (EST)

[edit] sendtrial

The sendtrial function can only take a single input - the protocol object.

 % [] = sendtrial(obj)
 %
 % Pushes the scalar soloparamhandles for all trials to a table with the protocol name
 %
 %
 % PARAMETERS:
 % ----------
 %
 % obj     This is the protocol object
 %

This function would normally be called in the pre_saving_settings section of your protocol. That way after the behavioral session is done and the data has been saved to disk, then this function sends data to the mysql server.

In order for this function to work a table with the protocol name needs to be created in the protocol schema on the mysql server.

An example script for building such a table can be viewed in ExperPort/Analysis/ExtendedStimulus/build_es_table.m

After building the table, one should go through the table by hand using the mysql query browser and eliminate columns that are clearly not of interest or of incompatible type.

[edit] push_helper_vars_tosql

The push_helper_vars_tosql function takes two inputs - the protocol object and n_done_trials.

This function should be called in the prepare_next_trial section of your protocol after updating n_done_trials but before evaluating the training string in SessionDefinition (which recomputes the helper vars for the next trial). It gets all the helper vars and their values for the previous (just completed) trial, and for the ones whose "save_to_helper_vars_table" user property is 1, sends them to the protocol.helper_vars tables in the SQL database.

Personal tools