evalstate HF Staff commited on
Commit
e7e3105
·
verified ·
1 Parent(s): 7408778

Upload mcp_remote_daily.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. mcp_remote_daily.py +116 -0
mcp_remote_daily.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env -S uv run
2
+ # /// script
3
+ # requires-python = ">=3.10"
4
+ # dependencies = [
5
+ # "datasets",
6
+ # "pandas",
7
+ # ]
8
+ # ///
9
+
10
+ """
11
+ Analyze daily proportion of sessions that include mcp-remote.
12
+
13
+ This script analyzes the evalstate/hf-mcp-logs dataset to calculate what proportion
14
+ of sessions included "mcp-remote" in the client name on a daily basis.
15
+
16
+ Usage:
17
+ uv run mcp_remote_daily.py [--limit N]
18
+ """
19
+
20
+ import sys
21
+ import re
22
+ import argparse
23
+ from datetime import datetime
24
+ from collections import defaultdict
25
+ from datasets import load_dataset
26
+
27
+
28
+ def main():
29
+ parser = argparse.ArgumentParser(description="Analyze daily mcp-remote usage")
30
+ parser.add_argument("--limit", type=int, default=None, help="Limit processing to N rows (for testing)")
31
+ args = parser.parse_args()
32
+
33
+ print(f"[{datetime.now().isoformat()}] Loading dataset from evalstate/hf-mcp-logs...", file=sys.stderr)
34
+
35
+ # Load the source dataset (streaming for large datasets)
36
+ ds = load_dataset('evalstate/hf-mcp-logs', 'sessions', streaming=True)
37
+ sessions_ds = ds['sessions']
38
+
39
+ # Pattern to detect mcp-remote suffix (any version)
40
+ MCP_REMOTE_PATTERN = re.compile(r'\(via mcp-remote')
41
+
42
+ # Track by day
43
+ daily_stats = defaultdict(lambda: {'total': 0, 'with_mcp_remote': 0})
44
+
45
+ total_rows = 0
46
+ start_time = datetime.now()
47
+
48
+ print(f"[{datetime.now().isoformat()}] Processing sessions...", file=sys.stderr)
49
+
50
+ for batch in sessions_ds.iter(batch_size=10000):
51
+ batch_len = len(batch['time'])
52
+ total_rows += batch_len
53
+
54
+ # Progress indicator
55
+ if total_rows % 100000 == 0:
56
+ elapsed = (datetime.now() - start_time).total_seconds()
57
+ rate = total_rows / elapsed if elapsed > 0 else 0
58
+ print(f"[{datetime.now().isoformat()}] Progress: {total_rows:,} rows processed "
59
+ f"({rate:.0f} rows/sec)", file=sys.stderr)
60
+
61
+ if args.limit and total_rows >= args.limit:
62
+ print(f"[{datetime.now().isoformat()}] Reached limit of {args.limit:,} rows", file=sys.stderr)
63
+ break
64
+
65
+ for i in range(batch_len):
66
+ time_str = batch['time'][i]
67
+ name = batch['name'][i]
68
+
69
+ # Skip if name is None
70
+ if name is None:
71
+ continue
72
+
73
+ # Extract date from time string (ISO format: 2025-11-19T...)
74
+ date_str = time_str.split('T')[0] if 'T' in time_str else time_str
75
+
76
+ daily_stats[date_str]['total'] += 1
77
+
78
+ # Check if name contains mcp-remote suffix
79
+ if MCP_REMOTE_PATTERN.search(name):
80
+ daily_stats[date_str]['with_mcp_remote'] += 1
81
+
82
+ elapsed = (datetime.now() - start_time).total_seconds()
83
+ rate = total_rows / elapsed if elapsed > 0 else 0
84
+
85
+ print(f"[{datetime.now().isoformat()}] Processing complete: {total_rows:,} rows", file=sys.stderr)
86
+ print(f"Rate: {rate:.0f} rows/sec, elapsed: {elapsed:.1f} seconds", file=sys.stderr)
87
+ print(f"Found {len(daily_stats)} days of data", file=sys.stderr)
88
+ print()
89
+
90
+ # Print daily statistics
91
+ print("Daily mcp-remote Usage")
92
+ print("=" * 70)
93
+ print(f"{'Date':<12} {'Total Sessions':>15} {'mcp-remote':>12} {'%':>10}")
94
+ print("-" * 70)
95
+
96
+ # Sort by date
97
+ for date in sorted(daily_stats.keys()):
98
+ stats = daily_stats[date]
99
+ total = stats['total']
100
+ with_mcp = stats['with_mcp_remote']
101
+ pct = (with_mcp / total * 100) if total > 0 else 0
102
+ print(f"{date:<12} {total:>15,} {with_mcp:>12,} {pct:>9.1f}%")
103
+
104
+ print("=" * 70)
105
+
106
+ # Overall summary
107
+ overall_total = sum(s['total'] for s in daily_stats.values())
108
+ overall_with_mcp = sum(s['with_mcp_remote'] for s in daily_stats.values())
109
+ overall_pct = (overall_with_mcp / overall_total * 100) if overall_total > 0 else 0
110
+
111
+ print(f"{'TOTAL':<12} {overall_total:>15,} {overall_with_mcp:>12,} {overall_pct:>9.1f}%")
112
+ print()
113
+
114
+
115
+ if __name__ == '__main__':
116
+ main()