Files
2026-05-16 13:44:12 -04:00

33 lines
962 B
PHP
Executable File

<?php
namespace App\Services\Calculators;
use App\Interfaces\ScoreCalculatorInterface;
use App\Models\ProjectModel;
class ProjectCalculator implements ScoreCalculatorInterface
{
private $projectModel;
public function __construct(ProjectModel $projectModel)
{
$this->projectModel = $projectModel;
}
/**
* Calculate the average project score for a student
*
* @param int $studentId
* @param string $semester
* @param string $schoolYear
* @return array Returns ['project_avg' => float|null]
* @throws \RuntimeException If no project scores are found
*/
public function calculate(int $studentId, string $semester, string $schoolYear, ?int $classSectionId = null): array
{
$average = $this->projectModel->getAverageProjectScore($studentId, $semester, $schoolYear, $classSectionId);
return ['project_avg' => $average !== null ? (float) $average : null];
}
}