nix-flake-outputs-size/compare.jq

21 lines
889 B
Text
Raw Normal View History

# Calculate the change in percentage of a nummeric key
#
# Where .[0] is the new value, and .[1] is the old value
def calc_change($key):
. as $input | $input[1][$key] - $input[0][$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"])))