calculateScore

fun calculateScore(result: IntonationAnalysisResult, weightingMethod: WeightingMethod = WeightingMethod.EQUAL): PitchingScore

Calculate an overall intonation score (0–100) from analysis results.

Uses a piecewise linear grading scale that rewards high precision and penalizes noticeable deviations:

  • |deviation| ≤ 20% of interval: 90–100

  • 20% <|deviation| ≤ 40%: 70–90

  • 40% <|deviation| ≤ 80%: 50–70

  • |deviation|> 80%: 0–50 (clamped at 0)

For small samples (≤ 4 notes), an outlier-robust adjustment blends the base score with a re-weighted score that drops the worst note — this avoids a single flubbed note dominating a short sample. Result is rounded to one decimal place.

Return

Non-null PitchingScore with score (0–100, 1 decimal) and note count.

Parameters

result

Analysis result from analyzePitching. Must have error == null and a non-empty notes list — otherwise the result isn't scorable and this method throws.

weightingMethod

How to combine individual note scores: WeightingMethod.EQUAL weights all notes equally; WeightingMethod.DURATION weights by histogram peak amplitude (longer-held notes count more; falls back to EQUAL internally if all amplitudes are ≈ 0).

Throws

if result.error is non-null or result.notes is empty — an inconclusive analysis can't be scored, so callers must check result.error before invoking this method.