diff --git a/README.md b/README.md index 215fddb2cc501fd834c6b6e80491404b5e6fee95..080249678daf59219c818e87522d4cb6eafc8486 100644 --- a/README.md +++ b/README.md @@ -42,35 +42,22 @@ Example: >> 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 +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 as a table (including the column headers), type: - >> df_id(1:4,:) - - 6�16 cell array - - Columns 1 through 5 - - {'x_frequency'} {'provider_code'} {'dataset_code'} {'dataset_name' } {'series_code' } - {'annual' } {'AMECO' } {'ZUTN' } {'Unemployment ra�'} {'EA19.1.0.0.0.ZUTN'} - {'annual' } {'AMECO' } {'ZUTN' } {'Unemployment ra�'} {'EA19.1.0.0.0.ZUTN'} - {'annual' } {'AMECO' } {'ZUTN' } {'Unemployment ra�'} {'EA19.1.0.0.0.ZUTN'} - - Columns 6 through 11 - - {'series_name' } {'original_period'} {'period' } {'original_value'} {'value'} {'freq'} - {'Annually � (Per�'} {'1960' } {'1960-01-01'} {'NA' } {[ NaN]} {'a' } - {'Annually � (Per�'} {'1961' } {'1961-01-01'} {'NA' } {[ NaN]} {'a' } - {'Annually � (Per�'} {'1962' } {'1962-01-01'} {'NA' } {[ NaN]} {'a' } - - Columns 12 through 16 - - {'unit' } {'geo' } {'Frequency'} {'Unit' } {'Country' } - {'percentage-of-a�'} {'ea19'} {'Annually' } {'(Percentage of �'} {'Euro area'} - {'percentage-of-a�'} {'ea19'} {'Annually' } {'(Percentage of �'} {'Euro area'} - {'percentage-of-a�'} {'ea19'} {'Annually' } {'(Percentage of �'} {'Euro area'} - + >> tab_id = cell2table(df_id(2:end,:), 'VariableNames', df_id(1,:)); + >> tab_id(1:3,:) + + 3×16 table + x_frequency provider_code dataset_code dataset_name series_code series_name original_period period original_value value freq unit geo Frequency Unit Country + ___________ _____________ ____________ __________________________________________________________________ _____________________ ____________________________________________________________ _______________ ______________ ______________ _____ _____ ___________________________________ ________ ____________ _____________________________________ _____________ + + {'annual'} {'AMECO'} {'ZUTN'} {'Unemployment rate: total :- Member States: definition EUROSTAT'} {'EA19.1.0.0.0.ZUTN'} {'Annually – (Percentage of active population) – Euro area'} {'1960'} {'1960-01-01'} {'NA'} NaN {'a'} {'percentage-of-active-population'} {'ea19'} {'Annually'} {'(Percentage of active population)'} {'Euro area'} + {'annual'} {'AMECO'} {'ZUTN'} {'Unemployment rate: total :- Member States: definition EUROSTAT'} {'EA19.1.0.0.0.ZUTN'} {'Annually – (Percentage of active population) – Euro area'} {'1961'} {'1961-01-01'} {'NA'} NaN {'a'} {'percentage-of-active-population'} {'ea19'} {'Annually'} {'(Percentage of active population)'} {'Euro area'} + {'annual'} {'AMECO'} {'ZUTN'} {'Unemployment rate: total :- Member States: definition EUROSTAT'} {'EA19.1.0.0.0.ZUTN'} {'Annually – (Percentage of active population) – Euro area'} {'1962'} {'1962-01-01'} {'NA'} NaN {'a'} {'percentage-of-active-population'} {'ea19'} {'Annually'} {'(Percentage of active population)'} {'Euro area'} + >> + In such cell array, you will always find at least those columns: * `x_frequency`: (harmonized frequency generated by DBnomics) diff --git a/src/fetch_series.m b/src/fetch_series.m index b437dcfa5c8b01547a696ca644048878ad05e288..5ef4655220f9e6f528ffe78bc3bf4031da3fe888 100644 --- a/src/fetch_series.m +++ b/src/fetch_series.m @@ -95,7 +95,7 @@ if ~isa(p.Results.dimensions, 'function_handle') if isempty(p.Results.provider_code) || isempty(p.Results.dataset_code) error('When you use dimensions, you must specifiy provider_code and dataset_code.'); end - api_link = sprintf('%s/%s/%s?observations=1&dimensions=%s', series_base_url, p.Results.provider_code, p.Results.dataset_code, p.Results.dimensions); %jsonencode( + api_link = sprintf('%s/%s/%s?observations=1&dimensions=%s', series_base_url, p.Results.provider_code, p.Results.dataset_code, p.Results.dimensions); end if ~isempty(p.Results.series_code) diff --git a/src/fetch_series_by_api_link.m b/src/fetch_series_by_api_link.m index 1092c459a4de87bb5b115181d8b49f855817123a..adc6fc784aba2b14a797b3f560e69c3b3e714bba 100644 --- a/src/fetch_series_by_api_link.m +++ b/src/fetch_series_by_api_link.m @@ -47,6 +47,7 @@ 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{:}); + [datasets_dimensions, series_dims_by_dataset_code, series_list]= iter_series_info(api_link, p.Results.max_nb_series); if isempty(series_list) @@ -166,7 +167,7 @@ else end end series_length=series_length+length(flat_series.value); - end + end end end diff --git a/src/initialize_mdbnomics.m b/src/initialize_mdbnomics.m index 3cf356e25da0d3a3437804d78b47689aa2769835..7db683f7a1bdee43600625a511e17c2c154013b9 100644 --- a/src/initialize_mdbnomics.m +++ b/src/initialize_mdbnomics.m @@ -38,7 +38,7 @@ if ~exist('matlab_ver_less_than','file') end if ~exist('octave_ver_less_than','file') - p{end+1} = 'missing/matlab_ver_less_than'; + p{end+1} = 'missing/octave_ver_less_than'; end if exist('OCTAVE_VERSION', 'builtin') && ~exist('user_has_octave_forge_package','file') @@ -50,10 +50,8 @@ P = cellfun(@(c)[mdbnomics_src_root c], p, 'uni', false); addpath(P{:}); % Check minimal MATLAB and Octave requirements. -if isoctave && octave_ver_less_than('6') - error('The minimum Octave requirement of this package is version 6.'); -elseif matlab_ver_less_than('8.5') - error('The minimum MATLAB requirement of this package is R2015a.'); +if (isoctave && octave_ver_less_than('6')) || matlab_ver_less_than('8.5') + error('The minimum MATLAB requirement of this package is R2015a, and the minimum Octave requirement of this package is version 6.'); end assignin('caller', 'mdbnomics_src_root', mdbnomics_src_root); diff --git a/src/utils/fetch_series_page.m b/src/utils/fetch_series_page.m index cbe20615ca0ee27e871caed83e7688c04cb7981f..8ecfc352b76dd9655bc8a814aa7f2508253eb579 100644 --- a/src/utils/fetch_series_page.m +++ b/src/utils/fetch_series_page.m @@ -44,8 +44,19 @@ catch ME error(error_message); end -series_page = response_json.series; -if ~isempty(series_page) - assert(series_page.offset == offset); +if isempty(response_json.errors) + series_page = response_json.series; + if ~isempty(series_page) + assert(series_page.offset == offset); + end +else + error_ = response_json.errors; + if ~isempty(error_.dataset_code) && isempty(error_.series_code) + error('%s for: %s. Please revise your input for dataset code.', error_.message, error_.dataset_code); + elseif ~isempty(error_.provider_code) && isempty(error_.series_code) + error('%s for: %s. Please revise your input for series provider.', error_.message, error_.provider_code); + elseif ~isempty(error_.series_code) + error('%s for: %s. Please revise your input for series code.', error_.message, error_.series_code); + end end end diff --git a/src/utils/iter_filtered_series.m b/src/utils/iter_filtered_series.m index a83774804c483afa47f806f315183239841e214c..a7fb491a27f5aeaa432cb938c7af110274b8bf79 100644 --- a/src/utils/iter_filtered_series.m +++ b/src/utils/iter_filtered_series.m @@ -57,8 +57,12 @@ for gg = 1:size(grouped_series, 2) try response = webwrite(apply_endpoint_url, json_request, opts); - catch - error("Invalid response from Time Series Editor (JSON expected)"); + catch ME + error_message = ['Could not fetch data from URL: ' apply_endpoint_url ' because: ' ME.identifier]; + if strcmp(ME.identifier, 'MATLAB:webservices:HTTP400StatusCodeError') + error_message = sprintf('%s.\nPlease revise your input for the filter.', error_message); + end + error(error_message); end filtered_series_list = cell(1,size(series_list,2)); diff --git a/src/utils/normalize_value.m b/src/utils/normalize_value.m index b2d8545e96eb955d57df2b3f284402edd4729713..fb2b896885363fe2715749c1b5ef4f207964f602 100644 --- a/src/utils/normalize_value.m +++ b/src/utils/normalize_value.m @@ -30,7 +30,10 @@ function series = normalize_value(series) % along with Dynare. If not, see <http://www.gnu.org/licenses/>. if iscell(series.value) - series.original_value = series.value; +% series.original_value = cellfun(@char, series.value, 'UniformOutput', false); + series.original_value = cellfun(@num2str,series.value,'un',0); + +% series.original_value = char(series.value); series.value(strcmp(series.value, 'NA')) = {NaN}; else series.original_value = num2cell(series.value);