# SCAS Schedule

SCAS (School Class Automated Scheduling) generates conflict-free class timetables for Benigno S. Aquino National High School. The system combines a Next.js interface, a FastAPI backend, SQLAlchemy/PostgreSQL persistence, and Google OR-Tools CP-SAT scheduling.

## Repository map

- `saas_frontend/` — Next.js scheduling interface and tenant-aware API client.
- `saas_backend/` — FastAPI services, database models, teacher allocation, CP-SAT solver, and curriculum verifier.
- `app/` and `migrations/` — application services and database migrations.
- `verification_reports/` — measured schedule evidence, raw trial data, tests, and screenshot proof.

See the [backend README](saas_backend/README.md) for API setup and deployment notes.

## Research Verification Evidence

This section records an executed verification run, not a proposed test. The saved measurements come from ten real CP-SAT solves of the frozen Grade 10 dataset. The accompanying [HTML report](verification_reports/index.html) renders the saved schedule and trial results without requiring the application to run.

### Dataset and isolation

| Item | Value |
|---|---:|
| School year | 2026-2027 |
| Grade level | Grade 10 |
| Sections | 30 |
| Catalog subjects | 12 |
| Faculty | 65 |
| Rooms | 45 |
| Programs | STE, TVE |
| Schedule shape | 5 days × 8 periods |
| Required class periods | 1,164 |
| Evaluation trials | 10 |
| Seeds | 42–51 |

The solver read sections, subjects, faculty, rooms, availability masks, and weekly limits from an isolated local SQLite copy containing the `verification-tenant` dataset. The working application database was not used as the output store, and the generated schedule was not written into production or live deployment data. Local verification databases are ignored by Git because they may contain account records.

Teacher allocation ran before timetabling. The allocator assigned all 300 applicable section-subject pairs to 65 teachers with no unallocated or overloaded pairs. Homeroom Guidance used adviser or least-loaded fallback assignments where no subject specialist existed; those warnings remain visible in the raw allocation evidence.

### Measurement protocol

1. Load the frozen Grade 10 dataset from the isolated database.
2. Allocate teachers to each applicable section-subject pair.
3. Build and solve the timetable with CP-SAT using a 60-second limit and the recorded seed.
4. Assign rooms and recompute section, teacher, availability, and room conflicts from the saved class rows.
5. Run the curriculum verifier twice: once with school-catalog frequency overrides and once against the official reference frequencies.
6. Repeat steps 2–5 for seeds 42 through 51.
7. Calculate per-trial metrics, then calculate the mean, sample standard deviation, minimum, maximum, and Student-t 95% confidence interval.
8. Cross-check the saved schedule, evaluation JSON, CSV, JUnit XML, report HTML, and screenshot hashes.

The first trial is retained as `schedule-run.json` and rendered as the example timetable. It is an illustration of one solve; the repeated trials provide the timing statistics.

### Metric definitions

| Metric | Definition |
|---|---|
| Completion | `assigned class periods ÷ required class periods × 100` |
| Sections scheduled | Required sections with at least one scheduled class ÷ required sections |
| Divisions represented | Required programs with at least one scheduled class ÷ required programs |
| Core subject coverage | Applicable core section-subject pairs with at least one class ÷ applicable core pairs |
| Specialized subject coverage | Applicable specialized section-subject pairs with at least one class ÷ applicable specialized pairs |
| Teacher workload accuracy | Active teachers within their configured weekly and daily limits ÷ active teachers |
| Time availability accuracy | Scheduled classes inside teacher availability masks ÷ scheduled classes |
| Lesson frequency accuracy | Applicable section-subject pairs with exactly the catalog frequency ÷ applicable pairs |
| Room-conflict prevention | Trials with zero room double-bookings ÷ all trials |
| Generation time | Solver elapsed time in seconds, recorded per trial |

The independent ledger additionally checks RA 8491 Monday Period 1, section collisions, teacher double-bookings, the six-period teacher daily ceiling, missing teachers, and exact school-catalog frequencies.

For timing values `x₁ … xₙ`, the report uses:

- `mean = Σxᵢ / n`
- `sample SD = √[Σ(xᵢ − mean)² / (n − 1)]`
- `95% CI = mean ± t(0.975, n−1) × sample SD / √n`

For ten trials, `n = 10`, `df = 9`, and the stored critical value is `t = 2.262`.

The predefined verdict rules were not changed after measurement:

- **Effective:** every hard-accuracy mean is at least 95%, and room-conflict prevention is 100%.
- **Efficient:** mean generation time is at most 60 seconds.

### Results

All ten trials returned `FEASIBLE`, assigned all 1,164 required periods, and recorded zero room conflicts, availability violations, or school-catalog verifier violations.

| Measure | Result |
|---|---:|
| Trials completed | 10/10 |
| Assigned periods per trial | 1,164/1,164 |
| Completion | 100.00% |
| Mean of all seven hard-accuracy metrics | 100.00% |
| Exact catalog-frequency pairs | 300/300 |
| Room-conflict-free trials | 10/10 |
| Teachers used | 65 |
| Maximum teacher weekly load | 28 periods |
| Maximum teacher daily load | 6 periods |
| Generation time, minimum | 60.2756 s |
| Generation time, maximum | 60.7689 s |
| Generation time, mean | 60.4618 s |
| Sample SD | 0.1683 s |
| 95% confidence interval | 60.3414–60.5822 s |
| Effectiveness verdict | Pass |
| Efficiency verdict | Fail |

The efficiency target failed by **0.4618 seconds** at the mean. The entire recorded 95% interval is above 60 seconds, so the result is not rounded into a pass.

| Trial | Seed | Status | Completion | Frequency accuracy | Seconds | Catalog violations |
|---:|---:|---|---:|---:|---:|---:|
| 1 | 42 | FEASIBLE | 100.00% | 100.00% | 60.6047 | 0 |
| 2 | 43 | FEASIBLE | 100.00% | 100.00% | 60.4366 | 0 |
| 3 | 44 | FEASIBLE | 100.00% | 100.00% | 60.7689 | 0 |
| 4 | 45 | FEASIBLE | 100.00% | 100.00% | 60.4011 | 0 |
| 5 | 46 | FEASIBLE | 100.00% | 100.00% | 60.4235 | 0 |
| 6 | 47 | FEASIBLE | 100.00% | 100.00% | 60.6746 | 0 |
| 7 | 48 | FEASIBLE | 100.00% | 100.00% | 60.4369 | 0 |
| 8 | 49 | FEASIBLE | 100.00% | 100.00% | 60.3044 | 0 |
| 9 | 50 | FEASIBLE | 100.00% | 100.00% | 60.2915 | 0 |
| 10 | 51 | FEASIBLE | 100.00% | 100.00% | 60.2756 | 0 |

### School catalog versus official MATATAG reference

School-catalog compliance and official-reference compliance are reported separately. The ten-trial `deped_violation_count` is zero because the catalog verifier uses the school's configured frequencies. The official-reference comparison finds **120 weekly-frequency gaps** across the 30 sections:

| Subject | School catalog | Official reference | Sections affected | Total gaps |
|---|---:|---:|---:|---:|
| English | 4 | 5 | 30 | 30 |
| Mathematics | 4 | 5 | 30 | 30 |
| Science | 4 | 5 | 30 | 30 |
| TLE | Not cataloged as TLE | 4 | 30 | 30 |
| EsP | 4 | 3–4 | 0 | 0 |
| HGP / Homeroom Guidance | 1 | 1 | 0 | 0 |

TVE specialization is not treated as equivalent to TLE. EsP at four periods is within the official 3–4 range. These 120 gaps must not be described as full official MATATAG compliance.

### Screenshot proof

Each image below was captured from the generated local report and inspected after capture. The screenshot manifest records the source HTML hash, browser version, viewport, image dimensions, and SHA-256 hash for every PNG.

#### 1. Run scope and verdict

Shows the database-backed dataset size, 1,164 scheduled periods, 100% completion, zero hard conflicts, and the separate effectiveness and efficiency verdicts.

![Run scope and verdict](verification_reports/screenshots/01-overview.png)

#### 2. Independent compliance ledger

Shows zero violations for flag ceremony, section collisions, teacher double-bookings, teacher daily load, availability, room collisions, exact weekly frequency, and missing teachers.

![Independent compliance ledger](verification_reports/screenshots/02-compliance.png)

#### 3. Official MATATAG comparison

Shows the English, Mathematics, Science, and TLE differences separately from the passing school-catalog checks. It also shows EsP as within range and HGP as matched.

![Official MATATAG comparison](verification_reports/screenshots/03-official-matatag.png)

#### 4. Ten-trial measurements

Shows all seven hard-accuracy means at 100%, the 60.4618-second mean, the confidence interval, and the ten per-trial observations.

![Ten-trial measurements](verification_reports/screenshots/04-metrics.png)

#### 5. Solver-generated timetable

Shows the first saved Grade 10 timetable with period labels on the left, teacher and room assignments in each cell, open slots, and Monday Period 1 reserved for flag ceremony.

![Solver-generated Grade 10 timetable](verification_reports/screenshots/05-timetable.png)

#### 6. Automated test evidence

Shows the clean backend suite result and the highest observed teacher loads. The maximum daily load is six periods.

![Automated test evidence](verification_reports/screenshots/06-test-evidence.png)

#### 7. Reproduction and provenance

Shows the commands, evidence-integrity checks, raw-data links, and hashes needed to trace the report back to its inputs.

![Reproduction and provenance](verification_reports/screenshots/07-reproduction.png)

#### 8. Standalone metric chart

Provides the accuracy and timing chart without the per-trial table for use as a research-paper figure.

![Standalone accuracy and timing chart](verification_reports/screenshots/08-metric-chart.png)

### Test evidence

| Suite | Result | Evidence |
|---|---:|---|
| Backend | 90 passed, 0 failed | [JUnit XML](verification_reports/data/pytest-results.xml) |
| Frontend | 3 passed, 0 failed | [Test output](verification_reports/data/frontend-tests.txt) |
| Report and evidence | 21 passed, 0 failed | [JUnit XML](verification_reports/data/report-test-results.xml) |

The first backend run overlapped with other local work and produced two timing failures. That run is retained as [initial contended output](verification_reports/data/pytest-initial-contended.txt). Both tests passed when rerun without competing services, and the clean 90-pass result is the reported suite outcome.

### Reproduction

Rebuild the HTML report and screenshots from the committed JSON evidence:

```bash
python -m pip install -r saas_backend/requirements.txt
python verification_reports/generate_report.py
python -m http.server 8777 --bind 127.0.0.1 --directory verification_reports
python verification_reports/capture_screenshots.py
```

Run the report and evidence tests:

```bash
cd saas_backend
python -m pytest ../verification_reports/tests -q
```

Rerun the solver experiment when a prepared isolated SQLite database is available:

```bash
python verification_reports/run_verification.py --trials 10
```

The default solver command expects `verification_reports/data/verification-run.db` with tenant `verification-tenant`. That database is intentionally not published. Use `--database` and `--tenant` to point to another prepared isolated copy. A full rerun also requires the backend dependencies, OR-Tools, and Pillow/Playwright with Chrome for screenshot capture.

### Artifact index

- [HTML report](verification_reports/index.html)
- [Saved first-trial schedule](verification_reports/data/schedule-run.json)
- [Ten-trial evaluation JSON](verification_reports/data/evaluation.json)
- [Per-trial CSV](verification_reports/data/evaluation-trials.csv)
- [Evidence integrity check](verification_reports/data/integrity-check.json)
- [Final cross-check](verification_reports/data/final-audit.json)
- [Screenshot manifest](verification_reports/screenshots/capture-manifest.json)
- [Report generator](verification_reports/generate_report.py)
- [Evidence runner](verification_reports/run_verification.py)
- [Screenshot capture script](verification_reports/capture_screenshots.py)

### Interpretation boundaries

- One displayed timetable is an example; the timing statistics come from ten separate seeded trials.
- The trials vary seeds on one frozen dataset. They do not establish performance across other schools, datasets, or hardware.
- `FEASIBLE` is a solver status, not proof of optimality.
- School-catalog frequencies are not automatically the official MATATAG allocations. The 120 official-reference gaps remain part of the result.
- Generation time depends on the recorded machine and concurrent workload. The environment versions are stored in the schedule JSON.
- No production records, live deployment data, paid service, or cloud upgrade was used for this experiment.
