From ab4f14b3598a8840fa49890dbe3d37f686ee367e Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Sun, 4 Aug 2024 05:33:46 +0800 Subject: [PATCH] utils/analytics: improve accuracy of GitHub Packages download counts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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`. --- Library/Homebrew/utils/analytics.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index f43fc88375d46..1172462d084fe 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -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