reporting: annualAverages option for addTable
parent
79d62d85d0
commit
d1c012d289
|
@ -8427,11 +8427,16 @@ Display a solid black line at @math{y = 0}. Default: @code{false}
|
||||||
@end table
|
@end table
|
||||||
@end defmethod
|
@end defmethod
|
||||||
|
|
||||||
@defmethod Report addTable data, showHlines, precision, range, seriesToUse, title, titleSize, vlineAfter, vlineAfterEndOfPeriod, showVlines
|
@defmethod Report addTable annualAverages, data, showHlines, precision, range, seriesToUse, title, titleSize, vlineAfter, vlineAfterEndOfPeriod, showVlines
|
||||||
Adds a @code{Table} to a @code{Section}.
|
Adds a @code{Table} to a @code{Section}.
|
||||||
@optionshead
|
@optionshead
|
||||||
@table @code
|
@table @code
|
||||||
|
|
||||||
|
@item annualAverages, @code{bool}
|
||||||
|
Compute the average over every year in the table and display it in a
|
||||||
|
column to the right of the data (one column for every year). Only
|
||||||
|
works for quarterly data. Default: @code{false}
|
||||||
|
|
||||||
@item data, @code{dynSeries}
|
@item data, @code{dynSeries}
|
||||||
@xref{data}.
|
@xref{data}.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
function o = write(o, fid, dates, precision)
|
function o = write(o, fid, dates, precision, yrsForAvgs)
|
||||||
%function o = write(o, fid, dates, precision)
|
%function o = write(o, fid, dates, precision, yrsForAvgs)
|
||||||
% Write Table Row
|
% Write Table Row
|
||||||
%
|
%
|
||||||
% INPUTS
|
% INPUTS
|
||||||
|
@ -7,6 +7,8 @@ function o = write(o, fid, dates, precision)
|
||||||
% fid [int] file id
|
% fid [int] file id
|
||||||
% dates [dynDates] dates for series slice
|
% dates [dynDates] dates for series slice
|
||||||
% precision [float] precision with which to print the data
|
% precision [float] precision with which to print the data
|
||||||
|
% yrsForAvgs [bool] the years for which to compute averages
|
||||||
|
%
|
||||||
%
|
%
|
||||||
% OUTPUTS
|
% OUTPUTS
|
||||||
% o [series] series object
|
% o [series] series object
|
||||||
|
@ -92,5 +94,26 @@ for i=1:size(data,1)
|
||||||
fprintf(fid, ']');
|
fprintf(fid, ']');
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
% Calculate and display annual averages
|
||||||
|
for i=1:length(yrsForAvgs)
|
||||||
|
slice = o.data(dynDate([num2str(yrsForAvgs(i)) 'q1']):dynDate([num2str(yrsForAvgs(i)) 'q4']));
|
||||||
|
avg = sum(slice.data)/size(slice);
|
||||||
|
fprintf(fid, '&');
|
||||||
|
if o.tableShowMarkers
|
||||||
|
if avg < -o.tableMarkerLimit
|
||||||
|
fprintf(fid, '\\color{%s}', o.tableNegColor);
|
||||||
|
elseif avg > o.tableMarkerLimit
|
||||||
|
fprintf(fid, '\\color{%s}', o.tablePosColor);
|
||||||
|
end
|
||||||
|
fprintf(fid, '[');
|
||||||
|
end
|
||||||
|
|
||||||
|
fprintf(fid, dataString, round(avg*precision)/precision);
|
||||||
|
|
||||||
|
if o.tableShowMarkers
|
||||||
|
fprintf(fid, ']');
|
||||||
|
end
|
||||||
|
end
|
||||||
fprintf(fid, '\\\\%%\n');
|
fprintf(fid, '\\\\%%\n');
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,6 +41,8 @@ o.showVlines = false;
|
||||||
o.vlineAfter = '';
|
o.vlineAfter = '';
|
||||||
o.vlineAfterEndOfPeriod = false;
|
o.vlineAfterEndOfPeriod = false;
|
||||||
|
|
||||||
|
o.annualAverages = false;
|
||||||
|
|
||||||
o.data = '';
|
o.data = '';
|
||||||
o.seriesToUse = '';
|
o.seriesToUse = '';
|
||||||
o.range = {};
|
o.range = {};
|
||||||
|
@ -73,6 +75,7 @@ end
|
||||||
|
|
||||||
% Check options provided by user
|
% Check options provided by user
|
||||||
assert(ischar(o.title), '@table.table: title must be a string');
|
assert(ischar(o.title), '@table.table: title must be a string');
|
||||||
|
assert(islogical(o.annualAverages), '@table.table: annualAverages must be true or false');
|
||||||
assert(islogical(o.showHlines), '@table.table: showHlines must be true or false');
|
assert(islogical(o.showHlines), '@table.table: showHlines must be true or false');
|
||||||
assert(islogical(o.showVlines), '@table.table: showVlines must be true or false');
|
assert(islogical(o.showVlines), '@table.table: showVlines must be true or false');
|
||||||
assert(isint(o.precision), '@table.table: precision must be an int');
|
assert(isint(o.precision), '@table.table: precision must be an int');
|
||||||
|
|
|
@ -72,6 +72,19 @@ for i=1:ndates
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
datedata = dates.time;
|
||||||
|
years = unique(datedata(:, 1));
|
||||||
|
if o.annualAverages
|
||||||
|
yrsForAvgs = years;
|
||||||
|
else
|
||||||
|
yrsForAvgs = [];
|
||||||
|
end
|
||||||
|
for i=1:length(yrsForAvgs)
|
||||||
|
fprintf(fid, 'r');
|
||||||
|
if o.showVlines
|
||||||
|
fprintf(fid, '|');
|
||||||
|
end
|
||||||
|
end
|
||||||
fprintf(fid, '@{}}%%\n');
|
fprintf(fid, '@{}}%%\n');
|
||||||
if ~isempty(o.title)
|
if ~isempty(o.title)
|
||||||
fprintf(fid, '\\multicolumn{%d}{c}{\\%s %s}\\\\\n', ...
|
fprintf(fid, '\\multicolumn{%d}{c}{\\%s %s}\\\\\n', ...
|
||||||
|
@ -80,8 +93,6 @@ end
|
||||||
fprintf(fid, '\\toprule%%\n');
|
fprintf(fid, '\\toprule%%\n');
|
||||||
|
|
||||||
% Column Headers
|
% Column Headers
|
||||||
datedata = dates.time;
|
|
||||||
years = unique(datedata(:, 1));
|
|
||||||
thdr = num2cell(years, size(years, 1));
|
thdr = num2cell(years, size(years, 1));
|
||||||
switch dates.freq
|
switch dates.freq
|
||||||
case 1
|
case 1
|
||||||
|
@ -101,7 +112,6 @@ switch dates.freq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i=1:size(thdr, 1)
|
for i=1:size(thdr, 1)
|
||||||
fprintf(fid, ' & \\multicolumn{%d}{c}{%d}', size(thdr{i,2}, 2), thdr{i,1});
|
fprintf(fid, ' & \\multicolumn{%d}{c}{%d}', size(thdr{i,2}, 2), thdr{i,1});
|
||||||
end
|
end
|
||||||
|
@ -121,6 +131,9 @@ switch dates.freq
|
||||||
otherwise
|
otherwise
|
||||||
error('@table.write: invalid dynSeries frequency');
|
error('@table.write: invalid dynSeries frequency');
|
||||||
end
|
end
|
||||||
|
for i=1:length(yrsForAvgs)
|
||||||
|
fprintf(fid, ' & %d', years(i));
|
||||||
|
end
|
||||||
fprintf(fid, '\\\\[-2pt]%%\n');
|
fprintf(fid, '\\\\[-2pt]%%\n');
|
||||||
fprintf(fid, '\\hline%%\n');
|
fprintf(fid, '\\hline%%\n');
|
||||||
fprintf(fid, '%%\n');
|
fprintf(fid, '%%\n');
|
||||||
|
@ -128,7 +141,7 @@ fprintf(fid, '%%\n');
|
||||||
% Write Table Data
|
% Write Table Data
|
||||||
ne = o.seriesElements.numSeriesElements();
|
ne = o.seriesElements.numSeriesElements();
|
||||||
for i=1:ne
|
for i=1:ne
|
||||||
o.seriesElements(i).write(fid, dates, o.precision);
|
o.seriesElements(i).write(fid, dates, o.precision, yrsForAvgs);
|
||||||
if o.showHlines
|
if o.showHlines
|
||||||
fprintf(fid, '\\hline\n');
|
fprintf(fid, '\\hline\n');
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue