add grading, attendnace management
This commit is contained in:
@@ -2,27 +2,14 @@
|
||||
|
||||
namespace App\Services\Grading;
|
||||
|
||||
use App\Models\AttendanceRecord;
|
||||
use App\Models\CalendarEvent;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\ClassSection;
|
||||
use App\Models\GradingLock;
|
||||
use App\Models\Student;
|
||||
use App\Services\Scores\AttendanceCalculator;
|
||||
use App\Services\Scores\SemesterScoreService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class GradingOverviewService
|
||||
{
|
||||
private AttendanceCalculator $attendanceCalculator;
|
||||
|
||||
public function __construct(private SemesterScoreService $semesterScoreService)
|
||||
public function __construct()
|
||||
{
|
||||
$this->attendanceCalculator = new AttendanceCalculator(
|
||||
new AttendanceRecord(),
|
||||
new Configuration(),
|
||||
new CalendarEvent()
|
||||
);
|
||||
}
|
||||
|
||||
public function overview(?int $classId, ?string $semester, ?string $schoolYear): array
|
||||
@@ -38,62 +25,9 @@ class GradingOverviewService
|
||||
$scoresReleasedFall = $this->getParentScoresReleasedForSemester('Fall');
|
||||
$scoresReleasedSpring = $this->getParentScoresReleasedForSemester('Spring');
|
||||
|
||||
if ($classId && $this->semesterScoreService) {
|
||||
$sectionIds = ClassSection::query()
|
||||
->select('class_section_id')
|
||||
->where('class_id', $classId)
|
||||
->pluck('class_section_id')
|
||||
->map(fn ($v) => (int) $v)
|
||||
->all();
|
||||
foreach ($sectionIds as $sectionId) {
|
||||
$studentTeacherInfo = Student::getStudentInfoByClassSectionId(
|
||||
$sectionId,
|
||||
$semester,
|
||||
$schoolYear
|
||||
);
|
||||
if (empty($studentTeacherInfo)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$this->semesterScoreService->updateScoresForStudents($studentTeacherInfo, $semester, $schoolYear);
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rows = $this->buildGradingRows($semester, $schoolYear);
|
||||
|
||||
$counts = $this->loadScoreCounts($rows, $semester, $schoolYear);
|
||||
|
||||
$sectionsNeedingRefresh = [];
|
||||
foreach ($rows as $row) {
|
||||
$sectionId = (int) ($row['section_id'] ?? 0);
|
||||
if ($sectionId <= 0) {
|
||||
continue;
|
||||
}
|
||||
if ($row['ss_ptap_score'] === null || $row['ss_semester_score'] === null) {
|
||||
$sectionsNeedingRefresh[$sectionId] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($sectionsNeedingRefresh)) {
|
||||
foreach (array_keys($sectionsNeedingRefresh) as $sectionId) {
|
||||
$studentTeacherInfo = Student::getStudentInfoByClassSectionId(
|
||||
$sectionId,
|
||||
$semester,
|
||||
$schoolYear
|
||||
);
|
||||
if (empty($studentTeacherInfo)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$this->semesterScoreService->updateScoresForStudents($studentTeacherInfo, $semester, $schoolYear);
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
}
|
||||
$rows = $this->buildGradingRows($semester, $schoolYear);
|
||||
}
|
||||
|
||||
$grades = [];
|
||||
$studentsBySection = [];
|
||||
foreach ($rows as $row) {
|
||||
@@ -126,18 +60,7 @@ class GradingOverviewService
|
||||
continue;
|
||||
}
|
||||
|
||||
$attendanceScore = $this->calculateAttendanceScoreForStudent(
|
||||
$studentId,
|
||||
$semester,
|
||||
$schoolYear,
|
||||
$sectionId
|
||||
);
|
||||
if ($attendanceScore === null) {
|
||||
$rawAttendance = $row['ss_attendance_score'] ?? null;
|
||||
if ($rawAttendance !== null && $rawAttendance !== '') {
|
||||
$attendanceScore = round((float) $rawAttendance, 2);
|
||||
}
|
||||
}
|
||||
$attendanceScore = $this->normalizeScore($row['ss_attendance_score'] ?? null);
|
||||
|
||||
$studentRow = [
|
||||
'id' => $studentId,
|
||||
@@ -320,21 +243,6 @@ class GradingOverviewService
|
||||
return $map;
|
||||
}
|
||||
|
||||
private function calculateAttendanceScoreForStudent(int $studentId, string $semester, string $schoolYear, ?int $classSectionId = null): ?float
|
||||
{
|
||||
try {
|
||||
$result = $this->attendanceCalculator->calculate($studentId, $semester, $schoolYear, $classSectionId);
|
||||
$score = $result['attendance_score'] ?? null;
|
||||
if ($score === null || $score === '') {
|
||||
return null;
|
||||
}
|
||||
return round((float) $score, 2);
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function normalizeScore($value): ?float
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
|
||||
Reference in New Issue
Block a user