Commit 59ecec16 authored by Pauline Maury Laribière's avatar Pauline Maury Laribière
Browse files

documentation

parent cbda14f5
Pipeline #270141 passed with stage
in 26 seconds
......@@ -9,250 +9,86 @@ This public library is made available for the internal FSO staff, the federal ad
## Installation
You can install the library with
## Functionnalities
Based on the metadata that you want, you will call certain functions and parameters.
In the first part, we describe the API available from everywhere, then we describe the API available only from within the confederation network.
### Available everywhere with the interoperability plateform (i14y)
#### Codelists
1. Export a codelist based on an identifier
```
response = get_codelist(identifier, export_format="SDMX-ML", version_format=2.1, annotations=False)
install.packages("fso.metadata")
```
Parameters:
- identifier (str): the codelist's identifier
- export_format (str, default="SDMX-ML"): the export's format.
Available are CSV, XLSX, SDMX-ML or SDMX-JSON.
- version_format (float, default=2.1): the export format's version
(2.0 or 2.1 when format is SDMX-ML).
- annotations (bool, default=False): flag to include annotations
Returns:
- response (pd.DataFrame or dict) based on the export format
- a pd.DataFrame if export_format was CSV or XLSX
- a dictionnary if export_format was SDMX-ML or SDMX-JSON.
#### ContentConfigurations
1. Return the display information for the available configured content
then at the beginning of your R script, you will need to
```
response = get_content_creation()
library("fso.metadata")
```
Returns:
- response (dict): the configured content's display information
2. Return an identifier's nomenclature's information
```
response = get_identifier_content(identifier)
```
Parameters:
- identifier (str): the nomenclature's identifier
Returns:
- response (dict): the nomenclature's information
## Functionnalities
Based on the metadata that you want, you will call certain functions and parameters.
#### Datasets
1. Get the dataset description
### Codelists
1. Export a codelist based on an identifier
```
response = get_dataset_description(identifier, language='fr')
codelist <- get_codelist(identifier, export_format, version_format, annotations)
```
Parameters:
- identifier (str): the nomenclature's identifier
- language (str, default='fr'): the language of the response data.
Available are 'fr', 'de', 'it', 'en'.
- identifier ("character"): the codelist's identifier
- export_format ("character", default="SDMX-ML"): the export's format.
Available are CSV, XLSX, SDMX-ML or SDMX-JSON.
- version_format ("numeric", default=2.1): the export format's version
(2.0 or 2.1 when format is SDMX-ML).
- annotations (bool, default=FALSE): flag to include annotations
Returns:
- response: description's dictionnary
2. Get the dataset information
```
response = get_dataset_information(identifier, language='fr')
```
- codelist (data.frame) based on the export format
- a data.frame if export_format was CSV or XLSX
- a json if export_format was SDMX-ML or SDMX-JSON.
Parameters:
- identifier (str): the nomenclature's identifier
- language (str, default='fr'): the language of the response data.
Available are 'fr', 'de', 'it', 'en'.
Returns:
- response: information's dictionnary
#### Data Structures
### Data Structures
1. Get the data structure
```
response = get_data_structure(identifier, language='fr')
data_structure <- get_data_structure(identifier, language)
```
Parameters:
- identifier (str): the nomenclature's identifier
- language (str, default='fr'): the language of the response data.
- identifier ("character"): the nomenclature's identifier
- language ("character", default='fr'): the language of the response data.
Available are 'fr', 'de', 'it', 'en'.
Returns:
- response: data structure's dictionnary
- data_structure: data structure
#### Nomenclatures
1. Get the nodes of a path within a nomenclature
```
response = get_nomenclature_path_nodes(identifier, path, filters={}, language='fr')
```
Parameters:
- identifier (str): the nomenclature's identifier
- path (str): the path leading to the nodes
- filters (dict, default={}): the filters to apply
- language (str, default='fr'): the language of the response data.
Available are 'fr', 'de', 'it', 'en'.
Returns:
- response: dictionnary of the nodes
### Nomenclatures
2. Export one level of a nomenclature
1. Export one level of a nomenclature
```
response = get_nomenclature_one_level(identifier, level_number, filters={}, language='fr', annotations=False)
one_level_df <- get_nomenclature_one_level(identifier, level_number, filters, language, annotations)
```
Parameters:
- identifier (str): nomenclature's identifier
- level_number (int): level to export
- filter (default={}): additionnal filters
- language (str, default='fr'): response data's language
- identifier ("character"): nomenclature's identifier
- level_number ("numeric"): level to export
- filter (hash::hash): additionnal filters (hash)
- language ("character", default='fr'): response data's language
Available are 'fr', 'de', 'it', 'en'.
- annotations (bool, default=False): flag to include annotations
- annotations (bool, default=FALSE): flag to include annotations
Returns:
- response (pd.DataFrame): dataframe with 3 columns
- response (data.frame): dataframe with 3 columns
(Code, Parent and Name in the selected language)
3. Export multiple levels of a nomenclature (from `level_from` to `level_to`)
2. Export multiple levels of a nomenclature (from `level_from` to `level_to`)
```
response = get_nomenclature_multiple_levels(identifier, level_from, level_to, filters={}, language='fr', annotations=False)
multiple_levels_df = get_nomenclature_multiple_levels(identifier, level_from, level_to, filters, language, annotations)
```
Parameters:
- identifier (str): nomenclature's identifier
- level_from (int): the 1st level to include
- level_to (int): the last level to include
- filter (default={}): additionnal filters
- language (str, default='fr'): response data's language
- identifier ("character"): nomenclature's identifier
- level_from ("numeric"): the 1st level to include
- level_to ("numeric"): the last level to include
- filter (hash::hash): additionnal filters
- language ("character", default='fr'): response data's language
Available are 'fr', 'de', 'it', 'en'.
- annotations (bool, default=False): flag to include annotations
- annotations (bool, default=FALSE): flag to include annotations
Returns:
- response (pd.DataFrame): dataframe columns from `level_from` to `level_to` codes
4. Search query within a nomenclature
```
response = query_nomenclature(identifier, query, page_number, page_size, fiters={}, language='fr')
```
Parameters:
- identifier (str): the nomenclature's identifier
- query (str): the search query
- page_number (int): the number of the result page to return
- page_size (int): the size of each page result
- filter (default={}): additionnal filters
- language (str, default='fr'): response data's language
Available are 'fr', 'de', 'it', 'en'.
Returns:
- response (dict): the query result
### Available only internally (Intern to confederation or via VPN)
All these function start with `dcat_`
#### Agents
1. List all agents
```
response = dcat_list_all_agents()
```
Returns:
- response (dict): all agents
2. Get the agent with the corresponding agent id
```
response = dcat_get_agent_from_id(agent_id)
```
Parameters:
- agent_id (str): agent's id
Returns:
- response (dict): agent with this id
#### Datasets
1. List all datasets
```
response = dcat_list_all_datasets()
```
Returns:
- response (dict): list of all datasets
2. Get all distributions for the dataset with the corresponding dataset id
```
response = dcat_get_distributions_from_dataset_id(dataset_id)
```
Parameters:
- dataset_id (str): dataset's id
Returns:
- response (dict): distributions for the dataset with dataset's id
3. Get the dataset with the corresponding id
```
response = dcat_get_dataset_from_id(dataset_id)
```
Parameters:
- dataset_id (str): dataset's id
Returns:
- response (dict): the dataset
4. Get the dataset with the corresponding identifier
```
response = dcat_get_dataset_from_identifier(identifier: str)
```
Parameters:
- identidier (str): dataset's identifier
Returns:
- response (dict): the dataset
5. Get all distributions for the dataset with the corresponding dataset identifier.
```
response = dcat_get_distributions_from_dataset_identifier(identifier)
```
Parameters:
- identidier (str): dataset's identifier
Returns:
- response (dict): all distributions for the dataset with the corresponding identifier
#### Distribution
1. List all distributions
```
response = dcat_list_all_distributions()
```
Returns:
- response (dict): all distributions
2. Get the distribution with the corresponding id
```
response = dcat_get_distribution_from_id(distribution_id)
```
Parameters:
- distribution_id (str): distribution's id
Returns:
- response (dict): the distribution
- multiple_levels_df (data.frame): dataframe columns from `level_from` to `level_to` codes
As the APIs continue to be implemented, further functionnalities will be added.
......@@ -264,4 +100,4 @@ All the APIs made available in this library are also documented in Swagger UI sh
## Example
Examples for each API are provided in the [R Markdown](https://TODO).
\ No newline at end of file
Examples for each API are provided in the [R Markdown](https://renkulab.io/gitlab/pauline.maury-laribiere/metadata-auto-r-library/-/blob/r_apis/example.Rmd).
......@@ -14,12 +14,12 @@ knitr::opts_chunk$set(echo = TRUE)
You can install the library with
```{r install}
install.packages("fso_metadata")
install.packages("fso.metadata")
```
then at the beginning of your R script, you will need to
```{r library}
library("fso_metadata")
library("fso.metadata")
```
......@@ -41,8 +41,8 @@ get_data_structure(identifier='HCL_NOGA', language='it')
## Nomenclature
```{r , echo=FALSE}
my_filters <- hash::hash(
'prop1'= list("string"),
'prop2' = list("string", "string2")
'AF_ACTIVE'= list("0"),
'AFC_ISCO_REDUCED_LIST' = list("1")
)
```
......
......@@ -23,7 +23,6 @@ api_class <- setRefClass(
id = "character",
language = "character",
version_format = "numeric",
path = "character",
api_url = "character"
),
methods = list(
......@@ -32,8 +31,7 @@ api_class <- setRefClass(
parameters = "",
id = "",
language = "en",
version_format = 2.1,
path = ".") {
version_format = 2.1) {
callSuper(
...,
export_format = export_format,
......@@ -41,9 +39,8 @@ api_class <- setRefClass(
id = id,
language = language,
version_format = version_format,
path = path
)
get_url()
get_url(id, export_format, version_format, language)
},
get_response = function() {
request_function <- REQUEST_FUNCTION_MAPPING[[export_format]]
......@@ -54,9 +51,8 @@ api_class <- setRefClass(
}
request_function(url)
},
get_url = function() {
get_url = function(id, export_format, version_format, language) {
url_mapping <- hash::hash(
# i14y
"codelist" =
glue::glue("CodeLists/{id}/exports/{export_format}/{version_format}"),
"dcat_data_structure" =
......
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