Giter Site home page Giter Site logo

gotransform's Introduction

gotransform

This project to transform data from input to output using json configuration

Example Data :

{
    "name": "Supote",
    "surname": "Sirimahayarn",
    "clientId": "112233445566",
    "age": 42,
    "sex": "M",
    "group_code": "Radio28,19800218",
    "block": "aaaa-bbbb-cccc-dddd-eeee-xxxx",
    "trimMe": "\n   Aloha \n\r\t ",
    "birthDate": "1980-02-18",
    "number": 123456.789012,
    "step": 100,
    "strNum": "100.10",
    "strBool": "TruE",
    "animals": [
        {
            "aname": "Diggy",
            "akind": "dog"
        },
        {
            "aname": "Tom",
            "akind": "cat"
        },
        {
            "aname": "Bella",
            "akind": "bird"
        },
        {
            "aname": "Meep Meep",
            "akind": "bird"
        }
    ],
    "birds": [
        {
            "aname": "Bella",
            "akind": "bird",
            "age": 4
        },
        {
            "aname": "Meep Meep",
            "akind": "bird",
            "age": 25
        },
        {
            "aname": "Suga",
            "akind": "bird",
            "age": 3
        },
        {
            "aname": "Sunlight",
            "akind": "bird",
            "age": 2
        }
    ],
    "workers": [
        {
            "name": "Tong",
            "pos": "Senior"
        },
        {
            "name": "Tor",
            "pos": "Senior"
        },
        {
            "name": "Oat",
            "pos": "Senior"
        },
        {
            "name": "Ton",
            "pos": "Developer"
        },
        {
            "name": "Siam Type",
            "pos": "Developer"
        },
        {
            "name": "Num",
            "pos": "Junior"
        },
        {
            "name": "Toon",
            "pos": "Junior"
        }
    ]
}

Example Transform Config :

[
    {
        "input": [
            "name",
            "surname"
        ],
        "output": [
            "fullname"
        ],
        "type": "merge_string",
        "combine": "-"
    },
    {
        "input": [
            "group_code"
        ],
        "output": [
            "group",
            "$tmp.var0001"
        ],
        "type": "split_string",
        "split": ","
    },
    {
        "input": [
            "$tmp.var0001"
        ],
        "output": [
            "code"
        ],
        "type": "number_format",
        "format": "%010d"
    },
    {
        "input": [
            "age",
            "sex",
            "clientId"
        ],
        "output": [
            "age",
            "gender",
            "clientId"
        ],
        "type": "rename_fields"
    },
    {
        "input": [
            "block"
        ],
        "output": [
            "blockArr"
        ],
        "type": "split_string_array",
        "split": "-"
    },
    {
        "input": [
            "block"
        ],
        "output": [
            "aaa",
            "bbb",
            "ccc",
            "ddd"
        ],
        "type": "split_string",
        "split": "-"
    },
    {
        "input": [
            "block"
        ],
        "output": [
            "block2"
        ],
        "type": "replace_string",
        "position": "All",
        "from": "-",
        "to": "|"
    },
    {
        "input": [
            "trimMe"
        ],
        "output": [
            "trimMe"
        ],
        "type": "trim_string"
    },
    {
        "input": [],
        "output": [
            "uuid"
        ],
        "type": "gen_uuid",
        "num": 32
    },
    {
        "input": [],
        "output": [
            "cTime"
        ],
        "type": "get_current_time",
        "format": "2006-02-01 15:04:05"
    },
    {
        "input": [
            "step"
        ],
        "output": [
            "stepUp"
        ],
        "type": "increase_num",
        "step": 10
    },
    {
        "input": [
            "step"
        ],
        "output": [
            "stepDown"
        ],
        "type": "decrease_num",
        "step": 30
    },
    {
        "input": [
            "strNum"
        ],
        "output": [
            "toNum"
        ],
        "type": "to_number",
        "valueType": "decimal"
    },
    {
        "input": [
            "strBool"
        ],
        "output": [
            "toBool"
        ],
        "type": "to_boolean"
    },
    {
        "input": [],
        "output": [
            "fixValue"
        ],
        "type": "fix_value",
        "valueType": "string",
        "value": "What's the fuck?"
    },
    {
        "input": [
            "name",
            "surname"
        ],
        "output": [
            "animals"
        ],
        "type": "add_to_list",
        "position": "First"
    },
    {
        "input": [
            "clientId",
            "group_code"
        ],
        "output": [
            "animals"
        ],
        "type": "add_to_list",
        "position": "First"
    },
    {
        "input": [
            "sex",
            "age"
        ],
        "output": [
            "animals"
        ],
        "type": "copy_to_list"
    },
    {
        "input": [
            "birds"
        ],
        "output": [
            "aname",
            "akind",
            "age"
        ],
        "type": "copy_from_list",
        "index": "0"
    },
    {
        "input": [
            "animals",
            "birds"
        ],
        "output": [
            "joinedAnimal"
        ],
        "type": "join_list",
        "fields": "aname, akind",
        "fields2": "aname, akind",
        "operator": "AND"
    },
    {
        "input": [
            "workers"
        ],
        "output": [
            "delWorkers"
        ],
        "type": "delete_record",
        "index": "@first"
    },
    {
        "input": [
            "workers"
        ],
        "output": [
            "filterWorkers"
        ],
        "type": "filter_record",
        "fields": "pos",
        "value": "Junior",
        "operator": "AND"
    },
    {
        "input": [
            "birds"
        ],
        "output": [
            "totalAge"
        ],
        "type": "sum_fields_in_list",
        "fields": "age"
    }
]

Example Code :


dataBus := ...map data that you want to transform
transform := ...array data of transform configuration such as above example

res, err := hpi.ProcessTransform(dataBus, transform)

// res is result after transform data success

gotransform's People

Contributors

adirak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.