% REPO_TEST_OBJ_NUMBER Test repository submission/retrieval of different
% number of AOs of the same size
%
% M HUeller 05-12-08
%
% $Id: repo_test_obj_number.m,v 1.7 2009/03/02 16:28:19 mauro Exp $
%
function results = repo_test_obj_number()
  
  %% Prepares the plist for AOs
  NSECS = 3.6e3;
  
  %   nobjs = [linspace(1,10,10) linspace(20,100,9) linspace(200,1000,9)]';
  nobjs = [linspace(1,10,10) linspace(20,60,3)]';
  
  NOBJS_STEPS = length(nobjs);
  
  n_freqs = 10;
  fs  = 10;
  f_m = linspace(0.001, 0.01, n_freqs);
  A = linspace(0.1, 1, n_freqs);
  phi = linspace(0, pi, n_freqs);
  
  pl_ao = plist('waveform', 'sine wave', ...
    'fs', fs, ...
    'f', f_m, ...
    'A', A, ...
    'phi', phi, ...
    'nsecs', NSECS);
  
  
  
  %% Prepares a plist with the needed parameters
  pl_run = plist('RAND_N_OBJ',      false, ...
    'N_OBJ',           [], ...
    'OBJ_TYPE',        'ao', ...
    'RAND_AO',         false, ...
    'AO_PARAMS',       pl_ao, ...
    'HOSTNAME',        'btlab.science.unitn.it', ...
    'DBASE',           'ltpda_test', ...
    'SAVE_OBJS',       false, ...
    'SUBMIT',          true, ...
    'CONN',            [], ...
    'SAVE_RESULTS',    false, ...
    'DIR',             [], ...
    'RESULTS_FILENAME','repo_test' ...
    );
  
  % Empty arrays for the results
  results = cell(NOBJS_STEPS, 1);
  ret_time_xml = zeros(NOBJS_STEPS, 1);
  ret_time_bin = zeros(NOBJS_STEPS, 1);
  sub_time = zeros(NOBJS_STEPS, 1);
  
  %% Runs the tests with AOs
  
  for kk = 1 : NOBJS_STEPS
    results{kk} = repo_test_func(pl_run.pset('N_OBJ', nobjs(kk)));
  end
  
  %% Puts together a report
  import utils.const.*
  utils.helper.msg(msg.MNAME, '%s\n%s\n%s\n%s\n%s\n%s\n%s', ...
    '  ','%%%%%%%%%%%%%','  ',...
    ['Test started at: ' datestr(find(results{1}, 'start_time')) ...
    ' and ended at: ' datestr(find(results{end}, 'stop_time'))], ...
    '  ','%%%%%%%%%%%%%','  ');
  
  % TODO: add more info here (which repo etc)
  
  % Collects the results into a matrix
  for kk = 1 : NOBJS_STEPS
    ret_time_xml(kk) = find(results{kk}, 'ret_time_xml');
    ret_time_bin(kk) = find(results{kk}, 'ret_time_bin');
    sub_time(kk)     = find(results{kk}, 'sub_time');
  end
  
  % Plot submit times for objects as a function of number of objects
  fig_sub_time = figure;
  plot(nobjs, sub_time, 'b.');
  hold on;
  grid on;
  
  xlabel('Number of objs []');
  ylabel('Submit time [s]');
  title(['AO, fs = ' num2str(fs) ' nsecs = ' num2str(NSECS) ' s']);
  legend('XML + Binary submission');
  
  
  % Plot retrieval times for objects as a function of object size
  fig_ret_time = figure;
  plot(nobjs, ret_time_xml, 'b.');
  hold on;
  plot(nobjs, ret_time_bin, 'r.');
  grid on;
  
  xlabel('Number of objs []');
  ylabel('Retrieval time [s]');
  title(['AO, fs = ' num2str(fs) ' nsecs = ' num2str(NSECS) ' s']);
  legend('XML retrieval','Binary retrieval');
  
  
end
% END