docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Turns a list of orders into a concise summary with rollups, rankings, and tag insights driven by completed orders.
Default behavior uses topNPerCategory of 2 and minimumTotalForRepeat of 2 when options are omitted.
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. @testoptions.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. @testtopNPerCategory: 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. @testexport 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;Utility helpers for working with collections efficiently. @satisfied-by