feat(reports): restore the documented sample threshold, and draw the chart
MIN_SAMPLE goes back to the specified 10. The reason it had been lowered to 3 was real — a small clinic saw an empty report — but the fix was wrong: three samples do not make an average, and calling that "accurate" is worse than saying nothing. Rows below the threshold are now returned rather than dropped, with severity null and below_min_sample true. That refuses both mistakes: it claims no severity it cannot support, and it does not show a small clinic an empty page that implies everything is fine. They sort after the usable rows and render faded with a "small sample" badge. The utilization page gets its Recharts bar chart. The table stays underneath — six numeric columns are not something a chart answers — but the one question the table is bad at, "which resource is behind", is exactly what a chart is for. Colours come from the design tokens rather than hex, which is where a chart usually breaks in dark mode, and a resource with no calendar is left out entirely: null is not zero, and a zero bar would be a lie. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
final class PlanAccuracyReporter
|
||||
{
|
||||
/** زیر این تعداد نمونه، میانگین معنا ندارد. */
|
||||
public const MIN_SAMPLE = 3;
|
||||
public const MIN_SAMPLE = 10;
|
||||
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $em,
|
||||
@@ -59,12 +59,7 @@ final class PlanAccuracyReporter
|
||||
$out = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$sample = (int) $row['sample_size'];
|
||||
|
||||
if ($sample < self::MIN_SAMPLE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sample = (int) $row['sample_size'];
|
||||
$planned = (float) $row['planned'];
|
||||
$actual = (float) $row['actual'];
|
||||
|
||||
@@ -72,6 +67,26 @@ final class PlanAccuracyReporter
|
||||
continue;
|
||||
}
|
||||
|
||||
// زیر آستانه، **حذف نمیشود بلکه بیشدت برمیگردد**.
|
||||
//
|
||||
// میانگینِ سه نمونه معنا ندارد و نباید کسی رویش تصمیم بگیرد؛ ولی حذف کاملش
|
||||
// یعنی کلینیک کوچک یک گزارش خالی میبیند و فکر میکند همهچیز درست است.
|
||||
// اینطوری هم عدد را میبیند هم میداند که هنوز قابل استناد نیست.
|
||||
if ($sample < self::MIN_SAMPLE) {
|
||||
$out[] = [
|
||||
'service_uuid' => $row['service_uuid'],
|
||||
'service_name' => $row['service_name'],
|
||||
'sample_size' => $sample,
|
||||
'planned_minutes' => (int) round($planned),
|
||||
'actual_minutes' => (int) round($actual),
|
||||
'deviation_percent' => (int) round(($actual - $planned) / $planned * 100),
|
||||
'severity' => null,
|
||||
'below_min_sample' => true,
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$deviation = (int) round(($actual - $planned) / $planned * 100);
|
||||
|
||||
$out[] = [
|
||||
@@ -82,10 +97,14 @@ final class PlanAccuracyReporter
|
||||
'actual_minutes' => (int) round($actual),
|
||||
'deviation_percent' => $deviation,
|
||||
'severity' => $this->severityFor($deviation),
|
||||
'below_min_sample' => false,
|
||||
];
|
||||
}
|
||||
|
||||
usort($out, static fn (array $a, array $b): int => abs($b['deviation_percent']) <=> abs($a['deviation_percent']));
|
||||
// ردیفهای قابل استناد اول؛ بین خودشان، بدترین انحراف بالاتر.
|
||||
usort($out, static fn (array $a, array $b): int
|
||||
=> [$a['below_min_sample'], abs($b['deviation_percent'])]
|
||||
<=> [$b['below_min_sample'], abs($a['deviation_percent'])]);
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user