Skip to content

Commit 8967187

Browse files
ENH - print table that compares matlab version or fieldtrip version test results, sorted by comparison (i.e. passed/failed is the most interesting)
1 parent c5b13a7 commit 8967187

File tree

1 file changed

+107
-20
lines changed

1 file changed

+107
-20
lines changed

utilities/ft_test_result.m

Lines changed: 107 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
% FT_TEST_RESULT checks the status of selected test scripts on the FieldTrip dashboard
44
%
5-
% Use as
6-
% ft_test_result
5+
% To get all dashboard results as a structure array, you would do
6+
% result = ft_test_result
77
%
8-
% Query arguments are specified as key-value pairs and can include
8+
% To print a table with the results on screen, you would do
9+
% ft_test_result comparerevision ea3c2b9 314d186
10+
% ft_test_result comparematlab 2015b 2016b
11+
%
12+
% Additional query arguments are specified as key-value pairs and can include
913
% matlabversion = string
1014
% fieldtripversion = string
1115
% hostname = string
1216
% user = string
13-
%
14-
% To get a list of all distinct values of a certain parameter, you specify
15-
% distinct = string
17+
% branch = string
18+
% result = string
1619
%
1720
% See also FT_TEST_RUN, FT_VERSION
1821

@@ -39,18 +42,27 @@
3942
% set the default
4043
command = 'query';
4144

42-
if nargin>0 && isequal(varargin{1}, 'compare')
43-
% compare rev1 rev2
44-
command = varargin{1};
45-
revision1 = varargin{2};
46-
revision2 = varargin{3};
47-
varargin = varargin(4:end);
45+
if nargin>0
46+
if isequal(varargin{1}, 'compare') || isequal(varargin{1}, 'comparerevision')
47+
% comparerevision rev1 rev2
48+
command = 'comparerevision';
49+
arg1 = varargin{2};
50+
arg2 = varargin{3};
51+
varargin = varargin(4:end);
52+
elseif isequal(varargin{1}, 'matlab') || isequal(varargin{1}, 'comparematlab')
53+
% comparematlab ver1 ver2
54+
command = 'comparematlab';
55+
arg1 = varargin{2};
56+
arg2 = varargin{3};
57+
varargin = varargin(4:end);
58+
end
4859
end
4960

5061
% construct the query string
5162
query = '?';
5263

53-
queryparam = {'matlabversion', 'fieldtripversion', 'hostname', 'user', 'functionname', 'distinct'};
64+
% the 'distict' parameter is mutually exclusive with all others
65+
queryparam = {'matlabversion', 'fieldtripversion', 'hostname', 'user', 'functionname', 'result', 'branch', 'distinct'};
5466
for i=1:numel(queryparam)
5567
val = ft_getopt(varargin, queryparam{i});
5668
if ~isempty(val)
@@ -63,23 +75,98 @@
6375
switch command
6476
case 'query'
6577
results = webread(['http://dashboard.fieldtriptoolbox.org/api/' query], options);
66-
67-
case 'compare'
68-
dashboard1 = webread(['http://dashboard.fieldtriptoolbox.org/api/' query sprintf('&fieldtripversion=%s', revision1)], options);
69-
dashboard2 = webread(['http://dashboard.fieldtriptoolbox.org/api/' query sprintf('&fieldtripversion=%s', revision2)], options);
78+
79+
case 'comparerevision'
80+
dashboard1 = webread(['http://dashboard.fieldtriptoolbox.org/api/' query sprintf('&fieldtripversion=%s', arg1)], options);
81+
dashboard2 = webread(['http://dashboard.fieldtriptoolbox.org/api/' query sprintf('&fieldtripversion=%s', arg2)], options);
7082
assert(~isempty(dashboard1), 'no tests were returned for the first revision');
7183
assert(~isempty(dashboard2), 'no tests were returned for the second revision');
7284
functionname1 = {dashboard1.functionname};
7385
functionname2 = {dashboard2.functionname};
7486
functionname = unique(cat(2, functionname1, functionname2));
7587
n = max(cellfun(@length, functionname));
88+
line = cell(size(functionname));
89+
order = nan(size(functionname));
90+
for i=1:numel(functionname)
91+
sel1 = find(strcmp(functionname1, functionname{i}));
92+
sel2 = find(strcmp(functionname2, functionname{i}));
93+
res1 = getresult(dashboard1, sel1);
94+
res2 = getresult(dashboard2, sel2);
95+
line{i} = sprintf('%s : %s in %s, %s in %s\n', padto(functionname{i}, n), res1, arg1, res2, arg2);
96+
97+
% determine the order
98+
if strcmp(res1, 'passed') && strcmp(res2, 'passed')
99+
order(i) = 1;
100+
elseif strcmp(res1, 'failed') && strcmp(res2, 'failed')
101+
order(i) = 2;
102+
elseif strcmp(res1, 'missing') && strcmp(res2, 'passed')
103+
order(i) = 3;
104+
elseif strcmp(res1, 'passed') && strcmp(res2, 'missing')
105+
order(i) = 4;
106+
elseif strcmp(res1, 'missing') && strcmp(res2, 'failed')
107+
order(i) = 5;
108+
elseif strcmp(res1, 'failed') && strcmp(res2, 'missing')
109+
order(i) = 6;
110+
elseif strcmp(res1, 'failed') && strcmp(res2, 'passed')
111+
order(i) = 7;
112+
elseif strcmp(res1, 'passed') && strcmp(res2, 'failed')
113+
order(i) = 8;
114+
else
115+
order(i) = 9;
116+
end
117+
end % for each functionname
118+
119+
[order, index] = sort(order);
120+
line = line(index);
121+
for i=1:length(line)
122+
fprintf(line{i});
123+
end
124+
125+
case 'comparematlab'
126+
dashboard1 = webread(['http://dashboard.fieldtriptoolbox.org/api/' query sprintf('&matlabversion=%s', arg1)], options);
127+
dashboard2 = webread(['http://dashboard.fieldtriptoolbox.org/api/' query sprintf('&matlabversion=%s', arg2)], options);
128+
assert(~isempty(dashboard1), 'no tests were returned for the first matab version');
129+
assert(~isempty(dashboard2), 'no tests were returned for the second matab version');
130+
functionname1 = {dashboard1.functionname};
131+
functionname2 = {dashboard2.functionname};
132+
functionname = unique(cat(2, functionname1, functionname2));
133+
n = max(cellfun(@length, functionname));
134+
line = cell(size(functionname));
135+
order = nan(size(functionname));
76136
for i=1:numel(functionname)
77137
sel1 = find(strcmp(functionname1, functionname{i}));
78138
sel2 = find(strcmp(functionname2, functionname{i}));
79139
res1 = getresult(dashboard1, sel1);
80140
res2 = getresult(dashboard2, sel2);
81-
fprintf('%s : %s in %s, %s in %s\n', padto(functionname{i}, n), res1, revision1, res2, revision2);
82-
end % for
141+
line{i} = sprintf('%s : %s in %s, %s in %s\n', padto(functionname{i}, n), res1, arg1, res2, arg2);
142+
143+
% determine the order
144+
if strcmp(res1, 'passed') && strcmp(res2, 'passed')
145+
order(i) = 1;
146+
elseif strcmp(res1, 'failed') && strcmp(res2, 'failed')
147+
order(i) = 2;
148+
elseif strcmp(res1, 'missing') && strcmp(res2, 'passed')
149+
order(i) = 3;
150+
elseif strcmp(res1, 'passed') && strcmp(res2, 'missing')
151+
order(i) = 4;
152+
elseif strcmp(res1, 'missing') && strcmp(res2, 'failed')
153+
order(i) = 5;
154+
elseif strcmp(res1, 'failed') && strcmp(res2, 'missing')
155+
order(i) = 6;
156+
elseif strcmp(res1, 'failed') && strcmp(res2, 'passed')
157+
order(i) = 7;
158+
elseif strcmp(res1, 'passed') && strcmp(res2, 'failed')
159+
order(i) = 8;
160+
else
161+
order(i) = 9;
162+
end
163+
end % for each functionname
164+
165+
[order, index] = sort(order);
166+
line = line(index);
167+
for i=1:length(line)
168+
fprintf(line{i});
169+
end
83170

84171
otherwise
85172
error('unsupported command "%s"', command);
@@ -105,4 +192,4 @@
105192
str = 'failed';
106193
else
107194
str = 'ambiguous';
108-
end
195+
end

0 commit comments

Comments
 (0)