⚡ Zero-dependency plcbundle library exclusively for Bun
at main 1.4 kB view raw
1/** 2 * Example: Analyze operations and gather statistics 3 * 4 * Usage: 5 * bun examples/analyze.ts 6 */ 7 8import { PLCBundle } from '../src'; 9 10const bundle = new PLCBundle('./data/bundles'); 11 12console.log('Analyzing bundles 1-10...\n'); 13 14const stats = { 15 totalOps: 0, 16 uniqueDids: new Set<string>(), 17 byYear: {} as Record<string, number>, 18 withHandle: 0, 19 withPds: 0, 20}; 21 22await bundle.processBundles(1, 10, (op, position, bundleNum, line) => { 23 stats.totalOps++; 24 stats.uniqueDids.add(op.did); 25 26 // Count by year 27 const year = op.createdAt.substring(0, 4); 28 stats.byYear[year] = (stats.byYear[year] || 0) + 1; 29 30 // Count operations with handles 31 if (op.operation?.alsoKnownAs?.length > 0) { 32 stats.withHandle++; 33 } 34 35 // Count operations with PDS 36 if (op.operation?.services?.atproto_pds) { 37 stats.withPds++; 38 } 39}); 40 41 42console.log('📊 Analysis Results\n'); 43console.log(`Total operations: ${stats.totalOps.toLocaleString()}`); 44console.log(`Unique DIDs: ${stats.uniqueDids.size.toLocaleString()}`); 45console.log(`With handle: ${stats.withHandle.toLocaleString()} (${(stats.withHandle/stats.totalOps*100).toFixed(1)}%)`); 46console.log(`With PDS: ${stats.withPds.toLocaleString()} (${(stats.withPds/stats.totalOps*100).toFixed(1)}%)`); 47 48console.log('\nOperations by year:'); 49for (const [year, count] of Object.entries(stats.byYear).sort()) { 50 console.log(` ${year}: ${count.toLocaleString()}`); 51}