12 lines
633 B
PHP
12 lines
633 B
PHP
<?php
|
|||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
function calculate_sla_usage(float $allocatedHours, array $hours): array
|
||
|
|
{
|
||
|
|
$used = round(array_sum(array_map(static fn ($value): float => max(0.0, (float)$value), $hours)), 2);
|
||
|
|
$remaining = round(max(0.0, $allocatedHours - $used), 2);
|
||
|
|
$percentage = $allocatedHours > 0 ? round(($used / $allocatedHours) * 100, 2) : ($used > 0 ? 100.0 : 0.0);
|
||
|
|
$status = $used > $allocatedHours ? 'exceeded' : ($percentage >= 90 ? 'critical' : ($percentage >= 75 ? 'warning' : 'within_limit'));
|
||
|
|
return ['used' => $used, 'remaining' => $remaining, 'percentage' => $percentage, 'status' => $status];
|
||
|
|
}
|