Skip to content

Latest commit

 

History

History
342 lines (266 loc) · 6.38 KB

File metadata and controls

342 lines (266 loc) · 6.38 KB

Statistics and Analytics Documentation

Overview

DevTerm Network provides comprehensive statistics and analytics powered by MongoDB aggregation queries and ASCII chart visualization. Track your activity, analyze post performance, and view trends.

Features

  • User Statistics: Karma, posts, likes, followers, top tags
  • Post Analytics: Likes, comments, views, engagement rate
  • Daily Activity: ASCII charts showing activity over time
  • Trending Tags: Most popular tags across the platform
  • Platform Stats: Global metrics and insights

Commands

View Your Stats

stats

Shows your overall statistics including:

  • Username and karma
  • Total posts created
  • Likes and comments received
  • Follower/following counts
  • Top 5 tags you use
  • Account creation date

Example Output:

📊 Your Statistics

Username: johndoe
Karma: 1,234 ⭐
Joined: 2026-01-15

Activity:
  📝 Posts: 42
  👍 Likes Received: 156
  💬 Comments Received: 89

Network:
  👥 Followers: 23
  👤 Following: 15

Top Tags:
  1. #javascript (12 posts)
  2. #react (8 posts)
  3. #nodejs (6 posts)

View Post Statistics

stats <post-id>

Analyzes a specific post with detailed metrics:

  • Like count
  • Comment count
  • View count
  • Engagement rate (%)
  • Top commenters
  • Tags

Example:

stats post123

Output:

📊 Post Statistics

Post ID: post123
Author: johndoe
Type: code
Created: 2/8/2026

Engagement:
  👍 Likes: 42
  💬 Comments: 18
  👁️  Views: 250
  📈 Engagement Rate: 24.00%

Top Commenters:
  1. alice (5 comments)
  2. bob (3 comments)
  3. charlie (2 comments)

Tags: javascript, async, promises

Daily Activity Chart

stats --daily [--days=7]

Generates an ASCII chart showing your daily activity (posts + comments).

Parameters:

  • --days: Number of days to analyze (default: 7, max: 30)

Example:

stats --daily
stats --daily --days=14

Output:

📈 Daily Activity (Last 7 Days)

    10.00 ┤     ╭╮
     8.00 ┤    ╭╯╰╮
     6.00 ┤   ╭╯  ╰╮
     4.00 ┤  ╭╯    ╰╮
     2.00 ┤╭─╯      ╰─╮
     0.00 ┼╯          ╰

Total Activity: 45
Average Daily: 6.43
Period: 2026-02-01 to 2026-02-08

Technical Details

MongoDB Aggregations

User Stats Query:

// Total likes received
Post.aggregate([
  { $match: { author: userId } },
  { $project: { likeCount: { $size: '$likes' } } },
  { $group: { _id: null, total: { $sum: '$likeCount' } } }
])

// Top tags
Post.aggregate([
  { $match: { author: userId } },
  { $unwind: '$tags' },
  { $group: { _id: '$tags', count: { $sum: 1 } } },
  { $sort: { count: -1 } },
  { $limit: 5 }
])

Post Stats Query:

// Top commenters
Comment.aggregate([
  { $match: { post: postId } },
  { $group: { _id: '$author', count: { $sum: 1 } } },
  { $sort: { count: -1 } },
  { $limit: 3 },
  { $lookup: {
    from: 'users',
    localField: '_id',
    foreignField: '_id',
    as: 'user'
  }}
])

Daily Activity Query:

Post.aggregate([
  {
    $match: {
      author: userId,
      createdAt: { $gte: startDate }
    }
  },
  {
    $group: {
      _id: {
        $dateToString: { format: '%Y-%m-%d', date: '$createdAt' }
      },
      count: { $sum: 1 }
    }
  },
  { $sort: { _id: 1 } }
])

ASCII Charts

Powered by asciichart library:

Configuration:

{
  height: 10,           // Chart height in lines
  format: (x) => x.toFixed(0),  // Number formatting
  padding: '       '    // Left padding
}

Features:

  • Auto-scaling to fit data range
  • Unicode box-drawing characters
  • Customizable height and padding
  • Smooth curves for trends

Engagement Rate Calculation

engagementRate = ((likes + comments) / views) * 100
  • Measures how engaging content is
  • Higher rate = more interactive audience
  • Typical good rate: 10-30%

API Endpoints

Get User Stats

GET /api/stats/user/:userId?
Authorization: Bearer <token>

Get Post Stats

GET /api/stats/post/:postId
Authorization: Bearer <token>

Get Daily Activity

GET /api/stats/daily?days=7
Authorization: Bearer <token>

Get Trending Tags

GET /api/stats/trending?limit=10
Authorization: Bearer <token>

Get Platform Stats

GET /api/stats/platform
Authorization: Bearer <token>

Performance Optimization

Redis Caching (Future)

Stats can be cached in Redis for faster access:

// Cache user stats for 5 minutes
redis.setex(`stats:user:${userId}`, 300, JSON.stringify(stats));

// Cache trending tags for 1 hour
redis.setex('stats:trending', 3600, JSON.stringify(tags));

Query Optimization

  • Indexes on author, createdAt, tags
  • Aggregation pipeline optimization
  • Limit result sets appropriately
  • Use projection to reduce data transfer

Use Cases

Track Your Progress

# Check daily to see growth
stats
stats --daily

Analyze Post Performance

# See which posts perform best
stats post123
stats post456

Identify Trends

# View your activity patterns
stats --daily --days=30

Compare Engagement

# Check multiple posts
stats postA
stats postB
# Compare engagement rates

Metrics Explained

Karma: Points earned from creating content and receiving engagement

Posts: Total number of posts you've created

Likes Received: Sum of all likes on your posts

Comments Received: Total comments on your posts

Engagement Rate: Percentage of viewers who interacted (liked/commented)

Top Tags: Your most frequently used tags

Daily Activity: Posts + comments created per day

Best Practices

  1. Check Stats Regularly: Monitor your growth weekly
  2. Analyze Top Posts: Learn what content resonates
  3. Track Engagement: Aim for >15% engagement rate
  4. Use Popular Tags: Check trending tags for visibility
  5. Maintain Consistency: Daily activity chart should show steady activity

Future Enhancements

  • Real-time stats updates via WebSocket
  • Comparative analytics (vs. other users)
  • Predictive trends with ML
  • Export stats as CSV/JSON
  • Custom date ranges
  • Hourly activity breakdown
  • Follower growth charts
  • Tag correlation analysis
  • Content recommendations based on stats

Happy Analyzing! 📊

Type stats to see your overview, stats <post-id> for post analytics, or stats --daily for your activity chart!