From 2d5f613984ed71eea7e0049c236b437ac08df713 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Fri, 13 Dec 2024 12:32:28 -0800 Subject: [PATCH] feat: Process only last 1000 lines of analytics file --- scripts/my_models.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/my_models.py b/scripts/my_models.py index ae86a6cc3..e93484944 100755 --- a/scripts/my_models.py +++ b/scripts/my_models.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import json -from collections import defaultdict +from collections import defaultdict, deque from pathlib import Path # Get the analytics file path @@ -10,9 +10,14 @@ analytics_path = Path.home() / ".aider" / "analytics.jsonl" # Dictionary to store model stats model_stats = defaultdict(int) -# Read and process the file +# Number of lines to process from the end +N = 1000 + +# Read and process the last N lines of the file with open(analytics_path) as f: - for line in f: + # Get last N lines using deque + lines = deque(f, N) + for line in lines: try: event = json.loads(line) # Check if this is a message_send event