Adding script for exporting study plan from Ladok#37
Open
cohm wants to merge 1 commit into
Open
Conversation
…rom KOPPS, so far)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses #11.
Adds a Python extractor that builds candidate
src/data/<PROG>.jsonfiles from Ladok's programstruktur, plus a small--includeflag on the validator so candidates can be schema-checked outsideprograms.json. First target: CTFYS. Verified data is never touched — the extractor writes to<PROG>.ladok.jsonfor human diff-and-merge review.End-to-end smoke test against CTFYS HT23: 48 entries (46 courses, 2 option groups), structurally aligned with the hand-curated
CTFYS.jsonfor years 1–2 and the year-3 mandatories + bachelor thesis.What's new
scripts/extract-from-ladok.py— Python 3.11+ CLI. Talks to Ladok viadbosk/ladok3for the programme struktur, period scheduling, credits, and Swedish/English titles. Enriches with KOPPS (api.kth.se/api/kopps/v2/course/<code>) and the public kursplan HTML page for prerequisites, grading scale, and course level. Output goes to a candidate file alongside the verified one; existing<PROG>.jsonis never overwritten.scripts/requirements.txt— pinsladok3,requests,beautifulsoup4.scripts/validate-data.mjs— new--include <programCode>=<path>flag so a candidate JSON can be validated against the corresponding programme entry fromprograms.jsonwithout registering it as the active data file.CLAUDE.md— extractor recipe added to the Commands block (venv setup,ladok login, run, validate)..gitignore— adds/.venvand/scripts/.venv.CLI surface
How it works
program_rounds_JSON(code)lists every round Ladok has for that programme. Numeric admission codes win overOP*year-2-entry rounds;DTF*/DTM*/DFA*/DFY*exchange/double-degree rounds are filtered out. Cohort is chosen bySammanslagenTillfallesperiod.Startdatum.http://relations.ladok.se/utbildningsinformation/strukturon the programme round. The response'sInnehallis a tree of typedBoxtypboxes:UTBILDNINGSTILLFALLESBOXis a course-round leaf OR a sub-programme reference (distinguished by whetherUtbildningskodmatches the KTH course-code regex^[A-Z]{2,3}\d{3,4}[A-Z]?$);VALBOXis an elective container whose descendants become options;SEKVENSBOXand friends are pass-through containers. Sub-programme references are followed (one extra level) via their own struktur link. VALBOX context propagates across sub-programme boundaries so options inside a sub-programme stay grouped with their enclosing VALBOX.course_round_utbildningsinformation_JSON(cr_uid).Tillfallesperioder. Two shapes are handled: the structured (HT25+) formLasperiodsfordelning.Fordelningsposter[*]withLasperiodskod+Omfattningsvarde, and the legacy / date-based (HT23 and earlier) form with oneTillfallesperioderentry per period carryingForstaUndervisningsdatum+Omfattningsvarde— period derived from the start date.Startdatumversus the cohort's admission year.optionGroupentry (named fromBenamning, orValbart block Nnumbered chronologically when anonymous), plus aCourseentry for each option (the validator requiresoptions[]to reference real courses).exams/reexamsstay empty — those require manual verification against Riktlinje om läsårets förläggning and are left for the human reviewer.Validation against CTFYS
HT23 cohort, 46 courses + 2 option groups:
Valbart block 2(year 3, 15 hp, P3+P4) with options[EF112X, SA114X]— matches the verifiedKandidatexamensarbetemodulo the name (rename during merge).Valbart block 1with 20 KTH-recommended tillvalskurser — the real Ladok representation of the verified file'sXY123Z/XY456Zplaceholders.SF1675,SF1918, etc.) and the expected cosmetics warnings about year-3 placeholders.Known limitations
Tillfallesperioderin Ladok even when the verified file splits them across periods (DD1331, SE1055, SF1683, SG1112, SI1121). Total credits and the start period are correct; the trailing period attribution is missing from Ladok's source. Newer cohorts (HT25) use the structured shape and don't have this issue.exams/reexamsare always empty — by design.Valbart block N. CTFYS's two year-3 VALBOXes both come out anonymous and should be renamed during merge (Rekommenderade kurser,Kandidatexamensarbete).Test plan
pip install -r scripts/requirements.txtsucceeds in a fresh.venv.python scripts/extract-from-ladok.py --helpworks without ladok3 installed.npm run validate-datastill passes (no regression).node scripts/validate-data.mjs --include CTFYS=src/data/CTFYS.ladok.jsonreports 0 errors.python scripts/extract-from-ladok.py CTFYS --list-roundsenumerates all CTFYS rounds with[✓]/[skip]markers for the regular admission vs special-purpose codes.python scripts/extract-from-ladok.py CTFYS --cohort HT25produces a candidate covering years 1–2 (HT25 cohort hasn't reached year 3 yet, and Ladokstrukturobject is not complete).python scripts/extract-from-ladok.py CTFYS --cohort HT23produces a candidate with the year-3 content including both VALBOXes.useCourseModel.tsexpects (flatperiodCredits+year,optionGroupentries withkind: "pickN", etc.) — verified by the--includecheck above.Still to do
The ladok3 package should be extended to allow for reading out the prerequisite information so that everything can come from Ladok, and we don't need to resort to Kopps (discontinued) or course web pages (which anyway take their info from Ladok, I think).