Jalil David Salamé Messina
ea9ec51d18
We did $old - $new instead of $new - $old so positive changes where good and negative where bad T-T
20 lines
888 B
Text
20 lines
888 B
Text
# Calculate the change in percentage of a numeric key
|
|
#
|
|
# Where .[0] is the new value, and .[1] is the old value
|
|
def calc_change($key):
|
|
. as $input | $input[0][$key] - $input[1][$key];
|
|
|
|
# Calculate the change in percentage for multiple keys
|
|
#
|
|
# Returns an array of {"key": $key, "value": change%}
|
|
def keys_change_perc($keys):
|
|
. as $input | $keys | map(. as $key | $input | {"key": $key, "value": . | calc_change($key)});
|
|
|
|
# For a set of keys, calculate the change percentage and return it as
|
|
# "\($key)Change" = $value in the original object.
|
|
def set_change_perc($keys):
|
|
. as $input | reduce keys_change_perc($keys)[] as $change ($input[0]; .["\($change.key)Change"] = $change.value);
|
|
|
|
# Bring everything together
|
|
reduce .[] as $x ({}; . as $acc | reduce ($x | keys[]) as $key ($acc; .[$key] |= . + $x[$key])) |
|
|
map_values(group_by(.name) | map(set_change_perc(["size", "narSize"])))
|