% generate statistics report
%
% the following programs need to be run first
%
% readsenselabaccess % creates the access_* cells of raw data
% mknondevlog % creates the log_* cells of non developer data
% then 
%
crlf=[char(13) char(10)]; 
disp(['Senselab Statistics from ' char(access_time(1)) ' to ' char(access_time(numofcells))])
disp(['Total number of hits in raw access.log: ' int2str(numofcells)])
disp(['Number of hits excluding developer ips: ' int2str(numinlog)])
disp(['Number of hits from developer ips: ' int2str(numofcells-numinlog) crlf])

% calculate top models downloaded
num_of_models=1000; % gets reset later to correct number after processing
down_obj_id=cell(1,num_of_models); % record the name of the model - for starters just as
                      % the query from a download
num_of_downloads=zeros(1,num_of_models);
found_models=0;
for i=1: numinlog

    if findstr('down',char(log_page(i)))
        % first see if already have obj id in down_obj_id cell
        incr_model=0;   % change to index if model already appeared
        % find object id number to compare in list
        tmp=char(log_query(i));
        y=findstr('m_id=',tmp);
        offset=5;
        if length(y)==0
            y=findstr('o=',tmp);
            offset=2;    
        end
        ampersand_pos=findstr('&',tmp);
        obj_id='';
        if length(y)
            if ampersand_pos
                obj_id=tmp(y(1)+offset:ampersand_pos(1)-1);
            else
                obj_id=tmp(y(1)+5:end);
            end
        end
        for j=1:found_models
            if strcmp(obj_id,char(down_obj_id(j)))
                % j is the index to be incremented
                incr_model=j;
            end
        end
        if incr_model
            num_of_downloads(incr_model)=num_of_downloads(incr_model)+1;
        else
            found_models=found_models+1;
            down_obj_id(found_models)=cellstr(obj_id);
            num_of_downloads(found_models)=num_of_downloads(found_models)+1;
        end
    end
end
num_of_models=found_models;


