From cb3742018715817e24247f0a28bf32f63d92f9f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristram=20Gr=C3=A4bener?= Date: Tue, 7 Feb 2017 19:37:32 +0100 Subject: [PATCH] Add user meaning plugin --- .../custom-recipes/user-meaning/recipe.json | 35 +++++++++++++++++++ .../custom-recipes/user-meaning/recipe.py | 33 +++++++++++++++++ user_meaning/plugin.json | 26 ++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 user_meaning/custom-recipes/user-meaning/recipe.json create mode 100644 user_meaning/custom-recipes/user-meaning/recipe.py create mode 100644 user_meaning/plugin.json diff --git a/user_meaning/custom-recipes/user-meaning/recipe.json b/user_meaning/custom-recipes/user-meaning/recipe.json new file mode 100644 index 00000000..18ec8469 --- /dev/null +++ b/user_meaning/custom-recipes/user-meaning/recipe.json @@ -0,0 +1,35 @@ +{ + // Meta data for display purposes + "meta" : { + "label" : "User meaning", + "author" : "Ministère de l’Intérieur — EIG 2017", + "tags" : [] + }, + + "kind" : "PYTHON", + + "inputRoles" : [{ + "name": "input", + "label": "Input datasset", + "arity": "UNARY", + "required": true, + "acceptsDataset": true + }], + "outputRoles" : [{ + "name": "output", + "label": "Output dataset", + "arity": "UNARY", + "required": true, + "acceptsDataset": true + }], + + "params": [ + { + "name": "meanings", + "label" : "Meaning to map", + "type": "TEXTAREA", + "description": "A json document: each entry is the name of a column. For entry is a dictionnary mapping from a constant to an user meaning", + "mandatory" : true + } + ] +} diff --git a/user_meaning/custom-recipes/user-meaning/recipe.py b/user_meaning/custom-recipes/user-meaning/recipe.py new file mode 100644 index 00000000..280d7f58 --- /dev/null +++ b/user_meaning/custom-recipes/user-meaning/recipe.py @@ -0,0 +1,33 @@ +# coding=utf-8 + +u"""Map constants to user meaning + +This plugin was developped by the Ministère de l’Intérieur (French ministry of interior) +in the context of the program Entrepreneurs d’Intérêt Général 2017 +""" + +from concurrent import futures +import dataiku +from dataiku.customrecipe import get_input_names_for_role +from dataiku.customrecipe import get_output_names_for_role +from dataiku.customrecipe import get_recipe_config +import json +import pandas as pd + +# We read the addresses from the input dataset +# And write the coordinates in the output dataset +input_name = get_input_names_for_role('input')[0] +input_dataset = dataiku.Dataset(input_name) + +output_name = get_output_names_for_role('output')[0] +output_dataset = dataiku.Dataset(output_name) + +meanings = get_recipe_config()['meanings'].encode('utf8') +meanings = json.loads(meanings) + +df = input_dataset.get_dataframe(infer_with_pandas=False) + +for column, mappings in meanings.iteritems(): + df[column] = df[column].map(mappings) + +output_dataset.write_with_schema(df) diff --git a/user_meaning/plugin.json b/user_meaning/plugin.json new file mode 100644 index 00000000..fa9c3a25 --- /dev/null +++ b/user_meaning/plugin.json @@ -0,0 +1,26 @@ +// This file is the descriptor for the DSS Plugin geocoding_BAN +{ + // The identifier of the plugin. + // This must be globally unique, and only contain A-Za-z0-9_- + "id" : "user_meaning", + + // Version. It is highly recommended to use Semantic Versioning + "version" : "0.0.1", + + // Meta data for display purposes + "meta" : { + // Name of this plugin that appears in the interface. + "label": "Map constants to user meaning", + + "description": "Transform multiple column values constants to more meaningful values", + "author": "Ministère de l’Intérieur — EIG 2017", + + // The icon of a plugin must be one of the FontAwesome 3.1 icons + "icon": "icon-list-ul", + + "licenseInfo" : "Apache Software License", + + // List of tags for filtering the list of plugins + "tags": [] + } +}