Commit 686a3840 authored by Dóra Kocsis's avatar Dóra Kocsis

Add tests to mdbnomics2dseries.m

parent 198023a2
Pipeline #3810 passed with stage
in 3 minutes and 7 seconds
......@@ -52,3 +52,81 @@ switch nargin
error('mdbnomics2dseries:WrongInputArguments', 'Too many input arguments! Please check the manual.')
end
end
%@test:1
%$ try
%$ dseries_src_root = strrep(which('initialize_dseries_class'),'initialize_dseries_class.m','');
%$ df_id = load([dseries_src_root '../tests/data/mdbnomics/df_id.mat']);
%$ df = df_id.df;
%$ ds = mdbnomics2dseries(df);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(ds.name, {'EA19_1_0_0_0_ZUTN'});
%$ t(3) = dassert(ds.vobs, 1);
%$ t(4) = dassert(ds.tags.provider_code, {'AMECO'});
%$ t(5:10) = isfield(ds.tags, {'freq', 'unit', 'geo', 'Frequency', 'Unit', 'Country'});
%$ end
%$
%$ T = all(t);
%@eof:1
%@test:2
%$ try
%$ dseries_src_root = strrep(which('initialize_dseries_class'),'initialize_dseries_class.m','');
%$ df_bi = load([dseries_src_root '../tests/data/mdbnomics/df_bi-annual.mat']);
%$ df = df_bi.df;
%$ ds = mdbnomics2dseries(df);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(ds.name, {'S_EUR_AL'});
%$ t(3) = dassert(ds.vobs, 1);
%$ t(4) = dassert(ds.dates.freq, 2);
%$ t(4) = dassert(ds.tags.provider_code, {'Eurostat'});
%$ t(5:10) = isfield(ds.tags, {'FREQ', 'currency', 'geo', 'Frequency', 'Currency', 'Geopolitical_entity__reporting_'});
%$ end
%$
%$ T = all(t);
%@eof:2
%@test:3
%$ try
%$ dseries_src_root = strrep(which('initialize_dseries_class'),'initialize_dseries_class.m','');
%$ df_dataset = load([dseries_src_root '../tests/data/mdbnomics/df_dataset.mat']);
%$ df = df_dataset.df;
%$ ds = mdbnomics2dseries(df);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(ds.vobs, 49);
%$ t(3) = dassert(ds.dates.freq, 1);
%$ t(4) = dassert(length(unique(ds.tags.provider_code)), 1);
%$ t(5) = dassert(size(ds.tags.provider_code,1), 49);
%$ end
%$
%$ T = all(t);
%@eof:3
%@test:4
%$ try
%$ dseries_src_root = strrep(which('initialize_dseries_class'),'initialize_dseries_class.m','');
%$ df_multi = load([dseries_src_root '../tests/data/mdbnomics/df_multi-freq.mat']);
%$ df = df_multi.df;
%$ ds = mdbnomics2dseries(df);
%$ t(1) = false;
%$ catch
%$ t(1) = true;
%$ end
%$
%$ T = all(t);
%@eof:4
......@@ -29,13 +29,21 @@ end
ds = dseries();
% Check for multiple datasets
dataset_codes = unique(o.data(:,o.col_idx.dataset_code),'stable');
if isoctave()
dataset_codes = unique(o.data(:,o.col_idx.dataset_code));
else
dataset_codes = unique(o.data(:,o.col_idx.dataset_code),'stable');
end
% Convert mdbnomics to dseries
for ii = 1:length(dataset_codes)
% Slice data for dataset
ds_dataset = o.data(strcmp(o.data(:,o.col_idx.dataset_code),dataset_codes{ii}),:);
series_codes = unique(ds_dataset(:,o.col_idx.series_code),'stable');
if isoctave()
series_codes = unique(ds_dataset(:,o.col_idx.series_code));
else
series_codes = unique(ds_dataset(:,o.col_idx.series_code),'stable');
end
% Get list of variable names
list_of_names = cellfun(@(x)regexprep(x, '[^a-zA-Z0-9]', '_'), series_codes, 'UniformOutput', false);
% Get dataset values
......@@ -70,8 +78,8 @@ for ii = 1:length(dataset_codes)
data_dataset = reshape(ds_dataset_values, max(series_length), size(series_codes, 1));
% Get dseries date format from dataset
starting_date = min(datetime(ds_dataset(:,o.col_idx.period), 'InputFormat', 'yyyy-MM-dd', 'Format', 'yyyy-MM-dd'));
original_period = ds_dataset(strcmp(ds_dataset(:,o.col_idx.period),string(starting_date)),o.col_idx.original_period);
starting_date = min(datenum(ds_dataset(:,o.col_idx.period)));
original_period = ds_dataset(strcmp(ds_dataset(:,o.col_idx.period),datestr(starting_date, 'yyyy-mm-dd')),o.col_idx.original_period);
dseries_date = get_series_start_date(freq, original_period{1});
% Transform dataset into dseries
dataset = dseries(data_dataset, dseries_date, list_of_names);
......@@ -82,7 +90,11 @@ end
% Add tags to the variables
if length(dataset_codes) > 1
series_codes = unique(o.data(:,o.col_idx.series_code),'stable');
if isoctave()
series_codes = unique(o.data(:,o.col_idx.series_code));
else
series_codes = unique(o.data(:,o.col_idx.series_code),'stable');
end
list_of_names = cellfun(@(x)regexprep(x, '[^a-zA-Z0-9]', '_'), series_codes, 'UniformOutput', false);
series_length = cell2mat(cellfun(@(x)length(find(strcmp(x, o.data(:,o.col_idx.series_code)))), series_codes, 'UniformOutput', false));
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment