Skip to content

feat: PDF horario upload — real Tec21 calendar from MiTec#19

Merged
danieldiazde merged 3 commits into
devfrom
feat/pdf-horario-parser
May 9, 2026
Merged

feat: PDF horario upload — real Tec21 calendar from MiTec#19
danieldiazde merged 3 commits into
devfrom
feat/pdf-horario-parser

Conversation

@danieldiazde
Copy link
Copy Markdown
Owner

Por qué

El calendario "5+1+5+1+5" calculado desde una sola fecha no funcionaba: cada estudiante tiene un horario distinto, con materias activas en periodos diferentes y Semanas Tec en fechas reales que dependen de su inscripción. Ahora leemos el PDF oficial de MiTec.

Cómo

Gemini multimodal (gemini-2.5-flash) acepta el PDF directo con structured output schema. Saca alumno, matrícula, periodo, materias con sus periodos y flag de Semana Tec.

Cambios

  • lib/pdf/horario-parser.ts — parse vía Gemini multimodal
  • POST /api/profile/horario — multipart upload, replaces materias_inscritas
  • lib/tec21/calendar.ts refactor: getPeriodoActivo() usa los periodos reales de la DB
  • Prompt updated: el modelo recibe periodo_activo real ("Semana Tec" / "Bloque N") en vez de calcularlo
  • Onboarding paso 3 ahora es upload del PDF (replaza selección manual de materias)
  • Auto-llena nombre/matrícula del PDF
  • profiles.semestre_inicio eliminado, reemplazado por periodo_nombre/periodo_inicio/periodo_fin
  • materias_inscritas gana crn y periodos jsonb

SQL Migration

ALTER TABLE profiles DROP COLUMN IF EXISTS semestre_inicio;
ALTER TABLE profiles ADD COLUMN IF NOT EXISTS periodo_nombre text;
ALTER TABLE profiles ADD COLUMN IF NOT EXISTS periodo_inicio date;
ALTER TABLE profiles ADD COLUMN IF NOT EXISTS periodo_fin date;
ALTER TABLE materias_inscritas ADD COLUMN IF NOT EXISTS crn text;
ALTER TABLE materias_inscritas ADD COLUMN IF NOT EXISTS periodos jsonb default '[]'::jsonb;

Test plan

  • CI verde
  • Onboarding paso 3 muestra dropzone para PDF
  • Subir Horarios.pdf → 8 materias detectadas con CRN y periodos
  • Insight regenerado → mensaje menciona "Semana Tec" hoy (May 9 cae en TI2002S)
  • Si hay eventos de Canvas con claves no inscritas, aparecen como inferidas

🤖 Generated with Claude Code

danieldiazde and others added 3 commits May 9, 2026 14:09
release: onboarding UX + Gemini insights engine
release: Persona A integration + Tec21 calendar + hydration fix
Replaces the hand-rolled "5+1+5+1+5" Tec21 calendar with the real periods
extracted from the student's official MiTec horario PDF. Periods, materias,
CRNs, schedules, and Semana Tec flags now come from the source of truth
instead of being computed from a single start date.

Backend
- lib/pdf/horario-parser.ts: sends the PDF directly to Gemini multimodal
  (gemini-2.5-flash) with a structured response schema. Returns alumno,
  matricula, periodo, and an array of materias with their `periodos`
  (each with inicio/fin/dias/hora_inicio/hora_fin/ubicacion/es_semana_tec).
- POST /api/profile/horario: multipart upload, parses, replaces
  materias_inscritas with PDF-derived rows and updates profiles with
  periodo_nombre/periodo_inicio/periodo_fin.
- lib/tec21/calendar.ts refactor: getPeriodoActivo() reads materias_inscritas.periodos
  to detect Semana Tec (any active period flagged) or compute the current
  block boundaries (intersection of active non-tec periods). Returns a
  human label and dias_restantes_bloque for prompt context.
- lib/gemini/prompts.ts: prompt now uses periodo_activo (real data) instead
  of computed semana_actual; new rules around Semana Tec; stronger Canvas
  prioritization; few-shot updated to a Semana Tec scenario.
- /api/insights/generate: filters materias to those active in the current
  period, marks Semana Tec materias, keeps Canvas-inferred materias.

Frontend
- OnboardingFlow rewritten: paso 3 ahora es "sube tu PDF de MiTec" en lugar
  de selección manual de materias. Auto-fills nombre/matricula del PDF.
- Old SelectedMateria/TOGGLE_MATERIA logic removed — PDF is source of truth.

Schema
- profiles.semestre_inicio dropped; replaced by periodo_nombre/periodo_inicio/periodo_fin.
- materias_inscritas: + crn text, + periodos jsonb.

Migration:
  ALTER TABLE profiles DROP COLUMN IF EXISTS semestre_inicio;
  ALTER TABLE profiles ADD COLUMN IF NOT EXISTS periodo_nombre text;
  ALTER TABLE profiles ADD COLUMN IF NOT EXISTS periodo_inicio date;
  ALTER TABLE profiles ADD COLUMN IF NOT EXISTS periodo_fin date;
  ALTER TABLE materias_inscritas ADD COLUMN IF NOT EXISTS crn text;
  ALTER TABLE materias_inscritas ADD COLUMN IF NOT EXISTS periodos jsonb default '[]'::jsonb;

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@supabase
Copy link
Copy Markdown

supabase Bot commented May 9, 2026

This pull request has been ignored for the connected project jwqffychkaczvknfgzbd because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@danieldiazde danieldiazde merged commit 1eb8368 into dev May 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant