Commit 2841e9df authored by Dóra Kocsis's avatar Dóra Kocsis

cosmetics

parent 27e5ce24
......@@ -37,7 +37,6 @@ function df = fetch_series_by_api_link(api_link, varargin)
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
default_editor_base_url = 'https://editor.nomics.world/api/v1/';
p = inputParser;
......@@ -48,11 +47,11 @@ 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)
df = {};
return
else
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
......@@ -60,7 +59,7 @@ else
dimensions_codes_columns_names = {};
dataset_codes = fieldnames(datasets_dimensions);
for ii = 1:length(fieldnames(datasets_dimensions))
for ii = 1:length(dataset_codes)
dataset_dimensions = datasets_dimensions.(dataset_codes{ii});
dimensions_codes_columns_names = dataset_dimensions.dimensions_codes_order';
for jj = 1:length(dataset_dimensions.dimensions_codes_order)
......@@ -87,16 +86,14 @@ else
end
df = cell(length(series_list{1}.value)*length(series_list)+1,length(ordered_columns_names));
for col = 1:length(ordered_columns_names)
col_ = ordered_columns_names{col};
df{1,col} = col_;
end
df(1,:) = ordered_columns_names;
series_length=0;
% Flatten series received from the API (rename some keys of JSON result to match DataFrame organization)
series_length=0;
% Flatten series received from the API (rename some keys of JSON result to match cell array organization)
for ii = 1:length(series_list)
if ~isfield(series_list{ii}, 'filtered')
flat_series = flatten_dbnomics_series(series_list{ii});
% Add dimensions labels to flat_series
complete_dataset_code = [flat_series.provider_code '_' flat_series.dataset_code];
dataset_dimensions = datasets_dimensions.(complete_dataset_code);
......@@ -116,7 +113,7 @@ else
dimension_label = dataset_dimensions_labels.(dimension_codes{jj});
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
if isstrprop(dimension_value_code(1), 'digit') %MATLAB doesn't allow struct field names to start with a digit
dimension_value_code = strcat('x', dimension_value_code);
end
try
......
......@@ -32,6 +32,7 @@ function series = flatten_dbnomics_series(series)
series = normalize_period(series);
series = normalize_value(series);
% Flatten dimensions.
if isfield(series, 'dimensions')
dimensions = series.dimensions;
......
......@@ -29,12 +29,7 @@ function series = normalize_period(series)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
period = series.period;
period_start_day = series.period_start_day;
series.original_period = series.period;
series.period = cellfun(@(x)datestr(datetime(x,'InputFormat','yyyy-MM-dd'),29),series.period_start_day, 'UniformOutput',false);
series = rmfield(series, 'period_start_day');
series.original_period = period;
for ii = 1:length(period_start_day)
series.period{ii,1} = datestr(datetime(period_start_day{ii},'InputFormat','yyyy-MM-dd'),29);
end
end
......@@ -31,13 +31,7 @@ function series = normalize_value(series)
if iscell(series.value)
series.original_value = series.value;
value = series.value;
for ii = 1:length(value)
if strcmp(value{ii}, 'NA')
value{ii} = NaN;
end
end
series.value = value;
series.value(cell2mat(cellfun(@(x)strcmp(x,'NA'),series.value,'UniformOutput',false))) = {NaN};
else
series.original_value = num2cell(series.value);
series.value = num2cell(series.value);
......
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