fix logic and tests, update docker CI file
This commit is contained in:
@@ -94,6 +94,10 @@ class ExamScoreService
|
||||
if (!is_numeric($studentId)) {
|
||||
continue;
|
||||
}
|
||||
$student = Student::query()->find((int) $studentId);
|
||||
if (!$student) {
|
||||
continue;
|
||||
}
|
||||
$rawScore = $data['score'] ?? null;
|
||||
$normalizedScore = is_numeric($rawScore) ? (float) $rawScore : null;
|
||||
|
||||
@@ -106,6 +110,7 @@ class ExamScoreService
|
||||
|
||||
$payload = [
|
||||
'student_id' => (int) $studentId,
|
||||
'school_id' => $student->school_id,
|
||||
'class_section_id' => $classSectionId,
|
||||
'updated_by' => $updatedBy,
|
||||
'score' => $normalizedScore,
|
||||
|
||||
@@ -57,12 +57,13 @@ class HomeworkScoreService
|
||||
->whereIn('semester', $semVariants)
|
||||
->where('school_year', $schoolYear)
|
||||
->get()
|
||||
->map(fn ($row) => (array) $row)
|
||||
->map(fn ($row) => $row->toArray())
|
||||
->all();
|
||||
|
||||
$scoresMap = [];
|
||||
foreach ($scoresRows as $row) {
|
||||
$scoresMap[(int) $row['student_id']][(int) $row['homework_index']] = $row['score'];
|
||||
$score = $row['score'] ?? null;
|
||||
$scoresMap[(int) $row['student_id']][(int) $row['homework_index']] = is_numeric($score) ? (float) $score : $score;
|
||||
}
|
||||
|
||||
foreach ($students as &$student) {
|
||||
@@ -196,6 +197,10 @@ class HomeworkScoreService
|
||||
->get();
|
||||
|
||||
foreach ($students as $student) {
|
||||
$studentRow = Student::query()->find((int) $student->student_id);
|
||||
if (!$studentRow) {
|
||||
continue;
|
||||
}
|
||||
$exists = Homework::query()
|
||||
->where('student_id', $student->student_id)
|
||||
->where('homework_index', $nextIndex)
|
||||
@@ -210,6 +215,7 @@ class HomeworkScoreService
|
||||
|
||||
Homework::query()->create([
|
||||
'student_id' => (int) $student->student_id,
|
||||
'school_id' => $studentRow->school_id,
|
||||
'class_section_id' => $classSectionId,
|
||||
'updated_by' => $updatedBy,
|
||||
'homework_index' => $nextIndex,
|
||||
|
||||
@@ -50,12 +50,14 @@ class ParticipationScoreService
|
||||
|
||||
$scoreMap = [];
|
||||
foreach ($scoresRows as $row) {
|
||||
$scoreMap[(int) $row->student_id] = $row->score;
|
||||
$score = $row->score;
|
||||
$scoreMap[(int) $row->student_id] = is_numeric($score) ? (float) $score : $score;
|
||||
}
|
||||
|
||||
foreach ($students as &$student) {
|
||||
$score = $scoreMap[$student['student_id']] ?? '';
|
||||
$student['scores'] = [
|
||||
'score' => $scoreMap[$student['student_id']] ?? '',
|
||||
'score' => $score,
|
||||
];
|
||||
}
|
||||
unset($student);
|
||||
|
||||
@@ -57,12 +57,13 @@ class ProjectScoreService
|
||||
->where('semester', $semester)
|
||||
->where('school_year', $schoolYear)
|
||||
->get()
|
||||
->map(fn ($row) => (array) $row)
|
||||
->map(fn ($row) => $row->toArray())
|
||||
->all();
|
||||
|
||||
$scoresMap = [];
|
||||
foreach ($scoresRows as $row) {
|
||||
$scoresMap[(int) $row['student_id']][(int) $row['project_index']] = $row['score'];
|
||||
$score = $row['score'] ?? null;
|
||||
$scoresMap[(int) $row['student_id']][(int) $row['project_index']] = is_numeric($score) ? (float) $score : $score;
|
||||
}
|
||||
|
||||
foreach ($students as &$student) {
|
||||
@@ -193,6 +194,10 @@ class ProjectScoreService
|
||||
->get();
|
||||
|
||||
foreach ($students as $student) {
|
||||
$studentRow = Student::query()->find((int) $student->student_id);
|
||||
if (!$studentRow) {
|
||||
continue;
|
||||
}
|
||||
$exists = Project::query()
|
||||
->where('student_id', $student->student_id)
|
||||
->where('project_index', $nextIndex)
|
||||
@@ -207,6 +212,7 @@ class ProjectScoreService
|
||||
|
||||
Project::query()->create([
|
||||
'student_id' => (int) $student->student_id,
|
||||
'school_id' => $studentRow->school_id,
|
||||
'class_section_id' => $classSectionId,
|
||||
'updated_by' => $updatedBy,
|
||||
'project_index' => $nextIndex,
|
||||
|
||||
@@ -56,12 +56,13 @@ class QuizScoreService
|
||||
->where('semester', $semester)
|
||||
->where('school_year', $schoolYear)
|
||||
->get()
|
||||
->map(fn ($row) => (array) $row)
|
||||
->map(fn ($row) => $row->toArray())
|
||||
->all();
|
||||
|
||||
$scoresMap = [];
|
||||
foreach ($scoresRows as $row) {
|
||||
$scoresMap[(int) $row['student_id']][(int) $row['quiz_index']] = $row['score'];
|
||||
$score = $row['score'] ?? null;
|
||||
$scoresMap[(int) $row['student_id']][(int) $row['quiz_index']] = is_numeric($score) ? (float) $score : $score;
|
||||
}
|
||||
|
||||
foreach ($students as &$student) {
|
||||
@@ -135,6 +136,10 @@ class QuizScoreService
|
||||
if (!is_array($quizData)) {
|
||||
$quizData = [1 => $quizData];
|
||||
}
|
||||
$student = Student::query()->find((int) $studentId);
|
||||
if (!$student) {
|
||||
continue;
|
||||
}
|
||||
foreach ($quizData as $quizNumber => $score) {
|
||||
if (!is_numeric($quizNumber)) {
|
||||
continue;
|
||||
@@ -152,6 +157,7 @@ class QuizScoreService
|
||||
|
||||
$payload = [
|
||||
'student_id' => (int) $studentId,
|
||||
'school_id' => $student->school_id,
|
||||
'class_section_id' => $classSectionId,
|
||||
'updated_by' => $updatedBy,
|
||||
'quiz_index' => (int) $quizNumber,
|
||||
@@ -190,6 +196,10 @@ class QuizScoreService
|
||||
->get();
|
||||
|
||||
foreach ($students as $student) {
|
||||
$studentRow = Student::query()->find((int) $student->student_id);
|
||||
if (!$studentRow) {
|
||||
continue;
|
||||
}
|
||||
$exists = Quiz::query()
|
||||
->where('student_id', $student->student_id)
|
||||
->where('quiz_index', $nextIndex)
|
||||
@@ -204,6 +214,7 @@ class QuizScoreService
|
||||
|
||||
Quiz::query()->create([
|
||||
'student_id' => (int) $student->student_id,
|
||||
'school_id' => $studentRow->school_id,
|
||||
'class_section_id' => $classSectionId,
|
||||
'updated_by' => $updatedBy,
|
||||
'quiz_index' => $nextIndex,
|
||||
|
||||
@@ -111,14 +111,14 @@ class ScoreDashboardService
|
||||
$sid = $student['student_id'];
|
||||
$scoreRow = $scores[$sid] ?? null;
|
||||
$student['scores'] = $scoreRow ? [
|
||||
'homework' => $scoreRow->homework_avg,
|
||||
'quiz' => $scoreRow->quiz_avg,
|
||||
'project' => $scoreRow->project_avg,
|
||||
'midterm_exam' => $scoreRow->midterm_exam_score,
|
||||
'final_exam' => $scoreRow->final_exam_score,
|
||||
'attendance' => $scoreRow->attendance_score,
|
||||
'ptap' => $scoreRow->ptap_score,
|
||||
'semester' => $scoreRow->semester_score,
|
||||
'homework' => $this->normalizeScore($scoreRow->homework_avg),
|
||||
'quiz' => $this->normalizeScore($scoreRow->quiz_avg),
|
||||
'project' => $this->normalizeScore($scoreRow->project_avg),
|
||||
'midterm_exam' => $this->normalizeScore($scoreRow->midterm_exam_score),
|
||||
'final_exam' => $this->normalizeScore($scoreRow->final_exam_score),
|
||||
'attendance' => $this->normalizeScore($scoreRow->attendance_score),
|
||||
'ptap' => $this->normalizeScore($scoreRow->ptap_score),
|
||||
'semester' => $this->normalizeScore($scoreRow->semester_score),
|
||||
] : [];
|
||||
$student['comments'] = $commentMap[$sid] ?? [];
|
||||
}
|
||||
@@ -267,4 +267,13 @@ class ScoreDashboardService
|
||||
'selectedYear' => $schoolYear,
|
||||
];
|
||||
}
|
||||
|
||||
private function normalizeScore(mixed $value): mixed
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return is_numeric($value) ? (float) $value : $value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user