Commit 5acefc83 authored by Dóra Kocsis's avatar Dóra Kocsis

remove double quotes and string arrays for backward compatibility, closes #8

parent 3aaa0742
......@@ -40,7 +40,7 @@ belonging to the [AMECO provider](https://db.nomics.world/AMECO).
Example:
>> df_id = fetch_series('series_ids',"AMECO/ZUTN/EA19.1.0.0.0.ZUTN");
>> df_id = fetch_series('series_ids', 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN');
The returned data is stored in the `df_id` variable. Its type is a cell array. To display the first 3 rows of the array
(including the column headers), type:
......@@ -81,7 +81,7 @@ In such cell array, you will always find at least those columns:
* `series_name`
* `original_period`: the `period` as returned by DBnomics
* `period`: the first day of `original_period`
* `original_value` (`str` or `float`): the observation value as returned by DBnomics, where not available values are represented by `"NA"`
* `original_value` (`str` or `float`): the observation value as returned by DBnomics, where not available values are represented by `'NA'`
* `value` (`float` or `NaN`): the observation value as returned by DBnomics, where not available values are represented by `NaN`
Followed by dimensions columns, corresponding to the dimensions of the dataset:
......@@ -97,7 +97,7 @@ belonging to the [AMECO provider](https://db.nomics.world/AMECO).
Example:
>> df_ids = fetch_series('series_ids', ["AMECO/ZUTN/EA19.1.0.0.0.ZUTN", "AMECO/ZUTN/DNK.1.0.0.0.ZUTN"]);
>> df_ids = fetch_series('series_ids', {'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'AMECO/ZUTN/DNK.1.0.0.0.ZUTN'});
### Fetch time series by code mask
The code mask notation is a very concise way to select one or many time series at once.
......@@ -112,16 +112,16 @@ It is not compatible with all the providers. In particular, only the providers f
* OECD
* WTO
Given 3 dimensions "frequency", "country" and "indicator", the user can select:
* one time series by giving its code: `"M.FR.PCPIEC_IX"`
* many series by enumerating dimensions codes: `"M.FR+DE.PCPIEC_IX"` is equivalent to `["M.FR.PCPIEC_IX", "M.DE.PCPIEC_IX"]`
* many series by skipping a dimension, repeating "." in the code mask: `"M..PCPIEC_IX"` is equivalent to `["M.country1.PCPIEC_IX", "M.country2.PCPIEC_IX", ..., "M.countryN.PCPIEC_IX"]`
Given 3 dimensions 'frequency', 'country' and 'indicator', the user can select:
* one time series by giving its code: `'M.FR.PCPIEC_IX'`
* many series by enumerating dimensions codes: `'M.FR+DE.PCPIEC_IX'` is equivalent to `{'M.FR.PCPIEC_IX', 'M.DE.PCPIEC_IX'}`
* many series by skipping a dimension, repeating '.' in the code mask: `'M..PCPIEC_IX'` is equivalent to `{'M.country1.PCPIEC_IX', 'M.country2.PCPIEC_IX', ..., 'M.countryN.PCPIEC_IX'}`
Examples:
>> df_code_mask1 = fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', "M.FR+DE.PCPIEC_IX+PCPIA_IX");
>> df_code_mask2 = fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', ".FR.PCPIEC_WT");
>> df_code_mask3 = fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', "M..PCPIEC_IX+PCPIA_IX", 'max_nb_series', 400);
>> df_code_mask1 = fetch_series('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', 'M.FR+DE.PCPIEC_IX+PCPIA_IX');
>> df_code_mask2 = fetch_series('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', '.FR.PCPIEC_WT');
>> df_code_mask3 = fetch_series('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', 'M..PCPIEC_IX+PCPIA_IX', 'max_nb_series', 400);
### Fetch time series by dimension
Searching by dimension is a less concise way to select time series than using the code mask, but it's universal:
......@@ -131,7 +131,7 @@ and the indicator "Procedures required to start a business - Women (number)" (`i
Example:
>> df_dims = fetch_series('provider_code',"WB",'dataset_code',"DB", 'dimensions', '{"country":["ES","FR","IT"],"indicator":["IC.REG.COST.PC.FE.ZS.DRFN"]}');
>> df_dims = fetch_series('provider_code', 'WB', 'dataset_code', 'DB', 'dimensions', '{"country":["ES","FR","IT"],"indicator":["IC.REG.COST.PC.FE.ZS.DRFN"]}');
### Fetch time series by API link
When the dimensions, provider, dataset or series codes are unknown, the user can:
......@@ -156,9 +156,9 @@ Example:
Example:
>> df_multi_freq = fetch_series('series_ids', ["BEA/NIUnderlyingDetail-U001BC/S315-A",...
"BEA/NIUnderlyingDetail-U001BC/S315-Q",...
"BEA/NIUnderlyingDetail-U001BC/S315-M"]);
>> df_multi_freq = fetch_series('series_ids', {'BEA/NIUnderlyingDetail-U001BC/S315-A',...
'BEA/NIUnderlyingDetail-U001BC/S315-Q',...
'BEA/NIUnderlyingDetail-U001BC/S315-M'});
### Transform time series
The routines can interact with the [Time Series Editor](https://editor.nomics.world/) to transform time series by applying filters to them.
......@@ -170,7 +170,7 @@ Here is an example of how to interpolate two annual time series with a monthly f
Example:
>> filters_ = '[{"code": "interpolate", "parameters": {"frequency": "monthly", "method": "spline"}}]';
>> df_filter = fetch_series('series_ids', "AMECO/ZUTN/EA19.1.0.0.0.ZUTN",'dbnomics_filters', filters_);
>> df_filter = fetch_series('series_ids', 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'dbnomics_filters', filters_);
The first row of the final cell array changes when filters are used:
* `period_middle_day`: the middle day of `original_period` (can be useful when you compare graphically interpolated series and original ones)
......
......@@ -5,17 +5,17 @@ function df = fetch_series(varargin)
%
% Examples:
% Fetch one series:
% fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', "M.FR+DE.PCPIEC_IX+PCPIA_IX");
% fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', ".FR.PCPIEC_WT");
% fetch_series('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', 'M.FR+DE.PCPIEC_IX+PCPIA_IX');
% fetch_series('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', '.FR.PCPIEC_WT');
%
% Fetch all the series of a dataset:
% fetch_series('provider_code', "AMECO", 'dataset_code', "UVGD", 'max_nb_series', 500);
% fetch_series('provider_code', 'AMECO', 'dataset_code', 'UVGD', 'max_nb_series', 500);
%
% Fetch many series from different datasets:
% fetch_series('series_ids', ["AMECO/ZUTN/EA19.1.0.0.0.ZUTN", "AMECO/ZUTN/DNK.1.0.0.0.ZUTN", "IMF/CPI/A.AT.PCPIT_IX"]);
% fetch_series('series_ids', {'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'AMECO/ZUTN/DNK.1.0.0.0.ZUTN', 'IMF/CPI/A.AT.PCPIT_IX'});
%
% Fetch many series from the same dataset, searching by dimension:
% fetch_series('provider_code',"AMECO", 'dataset_code', "ZUTN", 'dimensions', '{"geo":["dnk"]}');
% fetch_series('provider_code','AMECO', 'dataset_code', 'ZUTN', 'dimensions', '{"geo":["dnk"]}');
%
% POSSIBLE PARAMETERS
% provider_code [string] the code of the dataset provider.
......@@ -109,7 +109,12 @@ if ~isempty(p.Results.series_ids)
if ~isempty(p.Results.provider_code) || ~isempty(p.Results.dataset_code)
error('When you use series_ids, you must not specifiy provider_code nor dataset_code.');
end
api_link = sprintf('%s?observations=1&series_ids=%s', series_base_url, strjoin(p.Results.series_ids,','));
if iscellstr(p.Results.series_ids)
series_ids = strjoin(p.Results.series_ids,',');
else
series_ids = p.Results.series_ids;
end
api_link = sprintf('%s?observations=1&series_ids=%s', series_base_url, series_ids);
end
df = fetch_series_by_api_link(api_link, p.Results.dbnomics_filters, p.Results.max_nb_series, default_editor_base_url);
end
......
......@@ -5,7 +5,7 @@ function df = fetch_series_by_api_link(api_link, varargin)
% Returns a cell array.
%
% Example:
% fetch_series_by_api_link("https://api.db.nomics.world/v22/series?series_ids=AMECO%2FZUTN%2FEA19.1.0.0.0.ZUTN&observations=1");
% fetch_series_by_api_link('https://api.db.nomics.world/v22/series?series_ids=AMECO%2FZUTN%2FEA19.1.0.0.0.ZUTN&observations=1');
%
% REQUIRED PARAMETERS
% api_link [string] the URL used for the API request.
......@@ -54,15 +54,15 @@ p.parse(api_link, varargin{:});
if isempty(series_list)
df = {};
else
common_columns = ["x_frequency", "provider_code", "dataset_code", "dataset_name", "series_code", "series_name","original_period", "period", "original_value", "value"];
common_columns = {'x_frequency', 'provider_code', 'dataset_code', 'dataset_name', 'series_code', 'series_name','original_period', 'period', 'original_value', 'value'};
% Compute dimensions_labels_columns_names and dimensions_codes_columns_names
dimensions_labels_columns_names = [];
dimensions_codes_columns_names = [];
dimensions_labels_columns_names = {};
dimensions_codes_columns_names = {};
dataset_codes = fieldnames(datasets_dimensions);
for ii = 1:length(fieldnames(datasets_dimensions))
dataset_dimensions = datasets_dimensions.(dataset_codes{ii});
dimensions_codes_columns_names = [dimensions_codes_columns_names, string(dataset_dimensions.dimensions_codes_order')];
dimensions_codes_columns_names = dataset_dimensions.dimensions_codes_order';
for jj = 1:length(dataset_dimensions.dimensions_codes_order)
if isfield(dataset_dimensions, 'dimensions_labels') && isfield(dataset_dimensions, 'dimensions_values_labels')
dimensions_labels_columns_names_dataset{jj} = dataset_dimensions.dimensions_labels.(dataset_dimensions.dimensions_codes_order{jj});
......@@ -72,16 +72,16 @@ else
end
end
end
dimensions_labels_columns_names = [dimensions_labels_columns_names, string(dimensions_labels_columns_names_dataset)];
dimensions_labels_columns_names = dimensions_labels_columns_names_dataset;
end
ordered_columns_names = [common_columns, dimensions_codes_columns_names, dimensions_labels_columns_names];
if ~isempty(p.Results.dbnomics_filters)
filtered_series_list = filter_series(series_list, p.Results.dbnomics_filters,p.Results.editor_api_base_url);
% Append common column names with period_middle_day and filtered columns for the final DataFrame
idx_period = find(strcmp(ordered_columns_names, "period"));
idx_value = find(strcmp(ordered_columns_names, "value"));
ordered_columns_names = [ordered_columns_names{1:idx_period}, "period_middle_day", ordered_columns_names{idx_period+1:idx_value}, "filtered", ordered_columns_names{idx_value+1:end}];
idx_period = find(strcmp(ordered_columns_names, 'period'));
idx_value = find(strcmp(ordered_columns_names, 'value'));
ordered_columns_names = {ordered_columns_names{1:idx_period}, 'period_middle_day', ordered_columns_names{idx_period+1:idx_value}, 'filtered', ordered_columns_names{idx_value+1:end}};
% Append series_list with the filtered series
series_list = [series_list, filtered_series_list];
end
......@@ -110,7 +110,7 @@ else
end
% Add dimensions values labels to current series
if isfield(dataset_dimensions, 'dimensions_values_labels')
dimension_codes = intersect(dimensions_codes_columns_names, string(fieldnames(dataset_dimensions_labels)')); %string(fieldnames(dataset_dimensions_labels)');
dimension_codes = intersect(dimensions_codes_columns_names, fieldnames(dataset_dimensions_labels)');
for jj = 1:length(dimension_codes)
series_code = regexprep(flat_series.series_code,'[^a-zA-Z0-9]','_');
dimension_label = dataset_dimensions_labels.(dimension_codes{jj});
......@@ -155,7 +155,7 @@ else
else
df{series_length+jj+1,col} = NaN;
end
elseif any(strcmp(col_, dimensions_codes_columns_names)) && ~any(strcmp(col_,string(fieldnames(flat_series)')))
elseif any(strcmp(col_, dimensions_codes_columns_names)) && ~any(strcmp(col_,fieldnames(flat_series)'))
df{series_length+jj+1,col} = NaN;
elseif strcmp(col_, 'period_middle_day')
if isfield(flat_series, 'period_middle_day')
......
......@@ -34,7 +34,7 @@ series = normalize_value(series);
series.x_frequency = series.frequency;
series = rmfield(series, 'frequency');
orig_fields = ["provider_code", "dataset_code", "dataset_name"];
orig_fields = {'provider_code', 'dataset_code', 'dataset_name'};
for ii = 1:length(orig_fields)
series.(orig_fields{ii}) = dbnomics_series.(orig_fields{ii});
end
......
......@@ -42,8 +42,8 @@ end
for gg = 1:size(grouped_series, 2)
series_list = grouped_series{gg};
posted_series_list = cell(1,size(series_list,2));
series_fields = ["x_frequency", "period_start_day", "value"];
posted_series_fields = ["frequency", "period_start_day", "value"];
series_fields = {'x_frequency', 'period_start_day', 'value'};
posted_series_fields = {'frequency', 'period_start_day', 'value'};
for series = 1:size(series_list, 2)
for ii = 1:length(posted_series_fields)
posted_series.(posted_series_fields{ii}) = series_list{series}.(series_fields{ii});
......
......@@ -44,7 +44,7 @@ while (true)
num_found = series_page.num_found;
if isnan(max_nb_series) && num_found > default_max_nb_series
error("DBnomics Web API found %i series matching your request, %i, but you did not pass any value for the 'max_nb_series' argument, so a default value of %i was used. Please give a higher value (at least max_nb_series=%i), and try again.", ...
error('DBnomics Web API found %i series matching your request, %i, but you did not pass any value for the "max_nb_series" argument, so a default value of %i was used. Please give a higher value (at least max_nb_series=%i), and try again.', ...
num_found, default_max_nb_series, num_found);
end
......
......@@ -31,7 +31,7 @@ function series = normalize_period(series)
period = series.period;
period_start_day = series.period_start_day;
series = rmfield(series, "period_start_day");
series = rmfield(series, 'period_start_day');
series.original_period = period;
for ii = 1:length(period_start_day)
......
% fetch series by provider code and dataset code
df = fetch_series('provider_code', "AMECO", 'dataset_code', "UVGD", 'max_nb_series', 500);
df = fetch_series('provider_code', 'AMECO', 'dataset_code', 'UVGD', 'max_nb_series', 500);
% fetch one series by ID
df_id = fetch_series('series_ids',"AMECO/ZUTN/EA19.1.0.0.0.ZUTN");
df_id = fetch_series('series_ids','AMECO/ZUTN/EA19.1.0.0.0.ZUTN');
% fetch multiple series by ID
df_ids = fetch_series('series_ids', ["AMECO/ZUTN/EA19.1.0.0.0.ZUTN", "AMECO/ZUTN/DNK.1.0.0.0.ZUTN"]);
df_ids = fetch_series('series_ids', {'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'AMECO/ZUTN/DNK.1.0.0.0.ZUTN'});
% fetch many series by ID from different datasets
df_ids_sets = fetch_series('series_ids', ["AMECO/ZUTN/EA19.1.0.0.0.ZUTN", "AMECO/ZUTN/DNK.1.0.0.0.ZUTN", "IMF/CPI/A.AT.PCPIT_IX"]);
df_ids_sets = fetch_series('series_ids', {'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'AMECO/ZUTN/DNK.1.0.0.0.ZUTN', 'IMF/CPI/A.AT.PCPIT_IX'});
% fetch time series by code mask
df_code_mask1 = fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', "M.FR+DE.PCPIEC_IX+PCPIA_IX");
df_code_mask2 = fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', ".FR.PCPIEC_WT");
% df_code_mask3 = fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', "M..PCPIEC_IX+PCPIA_IX", 'max_nb_series', 400);
df_code_mask1 = fetch_series('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', 'M.FR+DE.PCPIEC_IX+PCPIA_IX');
df_code_mask2 = fetch_series('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', '.FR.PCPIEC_WT');
% df_code_mask3 = fetch_series('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', 'M..PCPIEC_IX+PCPIA_IX', 'max_nb_series', 400);
% fetch series by dimensions
% dimensions=struct("geo", "dnk");
df_dim = fetch_series('provider_code',"AMECO", 'dataset_code', "ZUTN", 'dimensions', '{"geo":["dnk"]}');
df_dims = fetch_series('provider_code',"WB",'dataset_code',"DB", 'dimensions', '{"country":["ES","FR","IT"],"indicator":["IC.REG.COST.PC.FE.ZS.DRFN"]}');
df_dim = fetch_series('provider_code','AMECO', 'dataset_code', 'ZUTN', 'dimensions', '{"geo":["dnk"]}');
df_dims = fetch_series('provider_code','WB','dataset_code','DB', 'dimensions', '{"country":["ES","FR","IT"],"indicator":["IC.REG.COST.PC.FE.ZS.DRFN"]}');
% fetch series by api link
df_link = fetch_series_by_api_link("https://api.db.nomics.world/v22/series/WB/DB?observations=1&dimensions=%7B%22country%22%3A%5B%22FR%22%2C%22IT%22%2C%22ES%22%5D%2C%22indicator%22%3A%5B%22IC.REG.COST.PC.FE.ZS.DRFN%22%5D%7D");
df_link = fetch_series_by_api_link('https://api.db.nomics.world/v22/series/WB/DB?observations=1&dimensions=%7B%22country%22%3A%5B%22FR%22%2C%22IT%22%2C%22ES%22%5D%2C%22indicator%22%3A%5B%22IC.REG.COST.PC.FE.ZS.DRFN%22%5D%7D');
% fetch series from the cart
df_cart = fetch_series_by_api_link("https://api.db.nomics.world/v22/series?series_ids=AMECO%2FZUTN%2FEA19.1.0.0.0.ZUTN&observations=1");
df_cart = fetch_series_by_api_link('https://api.db.nomics.world/v22/series?series_ids=AMECO%2FZUTN%2FEA19.1.0.0.0.ZUTN&observations=1');
% fetch multi frequency series
df_multi_freq = fetch_series('series_ids', ["BEA/NIUnderlyingDetail-U001BC/S315-A",...
"BEA/NIUnderlyingDetail-U001BC/S315-Q",...
"BEA/NIUnderlyingDetail-U001BC/S315-M"]);
df_multi_freq = fetch_series('series_ids', {'BEA/NIUnderlyingDetail-U001BC/S315-A',...
'BEA/NIUnderlyingDetail-U001BC/S315-Q',...
'BEA/NIUnderlyingDetail-U001BC/S315-M'});
% fetch one series and apply interpolation filter
filters_ = '[{"code": "interpolate", "parameters": {"frequency": "monthly", "method": "spline"}}]';
df_filter = fetch_series('series_ids', "AMECO/ZUTN/EA19.1.0.0.0.ZUTN",...
df_filter = fetch_series('series_ids', 'AMECO/ZUTN/EA19.1.0.0.0.ZUTN',...
'dbnomics_filters', filters_);
% fetch multiple series and apply interpolation filter
df_filters = fetch_series('series_ids', ["AMECO/ZUTN/EA19.1.0.0.0.ZUTN", "AMECO/ZUTN/DNK.1.0.0.0.ZUTN"],...
df_filters = fetch_series('series_ids', {'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'AMECO/ZUTN/DNK.1.0.0.0.ZUTN'},...
'dbnomics_filters', filters_);
\ No newline at end of file
function test_fetch_series_by_api_link() % --*-- Unitary tests --*--
df = fetch_series_by_api_link("https://api.db.nomics.world/v22/series/BIS/long_pp?limit=1000&offset=0&q=&observations=1&align_periods=1&dimensions=%7B%7D");
df = fetch_series_by_api_link('https://api.db.nomics.world/v22/series/BIS/long_pp?limit=1000&offset=0&q=&observations=1&align_periods=1&dimensions=%7B%7D');
idx = find(strcmp('provider_code',df(1,:)));
provider_codes = unique(df(2:end,idx));
assert(length(provider_codes)==1);
assert(provider_codes{1} == "BIS");
assert(strcmp(provider_codes{1},'BIS'));
idx = find(strcmp('dataset_code',df(1,:)));
dataset_codes = unique(df(2:end,idx));
assert(length(dataset_codes) == 1);
assert(dataset_codes{1} == "long_pp");
assert(strcmp(dataset_codes{1},'long_pp'));
idx = find(strcmp('series_code',df(1,:)));
series_codes = unique(df(2:end,idx));
......
function test_fetch_series_by_code() % --*-- Unitary tests --*--
df = fetch_series('provider_code', "AMECO", 'dataset_code', "ZUTN", 'series_code',"EA19.1.0.0.0.ZUTN");
df = fetch_series('provider_code', 'AMECO', 'dataset_code', 'ZUTN', 'series_code', 'EA19.1.0.0.0.ZUTN');
idx = find(strcmp('provider_code',df(1,:)));
provider_codes = unique(df(2:end,idx));
assert(length(provider_codes)==1);
assert(provider_codes{1} == "AMECO");
assert(strcmp(provider_codes{1},'AMECO'));
idx = find(strcmp('dataset_code',df(1,:)));
dataset_codes = unique(df(2:end,idx));
assert(length(dataset_codes) == 1);
assert(dataset_codes{1} == "ZUTN");
assert(strcmp(dataset_codes{1},'ZUTN'));
idx = find(strcmp('series_code',df(1,:)));
series_codes = unique(df(2:end,idx));
assert(length(series_codes) == 1);
assert(series_codes{1} == "EA19.1.0.0.0.ZUTN");
assert(strcmp(series_codes{1},'EA19.1.0.0.0.ZUTN'));
end
%@test:1
......
function test_fetch_series_by_code_mask() % --*-- Unitary tests --*--
df = fetch_series('provider_code', "IMF", 'dataset_code', "CPI", 'series_code', "M.FR+DE.PCPIEC_IX+PCPIA_IX");
df = fetch_series('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', 'M.FR+DE.PCPIEC_IX+PCPIA_IX');
idx = find(strcmp('provider_code',df(1,:)));
provider_codes = unique(df(2:end,idx));
assert(length(provider_codes)==1);
assert(provider_codes{1} == "IMF");
assert(strcmp(provider_codes{1},'IMF'));
idx = find(strcmp('dataset_code',df(1,:)));
dataset_codes = unique(df(2:end,idx));
assert(length(dataset_codes) == 1);
assert(dataset_codes{1} == "CPI");
assert(strcmp(dataset_codes{1},'CPI'));
idx = find(strcmp('series_code',df(1,:)));
series_codes = unique(df(2:end,idx));
......
function test_fetch_series_by_code_mask_with_plus() % --*-- Unitary tests --*--
df = fetch_series('provider_code', "SCB", 'dataset_code', "AKIAM", 'series_code', '"J+K"+"G+H".AM0301C1');
df = fetch_series('provider_code', 'SCB', 'dataset_code', 'AKIAM', 'series_code', '"J+K"+"G+H".AM0301C1');
idx = find(strcmp('provider_code',df(1,:)));
provider_codes = unique(df(2:end,idx));
assert(length(provider_codes)==1);
assert(provider_codes{1} == "SCB");
assert(strcmp(provider_codes{1},'SCB'));
idx = find(strcmp('dataset_code',df(1,:)));
dataset_codes = unique(df(2:end,idx));
assert(length(dataset_codes) == 1);
assert(dataset_codes{1} == "AKIAM");
assert(strcmp(dataset_codes{1},'AKIAM'));
idx = find(strcmp('series_code',df(1,:)));
series_codes = unique(df(2:end,idx));
......
function test_fetch_series_by_dimension() % --*-- Unitary tests --*--
df = fetch_series('provider_code',"WB",'dataset_code',"DB", 'dimensions', '{"country":["ES","FR","IT"],"indicator":["IC.REG.COST.PC.FE.ZS.DRFN"]}');
df = fetch_series('provider_code','WB','dataset_code','DB', 'dimensions', '{"country":["ES","FR","IT"],"indicator":["IC.REG.COST.PC.FE.ZS.DRFN"]}');
idx = find(strcmp('provider_code',df(1,:)));
provider_codes = unique(df(2:end,idx));
assert(length(provider_codes)==1);
assert(provider_codes{1} == "WB");
assert(strcmp(provider_codes{1},'WB'));
idx = find(strcmp('dataset_code',df(1,:)));
dataset_codes = unique(df(2:end,idx));
assert(length(dataset_codes) == 1);
assert(dataset_codes{1} == "DB");
assert(strcmp(dataset_codes{1},'DB'));
idx = find(strcmp('series_code',df(1,:)));
series_codes = unique(df(2:end,idx));
......
function test_fetch_series_by_id() % --*-- Unitary tests --*--
df = fetch_series('series_ids',"AMECO/ZUTN/EA19.1.0.0.0.ZUTN");
df = fetch_series('series_ids','AMECO/ZUTN/EA19.1.0.0.0.ZUTN');
idx = find(strcmp('provider_code',df(1,:)));
provider_codes = unique(df(2:end,idx));
assert(length(provider_codes)==1);
assert(provider_codes{1} == "AMECO");
assert(strcmp(provider_codes{1},'AMECO'));
idx = find(strcmp('dataset_code',df(1,:)));
dataset_codes = unique(df(2:end,idx));
assert(length(dataset_codes) == 1);
assert(dataset_codes{1} == "ZUTN");
assert(strcmp(dataset_codes{1},'ZUTN'));
idx = find(strcmp('series_code',df(1,:)));
series_codes = unique(df(2:end,idx));
assert(length(series_codes) == 1);
assert(series_codes{1} == "EA19.1.0.0.0.ZUTN");
assert(strcmp(series_codes{1},'EA19.1.0.0.0.ZUTN'));
end
%@test:1
......
function test_fetch_series_by_ids_in_different_datasets() % --*-- Unitary tests --*--
df = fetch_series('series_ids', ["AMECO/ZUTN/EA19.1.0.0.0.ZUTN", "BIS/cbs/Q.S.5A.4B.F.B.A.A.LC1.A.1C"]);
df = fetch_series('series_ids', {'AMECO/ZUTN/EA19.1.0.0.0.ZUTN', 'BIS/cbs/Q.S.5A.4B.F.B.A.A.LC1.A.1C'});
idx = find(strcmp('provider_code',df(1,:)));
provider_codes = unique(df(2:end,idx));
assert(length(provider_codes)==2);
assert(provider_codes{1} == "AMECO");
assert(provider_codes{2} == "BIS");
assert(strcmp(provider_codes{1},'AMECO'));
assert(strcmp(provider_codes{2},'BIS'));
idx = find(strcmp('dataset_code',df(1,:)));
dataset_codes = unique(df(2:end,idx));
assert(length(dataset_codes) == 2);
assert(dataset_codes{1} == "ZUTN");
assert(dataset_codes{2} == "cbs");
assert(strcmp(dataset_codes{1},'ZUTN'));
assert(strcmp(dataset_codes{2},'cbs'));
idx = find(strcmp('series_code',df(1,:)));
series_codes = unique(df(2:end,idx));
assert(length(series_codes) == 2);
assert(series_codes{1} == "EA19.1.0.0.0.ZUTN");
assert(series_codes{2} == "Q.S.5A.4B.F.B.A.A.LC1.A.1C");
assert(strcmp(series_codes{1},'EA19.1.0.0.0.ZUTN'));
assert(strcmp(series_codes{2},'Q.S.5A.4B.F.B.A.A.LC1.A.1C'));
end
%@test:1
......
function test_fetch_series_by_ids_in_same_dataset() % --*-- Unitary tests --*--
df = fetch_series('series_ids', ["AMECO/ZUTN/EA19.1.0.0.0.ZUTN",...
"AMECO/ZUTN/DNK.1.0.0.0.ZUTN"]);
df = fetch_series('series_ids', {'AMECO/ZUTN/EA19.1.0.0.0.ZUTN',...
'AMECO/ZUTN/DNK.1.0.0.0.ZUTN'});
idx = find(strcmp('provider_code',df(1,:)));
provider_codes = unique(df(2:end,idx));
assert(length(provider_codes)==1);
assert(provider_codes{1} == "AMECO");
assert(strcmp(provider_codes{1},'AMECO'));
idx = find(strcmp('dataset_code',df(1,:)));
dataset_codes = unique(df(2:end,idx));
assert(length(dataset_codes) == 1);
assert(dataset_codes{1} == "ZUTN");
assert(strcmp(dataset_codes{1},'ZUTN'));
idx = find(strcmp('series_code',df(1,:)));
series_codes = unique(df(2:end,idx));
assert(length(series_codes) == 2);
assert(series_codes{1} == "DNK.1.0.0.0.ZUTN");
assert(series_codes{2} == "EA19.1.0.0.0.ZUTN");
assert(strcmp(series_codes{1},'DNK.1.0.0.0.ZUTN'));
assert(strcmp(series_codes{2},'EA19.1.0.0.0.ZUTN'));
end
%@test:1
......
function test_fetch_series_of_dataset() % --*-- Unitary tests --*--
df = fetch_series('provider_code', "AMECO", 'dataset_code', "ZUTN");
df = fetch_series('provider_code', 'AMECO', 'dataset_code', 'ZUTN');
idx = find(strcmp('provider_code',df(1,:)));
provider_codes = unique(df(2:end,idx));
assert(length(provider_codes)==1);
assert(provider_codes{1} == "AMECO");
assert(strcmp(provider_codes{1},'AMECO'));
idx = find(strcmp('dataset_code',df(1,:)));
dataset_codes = unique(df(2:end,idx));
assert(length(dataset_codes) == 1);
assert(dataset_codes{1} == "ZUTN");
assert(strcmp(dataset_codes{1},'ZUTN'));
idx = find(strcmp('series_code',df(1,:)));
series_codes = unique(df(2:end,idx));
......
function test_fetch_series_with_filter_on_one_series() % --*-- Unitary tests --*--
filters_ = '[{"code": "interpolate", "parameters": {"frequency": "monthly", "method": "spline"}}]';
df = fetch_series('provider_code', "AMECO", 'dataset_code', "ZUTN", 'series_code', "DEU.1.0.0.0.ZUTN", 'dbnomics_filters', filters_);
df = fetch_series('provider_code', 'AMECO', 'dataset_code', 'ZUTN', 'series_code', 'DEU.1.0.0.0.ZUTN', 'dbnomics_filters', filters_);
idx = find(strcmp('provider_code',df(1,:)));
provider_codes = unique(df(2:end,idx));
assert(length(provider_codes)==1);
assert(provider_codes{1} == "AMECO");
assert(strcmp(provider_codes{1},'AMECO'));
idx = find(strcmp('dataset_code',df(1,:)));
dataset_codes = unique(df(2:end,idx));
assert(length(dataset_codes) == 1);
assert(dataset_codes{1} == "ZUTN");
assert(strcmp(dataset_codes{1},'ZUTN'));
idx = find(strcmp('series_code',df(1,:)));
series_codes = unique(df(2:end,idx));
assert(series_codes{1} == "DEU.1.0.0.0.ZUTN");
assert(strcmp(series_codes{1},'DEU.1.0.0.0.ZUTN'));
assert(any(find(strcmp('filtered',df(1,:)))));
idx_freq = find(strcmp('x_frequency',df(1,:)));
frequencies = unique(df(2:end, idx_freq));
assert(any(strcmp(frequencies, "monthly")));
assert(any(contains(series_codes, "_filtered")));
assert(any(strcmp(frequencies, 'monthly')));
assert(any(contains(series_codes, '_filtered')));
end
%@test:1
......
function test_fetch_series_with_max_nb_series() % --*-- Unitary tests --*--
df = fetch_series('provider_code', "AMECO", 'dataset_code', "ZUTN", 'max_nb_series',20);
df = fetch_series('provider_code', 'AMECO', 'dataset_code', 'ZUTN', 'max_nb_series',20);
idx = find(strcmp('provider_code',df(1,:)));
provider_codes = unique(df(2:end,idx));
assert(length(provider_codes)==1);
assert(provider_codes{1} == "AMECO");
assert(strcmp(provider_codes{1},'AMECO'));
idx = find(strcmp('dataset_code',df(1,:)));
dataset_codes = unique(df(2:end,idx));
assert(length(dataset_codes) == 1);
assert(dataset_codes{1} == "ZUTN");
assert(strcmp(dataset_codes{1},'ZUTN'));
idx = find(strcmp('series_code',df(1,:)));
series_codes = unique(df(2:end,idx));
......
function test_fetch_series_with_na_values() % --*-- Unitary tests --*--
df = fetch_series('provider_code', "AMECO", 'dataset_code', "ZUTN", 'series_code', "DEU.1.0.0.0.ZUTN");
df = fetch_series('provider_code', 'AMECO', 'dataset_code', 'ZUTN', 'series_code', 'DEU.1.0.0.0.ZUTN');
idx = find(strcmp('provider_code',df(1,:)));
provider_codes = unique(df(2:end,idx));
assert(length(provider_codes)==1);
assert(provider_codes{1} == "AMECO");
assert(strcmp(provider_codes{1},'AMECO'));
idx = find(strcmp('dataset_code',df(1,:)));
dataset_codes = unique(df(2:end,idx));
assert(length(dataset_codes) == 1);
assert(dataset_codes{1} == "ZUTN");
assert(strcmp(dataset_codes{1},'ZUTN'));
idx = find(strcmp('series_code',df(1,:)));
series_codes = unique(df(2:end,idx));
assert(series_codes{1} == "DEU.1.0.0.0.ZUTN");
assert(strcmp(series_codes{1},'DEU.1.0.0.0.ZUTN'));
idx = find(strcmp('original_value',df(1,:)));
assert(any(strcmp('NA', df(2:end,idx))) == true);
......
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