Copy
async function analyzeTeamCommunication() {
console.log('\n=== TEAM COMMUNICATION ANALYSIS ===\n');
// Get recent messages
const messages = await graphlit.queryContents({
types: [ContentTypes.Message],
createdInLast: 'P30D'
limit: 1000
});
console.log(`Total messages (last 30 days): ${messages.contents.results.length}`);
// Channel breakdown
const channels = new Map<string, number>();
messages.contents.results.forEach(msg => {
const ch = msg.message?.channelName || 'unknown';
channels.set(ch, (channels.get(ch) || 0) + 1);
});
console.log(`\nActive channels: ${channels.size}`);
console.log('Top 10 channels:');
Array.from(channels.entries())
.sort((a, b) => b[1] - a[1])
.slice(0, 10)
.forEach(([channel, count]) => {
console.log(` #${channel}: ${count} messages`);
});
// Author activity
const authors = new Map<string, number>();
messages.contents.results.forEach(msg => {
const author = msg.message?.author?.name || 'unknown';
authors.set(author, (authors.get(author) || 0) + 1);
});
console.log(`\nActive authors: ${authors.size}`);
console.log('Top 10 authors:');
Array.from(authors.entries())
.sort((a, b) => b[1] - a[1])
.slice(0, 10)
.forEach(([author, count]) => {
console.log(` ${author}: ${count} messages`);
});
// Mention statistics
const mentioned = new Map<string, number>();
let totalMentions = 0;
messages.contents.results.forEach(msg => {
msg.message?.mentions?.forEach(mention => {
const name = mention.name || mention.email;
mentioned.set(name, (mentioned.get(name) || 0) + 1);
totalMentions++;
});
});
console.log(`\nTotal mentions: ${totalMentions}`);
console.log('Most mentioned:');
Array.from(mentioned.entries())
.sort((a, b) => b[1] - a[1])
.slice(0, 10)
.forEach(([person, count]) => {
console.log(` ${person}: ${count} mentions`);
});
// Collaboration score
const collaborations = new Map<string, Set<string>>();
messages.contents.results.forEach(msg => {
const author = msg.message?.author?.email;
if (author) {
if (!collaborations.has(author)) {
collaborations.set(author, new Set());
}
msg.message?.mentions?.forEach(m => {
collaborations.get(author)!.add(m.email);
});
}
});
console.log(`\n Collaboration Matrix:`);
Array.from(collaborations.entries())
.sort((a, b) => b[1].size - a[1].size)
.slice(0, 5)
.forEach(([author, collaborators]) => {
console.log(` ${author}: works with ${collaborators.size} people`);
});
}
await analyzeTeamCommunication();