Skip to content

Commit b80372f

Browse files
committed
generate full graph
1 parent 97d349f commit b80372f

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
docker-compose.yml
22
data/graph.gexf
3+
data/graph-full.gexf
34
postgres-data/
45
.env
56
node_modules/

docker-compose.yml.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ services:
2121
restart: unless-stopped
2222
ports:
2323
- 8080:8080 # this is a really common port and should be changed most likely to something else
24+
depends_on:
25+
- app
2426
volumes:
2527
- ./nginx.conf:/etc/nginx/nginx.conf
2628
- ./public/:/usr/share/nginx/html/public
@@ -34,6 +36,5 @@ services:
3436
- ./data/:/app/data
3537
depends_on:
3638
- db
37-
- nginx
3839
environment:
3940
- DATABASE_URL=postgresql://postgres:slightlysecurepassword123@db:5432/postgres

nginx.conf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ http {
1313
proxy_pass http://app:8000;
1414
}
1515

16-
# Serve static files in /data
16+
# Serve static files in /data and block /data/graph-full.gexf as 403
1717
location /data {
1818
alias /usr/share/nginx/html/data;
1919
}
20+
21+
location /data/graph-full.gexf {
22+
deny all;
23+
return 403;
24+
}
2025
}
2126
}

src/bot.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,39 @@ async function generateGEXF() {
101101
}
102102
}
103103

104+
async function generateFullGEXF() { // generate full graph with all users
105+
await console.log('Generating FULL graph...');
106+
107+
// Create a new graph
108+
const graph = new Graph();
109+
110+
// Fetch all mentions and user lookups
111+
const mentions = await prisma.mention.findMany();
112+
const userLookups = await prisma.userLookup.findMany();
113+
114+
// add nodes to the graph
115+
userLookups.forEach((user) => {
116+
graph.addNode(user.id, { label: user.username });
117+
});
118+
119+
// add edges to the graph
120+
mentions.forEach((mention) => {
121+
if (graph.hasEdge(mention.user1Id, mention.user2Id)) {
122+
graph.updateEdgeAttribute(mention.user1Id, mention.user2Id, 'weight', (w) => w + mention.count);
123+
} else {
124+
graph.addEdge(mention.user1Id, mention.user2Id, { weight: mention.count });
125+
}
126+
});
127+
128+
// Export the graph
129+
try {
130+
fs.writeFileSync('data/graph-full.gexf', gexf.write(graph));
131+
console.log('Graph successfully exported to data/graph-full.gexf');
132+
} catch (err) {
133+
console.error('Error exporting graph:', err);
134+
}
135+
}
136+
104137
// On client ready
105138
client.once(Events.ClientReady, (readyClient) => {
106139
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
@@ -249,6 +282,7 @@ client.on(Events.MessageCreate, async (message) => {
249282
if (mentionsCounter >= MENTIONS_THRESHOLD) {
250283
mentionsCounter = 0; // Reset counter
251284
await generateGEXF();
285+
await generateFullGEXF();
252286
}
253287
});
254288

0 commit comments

Comments
 (0)