second commit
This commit is contained in:
@@ -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',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user