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

Function executeAggregateChart

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

Source from the content-addressed store, hash-verified

82 * Executes a simplified pipeline: normalize -> fetch aggregate -> format
83 */
84export async function executeAggregateChart(
85 input: IReportInput
86): Promise<FinalChart> {
87 // Stage 1: Normalize input
88 const normalized = await normalize(input);
89
90 // Handle subscription end date limit
91 const endDate = await getOrganizationSubscriptionChartEndDate(
92 input.projectId,
93 normalized.endDate
94 );
95 if (endDate) {
96 normalized.endDate = endDate;
97 }
98
99 const { timezone } = await getSettingsForProject(normalized.projectId);
100
101 // Stage 2: Fetch aggregate data for current period (event series only)
102 const fetchedSeries: ConcreteSeries[] = [];
103
104 for (let i = 0; i < normalized.series.length; i++) {
105 const definition = normalized.series[i]!;
106
107 if (definition.type !== 'event') {
108 // Skip formulas - they'll be computed in the next stage
109 continue;
110 }
111
112 const event = definition as IChartEventItem & { type: 'event' };
113
114 // Build query input
115 const queryInput = {
116 event: {
117 id: event.id,
118 name: event.name,
119 segment: event.segment,
120 filters: event.filters,
121 displayName: event.displayName,
122 property: event.property,
123 },
124 projectId: normalized.projectId,
125 startDate: normalized.startDate,
126 endDate: normalized.endDate,
127 breakdowns: normalized.breakdowns,
128 limit: normalized.limit,
129 metric: normalized.metric,
130 previous: normalized.previous,
131 timezone,
132 };
133
134 // Execute aggregate query
135 let queryResult = await chQuery<ISerieDataItem>(
136 await getAggregateChartSql(queryInput),
137 {
138 session_timezone: timezone,
139 }
140 );
141

Callers

nothing calls this directly

Calls 10

normalizeFunction · 0.90
getSettingsForProjectFunction · 0.90
getAggregateChartSqlFunction · 0.90
groupByLabelsFunction · 0.90
computeFunction · 0.90
getChartPrevStartEndDateFunction · 0.90
formatFunction · 0.90
joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected