or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-5/

Real-Time User Activity Monitor

Build a real-time user activity monitoring system that processes a streaming JSON API endpoint containing user events. The system should progressively parse and filter the event stream, tracking active users and responding to specific patterns.

Requirements

The system should fetch JSON data from a streaming endpoint and:

  1. Track when the response begins and log the HTTP status code
  2. Process user login events as they arrive, extracting username and timestamp
  3. Process user logout events as they arrive
  4. Detect and handle administrative events separately from regular user events
  5. Track completion of the entire stream and report final statistics
  6. Handle any errors that occur during streaming or parsing

Data Format

The streaming API returns JSON in this format:

{
  "stream_id": "abc123",
  "events": [
    {
      "type": "login",
      "username": "alice",
      "timestamp": "2024-01-15T10:30:00Z"
    },
    {
      "type": "logout",
      "username": "bob",
      "timestamp": "2024-01-15T10:35:00Z"
    },
    {
      "type": "admin_action",
      "username": "admin",
      "action": "user_ban",
      "timestamp": "2024-01-15T10:40:00Z"
    }
  ]
}

Implementation

@generates

API

/**
 * Start monitoring user activity from a streaming endpoint
 * @param {string} url - The streaming API endpoint URL
 * @returns {object} Monitor instance with methods to access collected data
 */
function monitorUserActivity(url) {
  // Returns an object with:
  // - activeUsers: Set of currently logged-in usernames
  // - adminEvents: Array of admin actions
  // - startTime: Timestamp when monitoring began
  // - complete: Boolean indicating if stream has completed
}

module.exports = { monitorUserActivity };

Test Cases

  • Given a URL returning JSON with three login events, activeUsers contains all three usernames @test
  • Given login events followed by a logout event, the logged-out username is removed from activeUsers @test
  • Given a stream with two admin_action events, adminEvents array contains both events @test
  • When the stream completes successfully, the complete flag changes to true @test

Dependencies { .dependencies }

oboe { .dependency }

Provides streaming JSON parsing for progressively handling HTTP responses.

@satisfied-by