Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

function to load indicator tabulation to HDX #12

Open
Edouard-Legoupil opened this issue Dec 6, 2017 · 1 comment
Open

function to load indicator tabulation to HDX #12

Edouard-Legoupil opened this issue Dec 6, 2017 · 1 comment

Comments

@Edouard-Legoupil
Copy link
Member

If indicators is not classified as sensitive, the value should be pushed to an on line repository (CKAN based) such as http://data.humdata.org/

This probably requires to:

  1. tag the variable according to HXL: http://hxlstandard.org/
  2. upload it through the API: Replicating or embedding the python work here https://github.com/OCHA-DAP/hdx-python-api
@dickoa
Copy link

dickoa commented Jan 19, 2018

@Edouard-Legoupil thanks for the suggestion and I would be happy to make a PR to add this functionality. As suggested on option is to wrap the Python API, see below:

library(reticulate)
library(tidyverse)


### Example from the github page https://github.com/OCHA-DAP/hdx-python-api#getting-started
hdx <- import("hdx")
conf <- hdx$hdx_configuration$Configuration
conf$create(hdx_site = "demo", hdx_read_only = FALSE) ### demo

### You need to follow for your CKAN API Key https://github.com/OCHA-DAP/hdx-python-api#obtaining-your-api-key
config <- conf$read()
key <- config$get_api_key()

### Function to create dataset and resource
dataset <- hdx$data$dataset$Dataset
resource <- hdx$data$resource$Resource


### Create a dataset
meta <- list(name = "iris_flower",
            title = "Iris flower data set",
            notes = "Typical test case for classification algorithm",
            methodology = "Other",
            methodology_other = "Collected by Ronald Fisher",
            dataset_source = "Gondwana",
            subnational = 1,
            license_id = "hdx_other",
            private = FALSE,
            url = "http://dickoa.gitlab.io")

### We create the dataset from the dict
df <- dataset(r_to_py(meta))

### Need to add a maintainer, set org and other metadata
df$set_maintainer(key)
df$set_organization('5a63012e-6c41-420c-8c33-e84b277fdc90') ## Innago
df$set_dataset_date(as.character(Sys.Date()))
df$set_expected_update_frequency("Every two weeks")
df$add_country_location("MLI")
df$add_tags(r_to_py(list("Rstats", "test")))

### Create a resource and add it to the dataset
tmp_file <- tempfile(fileext = ".csv")
write_csv(iris, path = tmp_file)
res <- list(name = "iris.csv", format = "csv", description = "iris data csv")
res <- resource(r_to_py(res))
res$set_file_to_upload(tmp_file)

### add to the dataset
df$add_update_resource(r_to_py(res))

### Push
df$create_in_hdx()

screen_hdx

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants