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

Function selectTopDimensions

packages/db/src/services/insights/utils.ts:130–151  ·  view source on GitHub ↗
(
  currentMap: Map<string, number>,
  baselineMap: Map<string, number>,
  maxDims: number,
)

Source from the content-addressed store, hash-verified

128 * @returns Array of dimension keys, ranked by greatest(current, baseline)
129 */
130export function selectTopDimensions(
131 currentMap: Map<string, number>,
132 baselineMap: Map<string, number>,
133 maxDims: number,
134): string[] {
135 // Merge all dimensions from both maps
136 const allDims = new Set<string>();
137 for (const dim of currentMap.keys()) allDims.add(dim);
138 for (const dim of baselineMap.keys()) allDims.add(dim);
139
140 // Rank by greatest(current, baseline)
141 const ranked = Array.from(allDims)
142 .map((dim) => ({
143 dim,
144 maxValue: Math.max(currentMap.get(dim) ?? 0, baselineMap.get(dim) ?? 0),
145 }))
146 .sort((a, b) => b.maxValue - a.maxValue)
147 .slice(0, maxDims)
148 .map((x) => x.dim);
149
150 return ranked;
151}

Callers 5

enumerateDimensionsFunction · 0.90
enumerateDimensionsFunction · 0.90
enumerateDimensionsFunction · 0.90
enumerateDimensionsFunction · 0.90
enumerateDimensionsFunction · 0.90

Calls 4

addMethod · 0.45
mapMethod · 0.45
fromMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected