Skip to content

Commit e4ad6be

Browse files
committed
docs: add advanced scoring section
1 parent 4ef80f3 commit e4ad6be

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

packages/cli/docs/scoring.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,76 @@ xychart-beta
286286
y-axis "Score" 0 --> 1
287287
line Grade [0,0,0,0,0.5,0.5,0.5,0.75,1,1,1]
288288
```
289+
290+
## Advanced Scoring Strategies
291+
292+
### Overview Table
293+
294+
| **Strategy Name** | **Formula** | **Description** |
295+
| ------------------------- | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
296+
| **Issue Penalty Scoring** | $$\text{finalScore} = \max\left(0, \text{thresholdScore} - \frac{w_e \times E + w_w \times W}{w_e + w_w}\right)$$ | Combines threshold limits with diagnostic penalties for comprehensive scoring. |
297+
298+
---
299+
300+
### Issue Penalty Scoring Details
301+
302+
Combines threshold limits with diagnostic penalties for comprehensive scoring.
303+
304+
**Pros:**
305+
306+
- Combines quantitative limits with quality metrics
307+
- Configurable penalty weights for different issue types
308+
- Applicable to any metric with both thresholds and diagnostics
309+
310+
**Cons:**
311+
312+
- More complex than single-metric strategies
313+
- Requires careful tuning of penalty weights
314+
315+
**Implementation:**
316+
317+
```ts
318+
function issuePenaltyScore(value: number, threshold: number, errors: number, warnings: number, errorWeight: number = 1, warningWeight: number = 0.5): number {
319+
const thresholdScore = value <= threshold ? 1 : Math.max(0, 1 - (value - threshold) / threshold);
320+
const penalty = errorWeight * errors + warningWeight * warnings;
321+
const totalWeight = errorWeight + warningWeight;
322+
const normalizedPenalty = totalWeight > 0 ? penalty / totalWeight : 0;
323+
return Math.max(0, thresholdScore - normalizedPenalty);
324+
}
325+
```
326+
327+
**When to use it:**
328+
Ideal for production metrics where you need to balance performance targets with maintainability diagnostics.
329+
330+
**Examples:**
331+
Bundle size + ESLint errors, page load time + accessibility warnings, complexity thresholds + TypeScript diagnostics.
332+
333+
**Parameters & Formulas:**
334+
335+
| Parameter | Description |
336+
| --------- | ----------------------------------------------- |
337+
| `S` | Actual value (bytes, milliseconds, count, etc.) |
338+
| `M` | Maximum threshold value |
339+
| `E` | Count of **errors** (🚨) |
340+
| `W` | Count of **warnings** (⚠️) |
341+
| `we` | Weight per error (default 1) |
342+
| `ww` | Weight per warning (default 0.5) |
343+
344+
$$\text{thresholdScore} = \begin{cases} 1, & S \leq M \\[4pt] \max(0, 1 - \frac{S-M}{M}), & S > M \end{cases}$$
345+
346+
$$\text{penalty} = w_e \times E + w_w \times W$$
347+
348+
$$\text{finalScore} = \max\left(0, \text{thresholdScore} - \frac{\text{penalty}}{w_e + w_w}\right)$$
349+
350+
**Example:** Value=15 (threshold: 10), 1 error, 2 warnings → thresholdScore = 0.5, penalty = 2, finalScore = 0
351+
352+
**Chart:**
353+
354+
```mermaid
355+
xychart-beta
356+
title "Issue Penalty Score (M=10, 1 error, 2 warnings)"
357+
x-axis "Value" [0,2,4,6,8,10,12,14,16,18,20]
358+
y-axis "Score" 0 --> 1
359+
line "Threshold Only" [1,1,1,1,1,1,0.83,0.71,0.6,0.5,0.4]
360+
line "With Penalties" [0,0,0,0,0,0,0,0,0,0,0]
361+
```

0 commit comments

Comments
 (0)