Skip to content

Commit

Permalink
Correct function get_geo_names() and additional_geo_mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
s915 committed Sep 15, 2019
1 parent 360da65 commit b9200fc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
17 changes: 16 additions & 1 deletion src/rdb_by_api_link.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,24 @@ function rdb_by_api_link(
additional_geo_mapping = get_geo_names(DBdata, additional_geo_column)
remove_provider!(additional_geo_column)
# Check coherence
if !isa(additional_geo_column, Nothing) & !isa(additional_geo_mapping, Nothing)
if isa(additional_geo_column, Nothing) | isa(additional_geo_mapping, Nothing)
additional_geo_column = additional_geo_mapping = nothing
else
keep = []
if length(additional_geo_column) != length(additional_geo_mapping)
additional_geo_column = additional_geo_mapping = nothing
else
for iaddg in 1:length(additional_geo_column)
if !isa(additional_geo_column[iaddg], Nothing) & !isa(additional_geo_mapping[iaddg], Nothing)
push!(keep, iaddg)
end
end
end
if length(keep) == 0
additional_geo_column = additional_geo_mapping = nothing
else
additional_geo_column = additional_geo_column[keep]
additional_geo_mapping = additional_geo_mapping[keep]
end
end
end
Expand Down
59 changes: 35 additions & 24 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -516,45 +516,56 @@ end
get_geo_names(x::Dict, colname::Nothing) = nothing
function get_geo_names(x::Dict, colname::Array)
# First try with multiple datasets
try
nm = try
x["datasets"];
"datasets"
catch
"dataset"
end

if nm == "datasets"
result = map(colname) do u
k = replace(u[1], r".*/" => "")

z = retrieve(x["datasets"][u[1]], Regex("^" * u[2] * "\$"))
z = to_dataframe(z[1])
z = stack(z, names(z))
z[selectop, :variable] = string.(z[selectop, :variable])
names!(z, Symbol.(u[2:3]))

insertcols!(z, 1, :dataset_code => k)
try
z = to_dataframe(z[1])
z = stack(z, names(z))
z[selectop, :variable] = string.(z[selectop, :variable])
names!(z, Symbol.(u[2:3]))

insertcols!(z, 1, :dataset_code => k)
catch
z = nothing
end
z
end
return result
catch
elseif nm == "dataset"
# Second try with only one dataset
try
result = map(colname) do u
subdict = x["dataset"]
k = replace(u[1], r".*/" => "")

keys_ = [string(key) for key in keys(subdict)]
k_ = keys_[
occursin.(Ref(r"^dimensions_value[s]*_label[s]*$"), keys_)
]

z = subdict[k_[1]][u[2]]
result = map(colname) do u
subdict = x["dataset"]
k = replace(u[1], r".*/" => "")

keys_ = [string(key) for key in keys(subdict)]
k_ = keys_[
occursin.(Ref(r"^dimensions_value[s]*_label[s]*$"), keys_)
]

z = subdict[k_[1]][u[2]]
try
z = to_dataframe(z)
z = stack(z, names(z))
z[selectop, :variable] = string.(z[selectop, :variable])
names!(z, Symbol.(u[2:3]))

insertcols!(z, 1, :dataset_code => k)
z
catch
z = nothing
end
return result
catch
return nothing
z
end
else
nothing
end
end

Expand Down

0 comments on commit b9200fc

Please sign in to comment.