Skip to content

Commit

Permalink
utils/analytics: improve accuracy of GitHub Packages download counts
Browse files Browse the repository at this point in the history
`millions_match.captures.first` will typically be a decimal (since it's
matched using `\d+\.\d+`), except we lose accuracy in the `#to_i`
conversion.

Before:
```
❯ brew info --analytics --github-packages-downloads sqlite
==> Analytics
==> install (30 days)
[snip]
==> GitHub Packages Downloads
1,009,898 (30 days)
```

After:

```
❯ brew info --analytics --github-packages-downloads sqlite
==> Analytics
==> install (30 days)
[snip]
==> GitHub Packages Downloads
1,199,898 (30 days)
```

In this case `1.19M` was being rounded down to `1M`.
  • Loading branch information
carlocab committed Aug 3, 2024
1 parent 822c847 commit ab4f14b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Library/Homebrew/utils/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def output_github_packages_downloads(formula, args:)

last_thirty_days_downloads = last_thirty_days_match.captures.first.tr(",", "")
thirty_day_download_count += if (millions_match = last_thirty_days_downloads.match(/(\d+\.\d+)M/).presence)
millions_match.captures.first.to_i * 1_000_000
millions_match.captures.first.to_f * 1_000_000
else
last_thirty_days_downloads.to_i
end
Expand Down

0 comments on commit ab4f14b

Please sign in to comment.