or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-6/

Data Processing Pipeline

Build a data processing utility that transforms and analyzes user activity logs using method chaining.

Requirements

Implement a function processActivityLogs(logs) that accepts an array of user activity log objects and returns a processed summary object. The function should:

  1. Filter out any logs where the status field is 'invalid'
  2. Group the remaining logs by the userId field
  3. For each user, calculate:
    • The total number of activities
    • The total points earned across all activities
  4. Sort users by total points in descending order
  5. Return only the top 5 users with their statistics

Each log object has this structure:

{
  userId: string,
  activity: string,
  points: number,
  status: 'valid' | 'invalid'
}

The output should be an array of objects with this structure:

{
  userId: string,
  activityCount: number,
  totalPoints: number
}

Important: Your solution should use a fluent chaining approach for data transformation rather than multiple intermediate variables.

Test Cases { .test-cases }

Test Case 1: Basic filtering and grouping { .test-case @test }

Input:

const logs = [
  { userId: 'user1', activity: 'login', points: 10, status: 'valid' },
  { userId: 'user2', activity: 'post', points: 50, status: 'valid' },
  { userId: 'user1', activity: 'comment', points: 20, status: 'valid' },
  { userId: 'user3', activity: 'share', points: 5, status: 'invalid' },
  { userId: 'user2', activity: 'like', points: 5, status: 'valid' }
];

Expected Output:

[
  { userId: 'user2', activityCount: 2, totalPoints: 55 },
  { userId: 'user1', activityCount: 2, totalPoints: 30 }
]

Test Case 2: Top 5 limit { .test-case @test }

Input:

const logs = [
  { userId: 'user1', activity: 'post', points: 100, status: 'valid' },
  { userId: 'user2', activity: 'post', points: 90, status: 'valid' },
  { userId: 'user3', activity: 'post', points: 80, status: 'valid' },
  { userId: 'user4', activity: 'post', points: 70, status: 'valid' },
  { userId: 'user5', activity: 'post', points: 60, status: 'valid' },
  { userId: 'user6', activity: 'post', points: 50, status: 'valid' },
  { userId: 'user7', activity: 'post', points: 40, status: 'valid' }
];

Expected Output:

[
  { userId: 'user1', activityCount: 1, totalPoints: 100 },
  { userId: 'user2', activityCount: 1, totalPoints: 90 },
  { userId: 'user3', activityCount: 1, totalPoints: 80 },
  { userId: 'user4', activityCount: 1, totalPoints: 70 },
  { userId: 'user5', activityCount: 1, totalPoints: 60 }
]

Implementation Files { .files }

process-logs.js { .file }

Implement the processActivityLogs function here and export it.

process-logs.test.js { .file @test }

Test file for the implementation. Should include the test cases specified above and any additional tests.

Dependencies { .dependencies }

lodash { .dependency }

Provides utility functions for data transformation and chaining.