Created
April 29, 2020 14:29
-
-
Save iogbole/4c778dcadcb72b488d76b33e0d3bc820 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function JSONProccessor { | |
jq ' | |
def myMathFunc: | |
if (.name | test("^sum")) then | |
{"\(.name)": (.values | add)} | |
elif (.name | test("^avg|^global-avg")) then | |
{"\(.name)": ((.values | add) / (.values | length)) } | |
elif (.name | test("^max")) then | |
{"\(.name)": (.values | max) } | |
elif (.name | test("^min")) then | |
{"\(.name)": (.values | min) } | |
else | |
{"\(.name)": .values[]} | |
end; | |
[ | |
.Response.stats.data[] | | |
.identifier.names[] as $name | | |
.identifier.values[] as $val | | |
{"\($name)": "\($val)"} + ([ | |
.metric[] | myMathFunc | |
] | add) | |
] | |
' < ${1} > ${2} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment