From ffc2c5a26e1d515dc836d1f34f1cc314997dc820 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 17 Dec 2024 12:55:24 -0800 Subject: [PATCH] refactor: Move uuid percentage check to function --- aider/analytics.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/aider/analytics.py b/aider/analytics.py index f906fca22..113b5c637 100644 --- a/aider/analytics.py +++ b/aider/analytics.py @@ -87,6 +87,7 @@ class Analytics: PERCENT = 5 return self.is_uuid_in_percentage(self.user_id, PERCENT) + # AI refactor this out of the class... def is_uuid_in_percentage(self, uuid_str, percent): """Check if a UUID string falls within the first X percent of the UUID space. @@ -107,7 +108,10 @@ class Analytics: # Using first 6 hex digits if percent == 0: return False + + # and make a separate function for computing the threshold AI! threshold = format(int(0xFFFFFF * percent / 100), "06x") + return uuid_str[:6] <= threshold def get_data_file_path(self): @@ -228,3 +232,9 @@ class Analytics: f.write("\n") except OSError: pass # Ignore OS errors when writing to logfile + + +if __name__ == '__main__': + a = Analytics() + dump(a.user_id) + a.is_uuid_in_percentage(a.user_id, 5)