refactor: Move uuid percentage check to standalone functions

This commit is contained in:
Paul Gauthier (aider) 2024-12-17 12:55:26 -08:00
parent ffc2c5a26e
commit 9a770eeae9

View file

@ -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: