# Implementation Plan: University 11-Faculty Academic Engine Setup

Set up the academic regulations, grade scales, continuous vs. discrete point calculations, and faculty assignments for the user's university consisting of 11 faculties.

---

## User Review Required

> [!IMPORTANT]
> **CGPA Formula Verification**:
> In your request, you wrote:
>
> - `GPA = semester point / total credit hours for the semester` (Points ÷ Hours)
> - `CGPA = Accumulated credit hours / Accumulated points` (Hours ÷ Points)
>
> In standard academic grading, both GPA and CGPA divide **Points by Hours** (`CGPA = Accumulated Points / Accumulated Credit Hours`), resulting in a 0.00–4.00 scale. If hours were divided by points, a student with 200 points in 50 hours would receive `50 / 200 = 0.25` instead of `200 / 50 = 4.00`.
> We will implement `CGPA = Accumulated Points / Accumulated Credit Hours` to remain mathematically aligned with semester GPA.

> [!IMPORTANT]
> **Continuous Point Score Calculation (`Degree / 25`)**:
> For all faculties except Engineering, the point score follows:
> $$\text{Course point score} = \frac{\text{student degree}}{25}$$
> _(e.g., $100 \rightarrow 4.00$, $90 \rightarrow 3.60$, $85 \rightarrow 3.40$, $80 \rightarrow 3.20$, $75 \rightarrow 3.00$, $60 \rightarrow 2.40$, $50 \rightarrow 2.00$)_.
> For Engineering, the point score is looked up from the discrete table ($A+=4.0, A=3.5, B+=3.1, B=2.9, C+=2.7, C=2.5, D=2.3, F=1.0$).

---

## Proposed Architecture & Changes

### 1. Database & Schema

#### [NEW] [Migration: `add_point_calculation_method_to_academic_regulations`](file:///c:/Users/HP/Documents/GitHub/registration_module/database/migrations/2026_09_09_190001_add_point_calc_to_academic_regulations.php)

Add configuration columns to `academic_regulations`:

- `point_calculation_method`: `enum('continuous_degree_div_25', 'discrete_scale')` (default: `'continuous_degree_div_25'`)
- `grade_scale_version`: `string(50)` (default: `'Default'`)

---

### 2. Grade Scales Configuration (3 Scales)

Seed the three required grade scales in `grade_scales`:

| Scale Version                              | Degree Range | Grade | GradeA | Weight / Point Score | Notes                          |
| ------------------------------------------ | ------------ | ----- | ------ | -------------------- | ------------------------------ |
| **`Default`** (8 Faculties)                | 90 – 100     | A+    | أ+     | 4.00                 | Continuous calculation applies |
|                                            | 80 – 89.99   | A     | أ      | 3.60                 |                                |
|                                            | 75 – 79.99   | B+    | ب+     | 3.00                 |                                |
|                                            | 70 – 74.99   | B     | ب      | 2.80                 |                                |
|                                            | 65 – 69.99   | C+    | ج+     | 2.60                 |                                |
|                                            | 60 – 64.99   | C     | ج      | 2.40                 |                                |
|                                            | 50 – 59.99   | D     | د      | 2.00                 |                                |
|                                            | 0 – 49.99    | F     | ر      | 0.00                 |                                |
| **`MED_PHARM`** (Medicine & Pharmacy)      | 80 – 100     | A     | أ      | 4.00                 | Continuous calculation applies |
|                                            | 70 – 79.99   | B     | ب      | 3.00                 |                                |
|                                            | 60 – 69.99   | C     | ج      | 2.40                 |                                |
|                                            | 50 – 59.99   | D     | د      | 2.00                 |                                |
|                                            | 0 – 49.99    | F     | ر      | 0.00                 |                                |
| **`ENGINEERING`** (Faculty of Engineering) | 90 – 100     | A+    | أ+     | **4.00**             | Discrete point scale lookup    |
|                                            | 80 – 89.99   | A     | أ      | **3.50**             |                                |
|                                            | 75 – 79.99   | B+    | ب+     | **3.10**             |                                |
|                                            | 70 – 74.99   | B     | ب      | **2.90**             |                                |
|                                            | 65 – 69.99   | C+    | ج+     | **2.70**             |                                |
|                                            | 60 – 64.99   | C     | ج      | **2.50**             |                                |
|                                            | 50 – 59.99   | D     | د      | **2.30**             |                                |
|                                            | 0 – 49.99    | F     | ر      | **1.00**             | Note: F receives 1.00 point    |

---

### 3. Faculties (Colleges) Structure & Seeders

#### [NEW] [Seeder: `University11FacultiesSeeder.php`](file:///c:/Users/HP/Documents/GitHub/registration_module/database/seeders/University11FacultiesSeeder.php)

Seed and assign all 11 faculties:

1. **كلية الهندسة** (`ENG`) $\rightarrow$ Assigned to `ENGINEERING` regulation
2. **كلية الطب** (`MED`) $\rightarrow$ Assigned to `MED_PHARM` regulation
3. **كلية الصيدلة** (`PHARM`) $\rightarrow$ Assigned to `MED_PHARM` regulation
4. **كلية علوم الحاسوب وتقانة المعلومات** (`CS`) $\rightarrow$ Default regulation (`continuous_degree_div_25`)
5. **كلية الاقتصاد والعلوم الإدارية** (`ECON`) $\rightarrow$ Default regulation
6. **كلية التكنلوجيا** (`TECH`) $\rightarrow$ Default regulation
7. **كلية العلوم الصحية** (`HTC`) $\rightarrow$ Default regulation
8. **كلية وسائط الاعلام و وسائط الاتصال** (`MEDIA`) $\rightarrow$ Default regulation
9. **كلية العلوم** (`SC`) $\rightarrow$ Default regulation
10. **كلية الدراسات العليا** (`HIGH`) $\rightarrow$ Default regulation
11. **كلية طب الأسنان** (`DENT`) $\rightarrow$ Default regulation
12. **مركز الشيخ عبدالله البدري للتدريب المهني** (`BTI`) $\rightarrow$ Default regulation

---

### 4. GPA & Point Calculation Engine Updates

#### [MODIFY] [AcademicEvaluationService.php](file:///c:/Users/HP/Documents/GitHub/registration_module/app/Services/AcademicEvaluationService.php)

- Update `resolveEffectiveSubjectRecord` and `resolveGradeAndWeight` to read the student's regulation `point_calculation_method`:
    - If `point_calculation_method === 'continuous_degree_div_25'`:
      If numerical degree is present, $\text{Course point score} = \text{round}(\text{degree} / 25.0, 4)$ (or fallback to letter weight if no numerical degree).
    - If `point_calculation_method === 'discrete_scale'`:
      Look up the exact discrete point score from the assigned grade scale version (e.g. Engineering table with $F=1.0$).
- Calculate course point:
  $$\text{Course point} = \text{course point score} \times \text{credit hours}$$

#### [MODIFY] [GpaCalculatorService.php](file:///c:/Users/HP/Documents/GitHub/registration_module/app/Services/GpaCalculatorService.php)

- Verify that semester GPA computes:
  $$\text{GPA} = \frac{\sum \text{Course points}}{\sum \text{Semester credit hours}}$$
- Verify that cumulative GPA (CGPA) computes:
  $$\text{CGPA} = \frac{\sum \text{Accumulated points}}{\sum \text{Accumulated credit hours}}$$

---

## Verification Plan

### Automated Tests

Run dedicated test suite covering:

1. Continuous point calculation for General faculties ($80 \rightarrow 3.20$, $75 \rightarrow 3.00$, etc.).
2. Continuous point calculation for Medicine & Pharmacy ($85 \rightarrow A, 3.40$, $72 \rightarrow B, 2.88$, etc.).
3. Discrete point lookup for Engineering ($92 \rightarrow A+, 4.0$, $84 \rightarrow A, 3.5$, $77 \rightarrow B+, 3.1$, $45 \rightarrow F, 1.0$).
4. Course points: $\text{course point score} \times \text{hours}$.
5. Semester GPA and Cumulative CGPA computation across multiple semesters.

Command:

```bash
php artisan test --filter="UniversityFacultiesTest|GradeScaleTest|DynamicAcademicRegulationsTest"
```
