utils/analytics: improve accuracy of GitHub Packages download counts

`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`.
This commit is contained in:
Carlo Cabrera 2024-08-04 05:33:46 +08:00
parent 822c84784c
commit ab4f14b359
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -307,7 +307,7 @@ module Utils
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