second commit

This commit is contained in:
2026-04-11 19:13:40 +02:00
parent 58bcc8f0f3
commit 87f7859017
25 changed files with 488 additions and 87 deletions
+21 -1
View File
@@ -72,6 +72,7 @@ final class ScoringService
'max_total' => $maxTotal,
'label' => $label,
'guardrail' => $guardrail,
'sentiment' => $this->sentimentForLabel($label, $ratings),
'percentage' => $maxTotal > 0 ? round(($total / $maxTotal) * 100, 1) : 0,
];
}
@@ -168,5 +169,24 @@ final class ScoringService
return $currentIndex > $capIndex ? $cap : $current;
}
}
private function sentimentForLabel(string $label, array $ratings): string
{
$order = array_values(array_map(static fn (array $rating): string => (string) $rating['label'], $ratings));
$index = array_search($label, $order, true);
if ($index === false || count($order) <= 1) {
return 'steady';
}
$ratio = $index / max(count($order) - 1, 1);
return match (true) {
$ratio <= 0.1 => 'storm',
$ratio <= 0.35 => 'heavy',
$ratio <= 0.65 => 'steady',
$ratio <= 0.9 => 'bright',
default => 'radiant',
};
}
}