Monorepo for Aesthetic.Computer
aesthetic.computer
1// MongoDB stats for kidlisp ecosystem report
2import { createRequire } from 'module';
3const require = createRequire(import.meta.url);
4const { MongoClient } = require('/workspaces/aesthetic-computer/system/node_modules/mongodb');
5
6const uri = process.env.MONGODB_CONNECTION_STRING;
7const dbName = 'aesthetic';
8
9async function main() {
10 const client = new MongoClient(uri);
11 try {
12 await client.connect();
13 console.log('Connected to MongoDB Atlas');
14
15 const db = client.db(dbName);
16
17 // List all collections
18 const collections = await db.listCollections().toArray();
19 console.log('\n📊 Collections:');
20 collections.forEach(c => console.log(' -', c.name));
21
22 // Count documents in kidlisp collection
23 const kidlispCount = await db.collection('kidlisp').countDocuments();
24 console.log('\n📝 KidLisp documents:', kidlispCount);
25
26 // Get some stats on kidlisp
27 const kidlispStats = await db.collection('kidlisp').aggregate([
28 { $group: {
29 _id: null,
30 totalDocs: { $sum: 1 },
31 withUser: { $sum: { $cond: [{ $ifNull: ['$user', false] }, 1, 0] } },
32 avgHits: { $avg: { $ifNull: ['$hits', 0] } },
33 maxHits: { $max: { $ifNull: ['$hits', 0] } }
34 }}
35 ]).toArray();
36
37 if (kidlispStats[0]) {
38 console.log('📈 Stats:');
39 console.log(' - Total:', kidlispStats[0].totalDocs);
40 console.log(' - With user:', kidlispStats[0].withUser);
41 console.log(' - Anonymous:', kidlispStats[0].totalDocs - kidlispStats[0].withUser);
42 console.log(' - Avg hits:', Math.round(kidlispStats[0].avgHits * 100) / 100);
43 console.log(' - Max hits:', kidlispStats[0].maxHits);
44 }
45
46 // Get sample of recent kidlisp
47 const samples = await db.collection('kidlisp')
48 .find({})
49 .sort({ when: -1 })
50 .limit(5)
51 .project({ code: 1, when: 1, hits: 1, user: 1, source: 1 })
52 .toArray();
53
54 console.log('\n🔖 Recent kidlisp samples:');
55 samples.forEach(s => {
56 const sourcePreview = s.source?.slice(0, 60).replace(/\n/g, ' ') + (s.source?.length > 60 ? '...' : '');
57 console.log(' - [' + s.code + '] hits:', s.hits || 0, 'user:', s.user ? 'yes' : 'anon');
58 console.log(' ', sourcePreview);
59 });
60
61 // Top hits
62 const topHits = await db.collection('kidlisp')
63 .find({})
64 .sort({ hits: -1 })
65 .limit(5)
66 .project({ code: 1, hits: 1, source: 1 })
67 .toArray();
68
69 console.log('\n🔥 Top hit kidlisp:');
70 topHits.forEach(s => {
71 const sourcePreview = s.source?.slice(0, 50).replace(/\n/g, ' ') + (s.source?.length > 50 ? '...' : '');
72 console.log(' - [' + s.code + '] hits:', s.hits || 0);
73 console.log(' ', sourcePreview);
74 });
75
76 // Other relevant collections
77 console.log('\n📦 Other counts:');
78 const paintings = await db.collection('paintings').countDocuments();
79 console.log(' - Paintings:', paintings);
80
81 const handles = await db.collection('@handles').countDocuments();
82 console.log(' - Handles:', handles);
83
84 const moods = await db.collection('moods').countDocuments();
85 console.log(' - Moods:', moods);
86
87 } catch (err) {
88 console.error('Error:', err.message);
89 } finally {
90 await client.close();
91 }
92}
93
94main();