function [Nstudent, Percent, Average] = ...
    assess_performance(FileName,MaxScore,Standard)

%[Nstudent,Percent,Average]=assess_performance(FileName,MaxScore,Standard)
%
%Nstudent - # of students meeting the standard
%Percent - % of students meeting the standard
%Average - the average percentage score per assignment
%
%FileName (string) is the name of the Excel Spreadsheet (without file
%extension)
%
%MaxScore is the vector of maximum scores for the individual assignments in
%Merge.xlsx or BME.xlsx or BMEP.xlsx (or whatever Major you are filtering
%in).
%The order of elements in MaxScore must match the order of assignments, e.g
%[hw#1, hw#2, ... , midterm, ... , final]
%If for all of your assignments the maximum score is 100, you should pass
%an empty matrix, i.e. MaxScore = [];
%
%Standard is a number between 0 and 100 that represents a performance
%standard given in %
%
%Zoran Nenadic, UC Irvine

[num,txt] = xlsread([num2str(FileName) '.xlsx']);

[Ns, Na] = size(num);

disp(['Number of students: ' num2str(Ns)])
disp(['Number of assignments: ' num2str(Na)])

AvgScore = mean(num,1);
if isempty(MaxScore)
    MaxScore = 100*ones(1,Na);
end
PerCentMax = AvgScore./MaxScore*100;
PI = MaxScore*Standard/100;
for i = 1:Na
    Ns_ms(i) = sum(num(:,i) > PI(i));
end

fid = fopen([num2str(FileName) '_assessment.txt'],'wt');
fprintf(fid,'%s\t%s\t%s\t%s\t%s\n','Assignment','Max. score', ...
    'PI %max','Avg. score %max','#&%stud.>stand.');

for i = 1:Na
    fprintf(fid,'%s\t',cell2mat(txt(1,i+1)));
    fprintf(fid,'%3d\t',MaxScore(i));
    fprintf(fid,'%3.2f ',PI(i));
    fprintf(fid,'%s%2.2f%s\t','(',Standard,'%)');
    fprintf(fid,'%3.2f ',AvgScore(i));
    fprintf(fid,'%s%2.2f%s\t','(',PerCentMax(i),'%)');
    fprintf(fid,'%3d ',Ns_ms(i));
    fprintf(fid,'%s%2.2f%s\n','(',Ns_ms(i)/Ns*100,'%)');
end
fclose(fid);

Nstudent = Ns_ms;
Percent = Ns_ms/Ns*100;
Average = PerCentMax;