MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / executeChart

Function executeChart

packages/db/src/engine/index.ts:27–78  ·  view source on GitHub ↗
(input: IReportInput)

Source from the content-addressed store, hash-verified

25 * Executes the pipeline: normalize -> plan -> fetch -> compute -> format
26 */
27export async function executeChart(input: IReportInput): Promise<FinalChart> {
28 // Stage 1: Normalize input
29 const normalized = await normalize(input);
30
31 // Handle subscription end date limit
32 const endDate = await getOrganizationSubscriptionChartEndDate(
33 input.projectId,
34 normalized.endDate
35 );
36 if (endDate) {
37 normalized.endDate = endDate;
38 }
39
40 // Stage 2: Create execution plan
41 const executionPlan = await plan(normalized);
42
43 // Stage 3: Fetch data for event series (current period)
44 const fetchedSeries = await fetch(executionPlan);
45
46 // Stage 4: Compute formula series
47 const computedSeries = compute(fetchedSeries, executionPlan.definitions);
48
49 // Stage 5: Fetch previous period if requested
50 let previousSeries: ConcreteSeries[] | null = null;
51 if (input.previous) {
52 const currentPeriod = {
53 startDate: normalized.startDate,
54 endDate: normalized.endDate,
55 };
56 const previousPeriod = getChartPrevStartEndDate(currentPeriod);
57
58 const previousPlan = await plan({
59 ...normalized,
60 ...previousPeriod,
61 });
62
63 const previousFetched = await fetch(previousPlan);
64 previousSeries = compute(previousFetched, previousPlan.definitions);
65 }
66
67 // Stage 6: Format final output with previous period data
68 const includeAlphaIds = executionPlan.definitions.length > 1;
69 const response = format(
70 computedSeries,
71 executionPlan.definitions,
72 includeAlphaIds,
73 previousSeries,
74 normalized.limit
75 );
76
77 return response;
78}
79
80/**
81 * Aggregate Chart Engine - Optimized for bar/pie charts without time series

Callers

nothing calls this directly

Calls 7

normalizeFunction · 0.90
planFunction · 0.90
fetchFunction · 0.90
computeFunction · 0.90
getChartPrevStartEndDateFunction · 0.90
formatFunction · 0.90

Tested by

no test coverage detected