fix(scripts): classify DMOJ problems and backfill degraded metadata - #141
Merged
Conversation
The classifier's source detection was still two-way, so a DMOJ URL fell into the Codeforces branch, failed to parse, and the row never got a type. Add DMOJ detection, URL extraction, and an API fetcher alongside the existing providers. DMOJ's Cloudflare rejects datacenter egress, so the /api/dmoj proxy returns 403 from Vercel and a submitted problem is stored with its bare code as the name and no tags. This script runs from a maintainer machine, where the API answers, so it also repairs those rows: when a row's name still equals its DMOJ problem code, name and tags are refreshed from the API. Rows on other providers, and DMOJ rows with a real name, are left untouched.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
main() constructed the Gemini client before touching the database, so a metadata repair required an API key it never uses. --backfill-only skips the client, narrows the query to DMOJ rows, and skips the type write, so the run only refreshes name and tags on rows still holding a bare problem code.
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.
Why
Two problems surfaced after #140 merged.
DMOJ is unreachable from any server we control. Probed from three network positions:
200/api/dmoj, 5 consecutive40352.225.25.54), 2 UA variants403Cloudflare rejects datacenter egress and User-Agent makes no difference, so neither a header tweak nor a scheduled CI job fixes it. DMOJ also sends no
access-control-allow-origin, ruling out a browser-side fetch. A submitted DMOJ problem therefore lands in the degraded state the ingestion fallback produces: name equals the bare problem code, no tags.ciw26p2is live in that state today.The classifier never learned about DMOJ.
get_problem_sourcewas still two-way, so a DMOJ URL fell into the Codeforces branch, failed to parse, and the row never got atype. That is a downstream miss from #140.What changed
scripts/classify_problems.pygains DMOJ alongside the existing providers:get_problem_sourcereturns"dmoj"fordmoj.caURLsextract_dmoj_infoparsesdmoj.ca/problem/<code>, rejecting bare codes for the same reason the web ingestion doesfetch_dmoj_problemreads name and types fromapi/v2/problem/<code>; the API carries no statement, so classification uses name and tags aloneis_degraded_metadataplus a write in the main loop: when a row's name still equals its DMOJ problem code,nameandtagsare refreshed from the APIThe backfill is deliberately narrow. It fires only when the stored name is exactly the problem code, so curated Kattis and Codeforces names cannot be clobbered, and a DMOJ row that already has a real name is left alone.
No new dependencies —
requestsandpsycopgwere already in use.Running it
From a machine with residential egress, after applying:
--allis required to reach rows that already have atypeset; the default query only selectsWHERE type IS NULL.Validation
python -m compileall -q scripts, 11 unittests pass (4 new DMOJ fetcher tests, 2 new degraded-metadata tests)python scripts/classify_problems.py --helpeslint .andprettier --check .clean (Python is outside both)One incidental diff
The editor stripped trailing whitespace from blank lines inside the Gemini prompt f-string. Whitespace-only, no semantic change to the prompt, and I could not reintroduce it through the editing tool.