Data source/VIES/data model/record/mapping/CDQ/ES/transformation

From CDQ
Revision as of 09:51, 18 August 2021 by Jenkins (talk | contribs) (Template parameters updated.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Part of Hierarchical relation between two concepts of the CDQ Data Model. Data source VIES
Mapping source The source of a data model mapping. VIES recordTHOROUGHFARE_VALUE, THOROUGHFARE_TYPE, POST_CODE_VALUE, POST_CODE_TYPE, LOCALITY_VALUE, LOCALITY_TYPE
Transformation type A type of a transformation applied to a data model mapping. CUSTOM
Transformation parameter A transformation parameter is an action proccessed by a data model transformation. n/a
Description Informal and comprehensive human-readable definition of a concept. n/a

Transformation code Any code (in Python, JAVA or other) that will transform values for a given data source attributes.

import json


def transform(raw_data):
    json_object = json.loads(raw_data)
    result = {}

    add_if_valid(json_object, 'traderStreet', 'address.thoroughfares[0]', 'STREET', result)
    add_if_valid(json_object, 'traderPostcode', 'address.postCodes[0]', 'REGULAR', result)
    add_if_valid(json_object, 'traderCity', 'address.localities[0]', 'CITY', result)

    return result


def add_if_valid(json_object, param, prefix, type, result):
    if json_object['countryCode']['value'] != 'ES' or json_object[param + 'Match']['value'] == '1':
        value = json_object[param]['value']
        if value:
            result.update({
                prefix + '.type': type,
                prefix + '.value': value
            })