(signalKey: string)
| 85 | * Returns null if the signal_key isn't in the map. |
| 86 | */ |
| 87 | export function primaryDimensionFor(signalKey: string): Dimension | null { |
| 88 | const entry = SIGNAL_MAP[signalKey]; |
| 89 | if (!entry) return null; |
| 90 | const totals: Partial<Record<Dimension, number>> = {}; |
| 91 | for (const choice of Object.keys(entry)) { |
| 92 | for (const dd of entry[choice]) { |
| 93 | totals[dd.dim] = (totals[dd.dim] ?? 0) + Math.abs(dd.delta); |
| 94 | } |
| 95 | } |
| 96 | let best: Dimension | null = null; |
| 97 | let bestVal = -Infinity; |
| 98 | for (const d of ALL_DIMENSIONS) { |
| 99 | const v = totals[d] ?? 0; |
| 100 | if (v > bestVal) { |
| 101 | bestVal = v; |
| 102 | best = d; |
| 103 | } |
| 104 | } |
| 105 | return bestVal > 0 ? best : null; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Given a signal_key, return a one-line plain-English annotation when |
no outgoing calls
no test coverage detected