›
byrcsc/laravel-checklist · 1.x
Submission stores weighted item scores, nested section rollups, threshold results, and critical failures.
Submitting a checklist calculates one score from its answers and stores it, so
the result never changes afterwards. Scores are stored as ratios from 0.0 to
1.0, while template authors set pass thresholds as percentages.
Checkbox, yes/no, pass/fail, rating, and scored select items contribute to the total. Text, number, date, and unscored select items do not enter either side of the calculation.
A rating is normalized linearly between its bounds. On a 1 to 5 scale, answers
1, 3, and 5 score 0.0, 0.5, and 1.0.
A multiple select uses the mean score of its selected options. An empty multiple select is unanswered and unscored, not a zero.
$version = TemplateBuilder::make('Weighted inspection')
->passThreshold(75)
->passFail('Brakes')->weight(3)
->passFail('Cabin light')->weight(1)
->publish();If brakes pass and the cabin light fails, the score is 3 / 4 = 0.75.
Absolute weight values do not matter; their ratios do.
The calculator excludes unanswered, unscored, and not-applicable answers from the possible weight. Hiding an answered item removes its earned and possible weight together.
passThreshold(75) compares the stored ratio against 0.75. Landing exactly
on the threshold passes. The calculator rounds its ratio before comparison so
binary floating-point noise does not turn an exact boundary into a failure.
Without a threshold, the package still stores a score but leaves passed as
null. A score and a verdict are separate facts.
$builder->passFail('Emergency stop operates')->critical();Any applicable critical answer whose handler reports a score of exactly zero
sets critical_failed and forces passed to false, even when the total score
exceeds the threshold or no threshold exists.
Unscored answers never fail. A rating fails only at the bottom of its scale. A select option without a score is worth zero once any option on that item has a score.
Each section score covers its own items and every nested section below it. Every item contributes once to each ancestor rollup and once to the checklist total.
$score = $checklist->sectionScore($section);
$same = $checklist->sectionScore($section->id);A section with no applicable scorable answers has a null score, not zero.
Before submission, score, passed, and section_scores are null. Successful
submission stores the calculation so historical reports do not rerun current
code against old work.
Reopening clears stored results. The next submission recalculates them from the corrected applicable answers.