From a41c7641dbaf42f080574f0eea101bbbdb6037bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3ra=20Kocsis?= <dora@dynare.org> Date: Mon, 25 May 2020 10:36:13 +0200 Subject: [PATCH] Cosmetics --- README.md | 10 +++++----- archive/template.m | 27 ++++++++++++--------------- src/fetch_series.m | 2 +- src/fetch_series_by_api_link.m | 7 ++++++- src/utils/normalize_value.m | 3 --- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 0802496..170750a 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ [](https://git.dynare.org/DoraK/mdbnomics/commits/master) -This MATLAB/Octave toolbox comes with routines to access DBnomics time series from MATLAB. +This MATLAB toolbox comes with routines to access DBnomics time series from MATLAB. -The package is compatible with MATLAB 2019b and following versions, and (almost compatible with) -the latest Octave version. +The package is compatible with MATLAB 2019b and following versions. +Octave compability will follow after the release of Octave 6 (an implementation to webread/webwrite/jsondecode is required). ## Installation @@ -19,12 +19,12 @@ or downloading a zip archive: ## Usage -Add the `mdbnomics/src` folder to the MATLAB/Octave path, and run the following command (on MATLAB/Octave) prompt: +Add the `mdbnomics/src` folder to the MATLAB path, and run the following command (on MATLAB) prompt: >> initialize_mdbnomics() which, depending on your system, will add the necessary subfolders to -the MATLAB/Octave path. +the MATLAB path. You are then ready to go. A full documentation will come soon. diff --git a/archive/template.m b/archive/template.m index 51cdb18..5e51621 100644 --- a/archive/template.m +++ b/archive/template.m @@ -1,44 +1,41 @@ % fetch series by provider code and dataset code -test = fetch_series('provider_code', 'AMECO', 'dataset_code', 'UVGD', 'max_nb_series', 500); -ds = to_dseries(df); +test = fetch_series('provider_code', 'AMECO', 'dataset_code', 'UVGD', 'max_nb_series', 50); +ds = dbnomics_to_dseries(test); % fetch one series by ID df_id = fetch_series('series_ids','AMECO/ZUTN/EA19.1.0.0.0.ZUTN'); -ds_id = to_dseries(df_id); +ds_id = dbnomics_to_dseries(df_id); % 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'}); -ds_ids = to_dseries(df_ids); +ds_ids = dbnomics_to_dseries(df_ids); % 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'}); +ds_ids_sets = dbnomics_to_dseries(df_ids_sets); % 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'); -ds_code_mask1 = to_dseries(df_code_mask1); +ds_code_mask1 = dbnomics_to_dseries(df_code_mask1); df_code_mask2 = fetch_series('provider_code', 'IMF', 'dataset_code', 'CPI', 'series_code', '.FR.PCPIEC_WT'); -ds_code_mask2 = to_dseries(df_code_mask1); +ds_code_mask2 = dbnomics_to_dseries(df_code_mask2); % 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 df_dim = fetch_series('provider_code','AMECO', 'dataset_code', 'ZUTN', 'dimensions', '{"geo":["dnk"]}'); -ds_dim = to_dseries(df_dim); +ds_dim = dbnomics_to_dseries(df_dim); df_dims = fetch_series('provider_code','WB','dataset_code','DB', 'dimensions', '{"country":["ES","FR","IT"],"indicator":["IC.REG.COST.PC.FE.ZS.DRFN"]}'); -ds_dims = to_dseries(df_dims); +ds_dims = dbnomics_to_dseries(df_dims); % 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'); -ds_link = to_dseries(df_link); +ds_link = dbnomics_to_dseries(df_link); % 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'); -ds_cart = to_dseries(df_cart); - -%% -% 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'}); -ds_ids_sets = to_dseries(df_ids_sets); +ds_cart = dbnomics_to_dseries(df_cart); % fetch multi frequency series df_multi_freq = fetch_series('series_ids', {'BEA/NIUnderlyingDetail-U001BC/S315-A',... diff --git a/src/fetch_series.m b/src/fetch_series.m index 5ef4655..511f9ff 100644 --- a/src/fetch_series.m +++ b/src/fetch_series.m @@ -278,7 +278,7 @@ end %$ t(3) = dassert(df(2,2), {'AMECO'}); %$ t(4) = dassert(length(unique(df(2:end,3))),1); %$ t(5) = dassert(df(2,3), {'ZUTN'}); -%$ t(6) = dassert(length(unique(df(2:end,5))), 49); +%$ t(6) = dassert(length(unique(df(2:end,5))), 48); %$ end %$ %$ T = all(t); diff --git a/src/fetch_series_by_api_link.m b/src/fetch_series_by_api_link.m index adc6fc7..14768d1 100644 --- a/src/fetch_series_by_api_link.m +++ b/src/fetch_series_by_api_link.m @@ -86,7 +86,12 @@ else series_list = [series_list, filtered_series_list]; end - df = cell(length(series_list{1}.value)*length(series_list)+1,length(ordered_columns_names)); + %%%%%%% OPTIMIZE SIZE PRE-ALLOCATION %%%%%%% + rows_ = 0; + for s = 1:length(series_list) + rows_ = rows_ + length(series_list{s}.value); + end + df = cell(rows_+1,length(ordered_columns_names)); df(1,:) = ordered_columns_names; series_length=0; diff --git a/src/utils/normalize_value.m b/src/utils/normalize_value.m index fb2b896..a94ef91 100644 --- a/src/utils/normalize_value.m +++ b/src/utils/normalize_value.m @@ -30,10 +30,7 @@ function series = normalize_value(series) % along with Dynare. If not, see <http://www.gnu.org/licenses/>. if iscell(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); -- GitLab