or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-2/

Order Summary Generator

Turns a list of orders into a concise summary with rollups, rankings, and tag insights driven by completed orders.

Capabilities

Default behavior uses topNPerCategory of 2 and minimumTotalForRepeat of 2 when options are omitted.

Generates rollups from completed orders

  • Given completed and non-completed orders across regions and categories, returns a summary where only status: "completed" orders count; regionTotals are sorted by revenue (sum of total) descending with orderCount tallies; categoryLeaders lists up to two highest-total completed orders per category sorted by total descending then id, each entry keeping id, total, customerId, and tags (empty array when missing); repeatCustomers lists customerIds appearing in two or more completed orders sorted alphabetically; tagFrequency counts all non-empty tags from completed orders flattened, sorted by count descending then tag name. @test

Filters by allowed channels

  • When options.allowedChannels is provided, only orders whose channel is in that list participate; for ["online"] using the same base data, regionTotals, categoryLeaders, repeatCustomers, and tagFrequency reflect only online completed orders. @test

Honors tuning knobs and empty inputs

  • With topNPerCategory: 1 and minimumTotalForRepeat: 3 on a dataset where no customer reaches the threshold, repeatCustomers is empty; categoryLeaders include only the single highest completed order per category; passing an empty order array returns all summary fields as empty arrays. @test

Implementation

@generates

API

export type OrderStatus = 'completed' | 'cancelled' | 'pending';

export interface Order {
  id: string;
  region: string;
  category: string;
  channel: string;
  status: OrderStatus;
  total: number;
  customerId: string;
  tags?: string[];
}

export interface SummaryOptions {
  allowedChannels?: string[];
  topNPerCategory?: number; // defaults to 2
  minimumTotalForRepeat?: number; // defaults to 2
}

export interface RegionTotal {
  region: string;
  revenue: number;
  orderCount: number;
}

export interface CategoryLeader {
  category: string;
  top: { id: string; total: number; customerId: string; tags: string[] }[];
}

export interface TagCount {
  tag: string;
  count: number;
}

export interface Summary {
  regionTotals: RegionTotal[];
  categoryLeaders: CategoryLeader[];
  repeatCustomers: string[];
  tagFrequency: TagCount[];
}

export function summarizeOrders(
  orders: Order[],
  options?: SummaryOptions
): Summary;

Dependencies { .dependencies }

lodash { .dependency }

Utility helpers for working with collections efficiently. @satisfied-by