Skip to content

Commit

Permalink
fix(scripts/technical-debt-metric): avoid division by 0 (#20537)
Browse files Browse the repository at this point in the history
The division by 0 affected #20521: all `ofNat` debts were removed in that PR, so one denominator became 0 giving a [CI error](https://github.com/leanprover-community/mathlib4/actions/runs/12636151506/job/35207580913).

This PR fixes the issue.
  • Loading branch information
adomani committed Jan 7, 2025
1 parent f79db55 commit 6bfeca1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions scripts/technical-debt-metrics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,14 @@ then
then
printf '<details><summary>No changes to technical debt.</summary>\n'
else
printf '%s\n' "${rep}" |
printf '%s\n' "${rep}" | # outputs lines containing `|Current number|Change|Type|`, so
# `$2` refers to `Current number` and `$3` to `Change`.
awk -F '|' -v rep="${rep}" '
BEGIN{total=0; weight=0}
BEGIN{total=0; weight=0; absWeight=0}
{absWeight+=$3+0}
(($3+0 == $3) && (!($2+0 == 0))) {total+=1 / $2; weight+=$3 / $2}
END{
average=weight/total
if (total == 0) {average=absWeight} else {average=weight/total}
if(average < 0) {change= "Decrease"; average=-average; weight=-weight} else {change= "Increase"}
printf("<details><summary>%s in tech debt: (relative, absolute) = (%4.2f, %4.2f)</summary>\n\n%s\n", change, average, weight, rep) }'
fi
Expand Down

0 comments on commit 6bfeca1

Please sign in to comment.