|
| 1 | +import dotenv from "dotenv"; |
| 2 | +import { MongoClient } from "mongodb"; |
| 3 | +dotenv.config(); |
| 4 | + |
| 5 | +async function main() { |
| 6 | + const client = new MongoClient(process.env.MONGODB_URI!); |
| 7 | + await client.connect(); |
| 8 | + const db = client.db(process.env.MONGODB_DB); |
| 9 | + const users = db.collection("users"); |
| 10 | + |
| 11 | + // 1. Does "following" vs "followers" discovery direction predict score? |
| 12 | + console.log("=== SCORE BY DISCOVERY DIRECTION ==="); |
| 13 | + for (const via of ["following", "followers"]) { |
| 14 | + const results = await users.aggregate([ |
| 15 | + { $match: { status: "processed", rating: { $exists: true }, discoveredVia: via } }, |
| 16 | + { $group: { _id: null, avgScore: { $avg: "$rating" }, count: { $sum: 1 }, scored40plus: { $sum: { $cond: [{ $gte: ["$rating", 40] }, 1, 0] } } } } |
| 17 | + ]).toArray(); |
| 18 | + if (results.length) { |
| 19 | + const r = results[0]; |
| 20 | + console.log(` ${via}: avg=${r.avgScore.toFixed(1)}, count=${r.count}, 40+=${r.scored40plus} (${((r.scored40plus/r.count)*100).toFixed(1)}%)`); |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + // 2. Does depth predict score? |
| 25 | + console.log("\n=== SCORE BY DEPTH ==="); |
| 26 | + const depthResults = await users.aggregate([ |
| 27 | + { $match: { status: "processed", rating: { $exists: true }, depth: { $exists: true } } }, |
| 28 | + { $group: { _id: "$depth", avgScore: { $avg: "$rating" }, count: { $sum: 1 }, scored40plus: { $sum: { $cond: [{ $gte: ["$rating", 40] }, 1, 0] } } } }, |
| 29 | + { $sort: { _id: 1 } } |
| 30 | + ]).toArray(); |
| 31 | + for (const r of depthResults) { |
| 32 | + console.log(` depth=${r._id}: avg=${r.avgScore.toFixed(1)}, count=${r.count}, 40+=${r.scored40plus} (${((r.scored40plus/r.count)*100).toFixed(1)}%)`); |
| 33 | + } |
| 34 | + |
| 35 | + // 3. Does max parent rating predict score? |
| 36 | + console.log("\n=== SCORE BY MAX PARENT RATING ==="); |
| 37 | + const processed = await users.find({ |
| 38 | + status: "processed", |
| 39 | + rating: { $exists: true }, |
| 40 | + parentRatings: { $exists: true, $ne: [] } |
| 41 | + }).project({ rating: 1, parentRatings: 1, depth: 1, discoveredVia: 1 }).toArray(); |
| 42 | + |
| 43 | + const buckets: Record<string, { total: number; good: number; sumScore: number }> = { |
| 44 | + "parent 55+": { total: 0, good: 0, sumScore: 0 }, |
| 45 | + "parent 45-55": { total: 0, good: 0, sumScore: 0 }, |
| 46 | + "parent 35-45": { total: 0, good: 0, sumScore: 0 }, |
| 47 | + "parent 25-35": { total: 0, good: 0, sumScore: 0 }, |
| 48 | + "parent <25": { total: 0, good: 0, sumScore: 0 }, |
| 49 | + }; |
| 50 | + |
| 51 | + for (const u of processed) { |
| 52 | + const parentScores = (u.parentRatings || []).map((p: any) => typeof p === "number" ? p : p.rating).filter((r: any) => typeof r === "number"); |
| 53 | + if (!parentScores.length) continue; |
| 54 | + const maxParent = Math.max(...parentScores); |
| 55 | + |
| 56 | + let bucket: string; |
| 57 | + if (maxParent >= 55) bucket = "parent 55+"; |
| 58 | + else if (maxParent >= 45) bucket = "parent 45-55"; |
| 59 | + else if (maxParent >= 35) bucket = "parent 35-45"; |
| 60 | + else if (maxParent >= 25) bucket = "parent 25-35"; |
| 61 | + else bucket = "parent <25"; |
| 62 | + |
| 63 | + buckets[bucket].total++; |
| 64 | + buckets[bucket].sumScore += u.rating; |
| 65 | + if (u.rating >= 40) buckets[bucket].good++; |
| 66 | + } |
| 67 | + |
| 68 | + for (const [label, b] of Object.entries(buckets)) { |
| 69 | + if (b.total > 0) { |
| 70 | + console.log(` ${label}: avg=${(b.sumScore/b.total).toFixed(1)}, count=${b.total}, 40+=${b.good} (${((b.good/b.total)*100).toFixed(1)}%)`); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + // 4. Does number of parents (discovered by multiple high-scoring people) predict score? |
| 75 | + console.log("\n=== SCORE BY NUMBER OF PARENTS ==="); |
| 76 | + const parentCountBuckets: Record<string, { total: number; good: number; sumScore: number }> = { |
| 77 | + "1 parent": { total: 0, good: 0, sumScore: 0 }, |
| 78 | + "2-3 parents": { total: 0, good: 0, sumScore: 0 }, |
| 79 | + "4-6 parents": { total: 0, good: 0, sumScore: 0 }, |
| 80 | + "7+ parents": { total: 0, good: 0, sumScore: 0 }, |
| 81 | + }; |
| 82 | + |
| 83 | + for (const u of processed) { |
| 84 | + const nParents = (u.parentRatings || []).length; |
| 85 | + if (!nParents) continue; |
| 86 | + |
| 87 | + let bucket: string; |
| 88 | + if (nParents >= 7) bucket = "7+ parents"; |
| 89 | + else if (nParents >= 4) bucket = "4-6 parents"; |
| 90 | + else if (nParents >= 2) bucket = "2-3 parents"; |
| 91 | + else bucket = "1 parent"; |
| 92 | + |
| 93 | + parentCountBuckets[bucket].total++; |
| 94 | + parentCountBuckets[bucket].sumScore += u.rating; |
| 95 | + if (u.rating >= 40) parentCountBuckets[bucket].good++; |
| 96 | + } |
| 97 | + |
| 98 | + for (const [label, b] of Object.entries(parentCountBuckets)) { |
| 99 | + if (b.total > 0) { |
| 100 | + console.log(` ${label}: avg=${(b.sumScore/b.total).toFixed(1)}, count=${b.total}, 40+=${b.good} (${((b.good/b.total)*100).toFixed(1)}%)`); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + // 5. Does "following" from a high-scorer beat "followers" from a high-scorer? |
| 105 | + console.log("\n=== COMBINED: DIRECTION + MAX PARENT SCORE ==="); |
| 106 | + const comboBuckets: Record<string, { total: number; good: number; sumScore: number }> = {}; |
| 107 | + |
| 108 | + for (const u of processed) { |
| 109 | + const parentScores = (u.parentRatings || []).map((p: any) => typeof p === "number" ? p : p.rating).filter((r: any) => typeof r === "number"); |
| 110 | + if (!parentScores.length) continue; |
| 111 | + const maxParent = Math.max(...parentScores); |
| 112 | + const via = u.discoveredVia || "unknown"; |
| 113 | + |
| 114 | + let parentBucket: string; |
| 115 | + if (maxParent >= 45) parentBucket = "45+"; |
| 116 | + else if (maxParent >= 35) parentBucket = "35-45"; |
| 117 | + else parentBucket = "<35"; |
| 118 | + |
| 119 | + const key = `${via} + parent ${parentBucket}`; |
| 120 | + if (!comboBuckets[key]) comboBuckets[key] = { total: 0, good: 0, sumScore: 0 }; |
| 121 | + comboBuckets[key].total++; |
| 122 | + comboBuckets[key].sumScore += u.rating; |
| 123 | + if (u.rating >= 40) comboBuckets[key].good++; |
| 124 | + } |
| 125 | + |
| 126 | + for (const [label, b] of Object.entries(comboBuckets).sort((a, b) => (b[1].good/b[1].total) - (a[1].good/a[1].total))) { |
| 127 | + if (b.total > 10) { |
| 128 | + console.log(` ${label}: avg=${(b.sumScore/b.total).toFixed(1)}, count=${b.total}, 40+=${b.good} (${((b.good/b.total)*100).toFixed(1)}%)`); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + // 6. GitHub metadata available before scraping: do we have followers count, public repos, etc? |
| 133 | + console.log("\n=== GITHUB METADATA CORRELATION ==="); |
| 134 | + // Check if we have any pre-scrape metadata |
| 135 | + const sampleWithMeta = await users.findOne( |
| 136 | + { status: "processed", rating: { $exists: true } }, |
| 137 | + { projection: { _id: 1, followers: 1, following: 1, public_repos: 1, githubFollowers: 1, githubData: 1 } } |
| 138 | + ); |
| 139 | + console.log(" Sample fields:", JSON.stringify(Object.keys(sampleWithMeta || {}))); |
| 140 | + |
| 141 | + await client.close(); |
| 142 | +} |
| 143 | +main().catch(console.error); |
0 commit comments