小聪明的设计其实是大愚昧,不直观的(让人费解的)设计会造成后期的麻烦。 这里视图从文件名中解析信息。 并在表格文件中追加一个冗余行,存储一些额外信息。(反人类思维设计)
代码设计要符合大众思维。
不用过度地开放,有时候固定一些更好。用户用到的API也就那么几个,很多东西都没必要修改也没人关心,东西好用就好,代码简单好维护就好!
classdef Test
methods (Static)
function [dataType, algoList] = readReportName(filename)
[dataType, algo] = strtok(filename);
algoName = strsplit(algo, '-');
for n = numel(algoName):-1:1
algoList(n).name = algoName{n};
algoList(n).func = str2func(algoName{n});
end
end
% 'dataType algoName1_algoName2_algoName3'
function filename = writeReportName(dataType, algoList)
algoName = strjoin({algoList.name}, '-');
filename = strjoin({dataType, algoName}, ' ');
end
function demo()
% test all
t = Test(@lime, @amsr, @dong, @bpdhe, @dheci, @he);
t.in_terms_of(@ambe,@loe,@entropy,@cni,@cci,@cm,@niqe,@brisque);
t.on_image('#dataset\#new\ColourCharts\*.tiff');
boxplot(t);
end
end
methods
function this = readtable(this, file)
t = readtable(file);
this.dataPath = t(end,1);
t(end,:) = [];
this.table = t;
% update
[~, name, ~] = fileparts(file);
[this.dataType, this.algoList] = this.readReportName(name);
this.evalList = struct('name', this.table.Properties.VariableNames(3:end));
for n = numel(this.evalList):-1:1
this.evalList(n).func = str2func(this.evalList(n).name);
end
end
function this = writetable(this, path) %
t = this.table;
t(end+1,1) = this.dataPath;
name = this.writeReportName(this.dataType, this.algoList);
writetable(t, [path,filesep,name,ext]);
end
end
end