From 9a770eeae9229d0a3a93f5cc11fce77a31a228e4 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 17 Dec 2024 12:55:26 -0800 Subject: [PATCH] refactor: Move uuid percentage check to standalone functions --- aider/analytics.py | 65 +++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/aider/analytics.py b/aider/analytics.py index 113b5c637..7c1c06bfb 100644 --- a/aider/analytics.py +++ b/aider/analytics.py @@ -10,6 +10,43 @@ from posthog import Posthog from aider import __version__ from aider.dump import dump # noqa: F401 + + +def compute_hex_threshold(percent): + """Convert percentage to 6-digit hex threshold. + + Args: + percent: Percentage threshold (0-100) + + Returns: + str: 6-digit hex threshold + """ + return format(int(0xFFFFFF * percent / 100), "06x") + + +def is_uuid_in_percentage(uuid_str, percent): + """Check if a UUID string falls within the first X percent of the UUID space. + + Args: + uuid_str: UUID string to test + percent: Percentage threshold (0-100) + + Returns: + bool: True if UUID falls within the first X percent + """ + if not (0 <= percent <= 100): + raise ValueError("Percentage must be between 0 and 100") + + if not uuid_str: + return False + + # Convert percentage to hex threshold (1% = "04...", 10% = "1a...", etc) + # Using first 6 hex digits + if percent == 0: + return False + + threshold = compute_hex_threshold(percent) + return uuid_str[:6] <= threshold from aider.models import model_info_manager mixpanel_project_token = "6da9a43058a5d1b9f3353153921fb04d" @@ -85,34 +122,8 @@ class Analytics: return False PERCENT = 5 - return self.is_uuid_in_percentage(self.user_id, PERCENT) + return 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. - - Args: - uuid_str: UUID string to test - percent: Percentage threshold (0-100) - - Returns: - bool: True if UUID falls within the first X percent - """ - if not (0 <= percent <= 100): - raise ValueError("Percentage must be between 0 and 100") - - if not uuid_str: - return False - - # Convert percentage to hex threshold (1% = "04...", 10% = "1a...", etc) - # 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): try: