Skip to content

Commit

Permalink
Merge pull request #864 from googlefonts/ttx-diff-total-diff
Browse files Browse the repository at this point in the history
[ttx_diff] Add a 'total diff' number to json output
  • Loading branch information
cmyr authored Jul 15, 2024
2 parents a8e16dd + 2c0db6b commit f2c758d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions resources/scripts/ttx_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,17 +415,29 @@ def jsonify_output(output: dict[str, dict[str, str]]):
fontmake = output["fontmake"]
all_tags = set(fontc.keys()) | set(fontmake.keys())
out = dict()
same_lines = 0
different_lines = 0
for tag in all_tags:
if tag not in fontc:
different_lines += len(fontmake[tag])
out[tag] = "fontmake"
elif tag not in fontmake:
different_lines += len(fontc[tag])
out[tag] = "fontc"
else:
s1 = fontc[tag]
s2 = fontmake[tag]
if s1 != s2:
ratio = diff_ratio(s1, s2)
n_lines = max(len(s1), len(s2))
same_lines += int(n_lines * ratio)
different_lines += int( n_lines * (1 - ratio))
out[tag] = ratio
else:
same_lines += len(s1)

overall_diff_ratio = same_lines / (same_lines + different_lines)
out["total"] = overall_diff_ratio
return {"success": out}


Expand Down

0 comments on commit f2c758d

Please sign in to comment.