diff --git a/Anson-Projects/badfriends/src/analyzer.js b/Anson-Projects/badfriends/src/analyzer.js index fad377341..954c1a622 100644 --- a/Anson-Projects/badfriends/src/analyzer.js +++ b/Anson-Projects/badfriends/src/analyzer.js @@ -50,16 +50,19 @@ export async function analyzeFollows(callbacks = {}) { // Progress allocation: // - Preferences: 0-2% // - Follows: 2-8% - // - Posts (quick scan): 8-95% (main work, takes most time) - // - Analysis/Finalizing: 95-100% + // - Posts (quick scan): 8-88% (main work, takes most time) + // - Sentiment analysis: 88-94% + // - Applying filters: 94-100% try { - // Step 1: Fetch user preferences (also updates rate limit info) - onStatus('Loading your muted words and filters...'); + // Step 1: Fetch user preferences + onStatus('Grabbing your preferences...'); onProgress(0, 'preferences'); const preferences = await getUserPreferences(); const mutedWords = extractMutedWords(preferences); + + onStatus(`Found ${mutedWords.length} muted words`); onProgress(2, 'preferences'); // Check rate limit after first API call @@ -94,15 +97,17 @@ export async function analyzeFollows(callbacks = {}) { } // Step 2: Fetch following list - onStatus('Loading your following list...'); + onStatus('Grabbing your following list...'); onProgress(3, 'follows'); const follows = await getAllFollows((count, page) => { // Follows phase: 3-8% onProgress(3 + Math.min(5, page), 'follows'); + onStatus(`Grabbing your following list... (${count} accounts)`); console.log(`Fetched ${count} follows (page ${page})`); }); + onStatus(`Found ${follows.length} accounts you follow`); console.log(`Found ${follows.length} follows`); if (follows.length === 0) { @@ -139,27 +144,35 @@ export async function analyzeFollows(callbacks = {}) { console.log(` - Quick scan: ${quickScanOptions.minPosts}-${quickScanOptions.maxPosts} posts per account`); console.log(` - Deep scan: fetch until ${deepScanOptions.minDaysOfHistory} days of history (max ${deepScanOptions.maxPosts} posts)`); - // Step 4: Initial quick scan - onStatus(`Quick scan: Analyzing ${follows.length} accounts...`); + // Step 4: Initial quick scan - fetch posts + onStatus(`Fetching posts from ${follows.length} accounts...`); onProgress(8, 'posts'); // Fetch initial batch - // Posts phase uses 8-95% of progress bar (87% range for main work) + // Posts phase uses 8-88% of progress bar (80% range for main work) const initialFeeds = await getMultipleAuthorFeeds( follows, quickScanOptions, (completed, total) => { - const progress = 8 + Math.floor((completed / total) * 87); + const progress = 8 + Math.floor((completed / total) * 80); onProgress(progress, 'posts', completed, total); - onStatus(`Quick scan: ${completed}/${total} accounts`); + onStatus(`Fetching posts... ${completed} of ${total} accounts`); } ); - console.log(`Initial scan: fetched posts from ${initialFeeds.length} accounts`); + const totalPostsFetched = initialFeeds.reduce((sum, f) => sum + f.feed.length, 0); + console.log(`Initial scan: fetched ${totalPostsFetched} posts from ${initialFeeds.length} accounts`); + + // Step 5: Run sentiment analysis + onStatus(`Running sentiment analysis on ${totalPostsFetched} posts...`); + onProgress(89, 'sentiment'); - // Step 5: Analyze initial results - onStatus('Analyzing initial results...'); - onProgress(96, 'analysis'); + // Small delay to show the status message + await sleep(100); + + // Step 6: Apply filters + onStatus('Applying your filters...'); + onProgress(94, 'filtering'); // Create a map of DID to follow URI for unfollowing const followUriMap = createFollowUriMap(follows); @@ -191,8 +204,10 @@ export async function analyzeFollows(callbacks = {}) { }; }); - // Step 6: Show initial results - onProgress(98, 'finalizing'); + // Step 7: Sort and finalize results + onStatus('Sorting results...'); + onProgress(97, 'finalizing'); + const sortedResults = sortAccountsByFilteredPosts(accountResults); const problematicAccounts = filterProblematicAccounts(sortedResults); const summary = generateSummary(follows, mutedWords, problematicAccounts); @@ -212,7 +227,7 @@ export async function analyzeFollows(callbacks = {}) { }; onProgress(100, 'complete'); - onStatus('Quick scan complete!'); + onStatus(`Found ${problematicAccounts.length} accounts matching your filters`); onResults(initialResults); // Step 7: Continue deep scan in background (async, don't await)