Commit 1c3767bd authored by Dóra Kocsis's avatar Dóra Kocsis

modify template, add default_editor_base_url

parent 88bb9f55
......@@ -36,6 +36,8 @@ function df = fetch_series(varargin)
%
default_api_base_url = 'https://api.db.nomics.world/v22/';
default_editor_base_url = 'https://editor.nomics.world/api/v1/';
p = inputParser;
validStringInput = @(x) isstring(x) || ischar(x) || iscellstr(x);
p.addParameter('provider_code', '', validStringInput);
......@@ -92,6 +94,6 @@ if ~isempty(p.Results.series_ids)
end
api_link = sprintf('%s?observations=1&series_ids=%s', series_base_url, strjoin(p.Results.series_ids,','));
end
df = fetch_series_by_api_link(api_link, p.Results.dbnomics_filters, p.Results.max_nb_series);
df = fetch_series_by_api_link(api_link, p.Results.dbnomics_filters, p.Results.max_nb_series, default_editor_base_url);
end
......@@ -5,10 +5,14 @@ function df = fetch_series_by_api_link(api_link, varargin)
% Example:
% fetch_series_by_api_link("https://api.db.nomics.world/v22/series?provider_code=AMECO&dataset_code=ZUTN")
default_editor_base_url = 'https://editor.nomics.world/api/v1/';
p = inputParser;
validStringInput = @(x) isstring(x) || ischar(x) || iscellstr(x);
p.addRequired('api_link');
p.addOptional('dbnomics_filters', '',@ischar);
p.addOptional('max_nb_series', NaN, @isnumeric);
p.addOptional('editor_api_base_url', default_editor_base_url, validStringInput);
p.KeepUnmatched = false;
p.parse(api_link, varargin{:});
......@@ -68,7 +72,7 @@ else
flat_series.labels{jj, 1} = dimension_label;
dimension_value_code = regexprep(series_dims_by_dataset_code.(complete_dataset_code).(series_code).(dimension_codes{jj}),'[^a-zA-Z0-9]','_');
if isstrprop(dimension_value_code(1), 'digit') %MATLAB doesn't allow struct fieldnames to start with a digit
dimension_value_code = ['x' dimension_value_code];
dimension_value_code = strcat('x', dimension_value_code);
end
try
flat_series.labels{jj, 2} = dataset_dimensions.dimensions_values_labels.(dimension_codes{jj}).(dimension_value_code);
......
......@@ -27,5 +27,5 @@ df_multi_freq = fetch_series('series_ids', ["BEA/NIUnderlyingDetail-U001BC/S315-
%% TO BE IMPLEMENTED
% fetch one series and apply interpolation filter %NOT IMPLEMENTED
df_filter = fetch_series('series_ids', "AMECO/ZUTN/EA19.1.0.0.0.ZUTN",...
'dbnomics_filters', '{"code":["interpolate"], "parameters": {"frequency": ["monthly"], "method": ["spline"]}}');
'dbnomics_filters', '[{"code": "interpolate", "parameters": {"frequency": "monthly", "method": "spline"}}]');
function run_all_tests()
r = [];
r = [r; run_this_test('test_fetch_series_by_code')];
r = [r; run_this_test('test_fetch_series_by_code_mask')];
r = [r; run_this_test('test_fetch_series_by_code_mask_with_plus_in_dimension_code')];
r = [r; run_this_test('test_fetch_series_by_id')];
r = [r; run_this_test('test_fetch_series_by_ids_in_same_dataset')];
r = [r; run_this_test('test_fetch_series_by_ids_in_different_datasets')];
r = [r; run_this_test('test_fetch_series_by_dimension')];
r = [r; run_this_test('test_fetch_series_of_dataset')];
r = [r; run_this_test('test_fetch_series_by_api_link')];
r = [r; run_this_test('test_fetch_series_with_na_values')];
r = [r; run_this_test('test_fetch_series_with_max_nb_series')];
print_results(r);
function o = run_this_test(file)
try
tstart = tic;
run([file '.m']);
elapsed = toc(tstart);
o = {file, true, elapsed};
catch
o = {file, false, NaN};
end
function print_results(r)
message = sprintf('Testsuite results:\n');
for i = 1:size(r, 1)
if r{i,2}
message = sprintf('%s\n%s\t\t PASS (%ss)', message, r{i,1}, num2str(r{i,3}));
else
message = sprintf('%s\n%s\t\t FAILED', message, r{i,1});
end
end
disp(message)
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