Skip to content

scripts/polygon_pdf_companion.py: parse Polygon statement PDFs into Competitive Companion - #92

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1787716933-polygon-pdf-companion
Open

scripts/polygon_pdf_companion.py: parse Polygon statement PDFs into Competitive Companion#92
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1787716933-polygon-pdf-companion

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

scripts/polygon_pdf_companion.py (needs pip install pdfplumber): parses a Polygon/olymp.sty-generated statements PDF and POSTs each problem to Competitive Companion listeners on localhost (all default ports from CC's hosts.ts: cpbooster/Hightail/acmX/Caide/CP Editor/cph), so onsite/PDF-only contests plug into the same workflow as web parsing.

scripts/polygon_pdf_companion.py statements.pdf            # parse + POST
scripts/polygon_pdf_companion.py statements.pdf --dump     # print CC JSON
scripts/polygon_pdf_companion.py statements.pdf -p A -p C  # subset
scripts/polygon_pdf_companion.py statements.pdf --port 27121

Per problem it extracts name, TL/ML, input/output file (file-based IO becomes {"type": "file", ...}), interactivity, and sample tests, sharing one batch id per contest.

Sample extraction reads the ruled example tables via pdfplumber find_tables (with a generous intersection_tolerance — some PDFs draw rules with mismatched endpoints that otherwise split the table in half):

  • one table row per test, so run-twice problems get one test per run;
  • extra columns (explanation, Notes, ...) are ignored via header classification (classify_header picks input/output column indices by substring);
  • interactive problems and multi-input-column communication tables (Alice's Input | Alice's Output | Bob's Input | Bob's Output) are treated as transcripts: all rows interleave into a single test;
  • header-less continuation tables at a page top merge into the previous test;
  • templates without in-table headers (ICPC EC-Final, UCup Finals) fall back to bordered 2-column boxes under Sample Input N/Examples headings;
  • problem headers recognized: Problem A. Name, bare Problem A + title line, and A – Name (EUC).

Verified against 18 UCup/Petrozavodsk/ICPC statement PDFs (161 problems, all with non-empty samples except interactive problems with no example table) and end-to-end against a live localhost listener. Known gap: EUC-style PDFs whose samples are plain unruled text get name/limits only.

Link to Devin session: https://app.devin.ai/sessions/a55635671cc24f94a77a282da22946d1
Requested by: @ecnerwala


Devin Review (Beta)

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

Copy link
Copy Markdown

GCC Code Coverage Report

📂 Overall coverage

Metric Coverage
Lines 🟡 8852/10410 (85.0%)
Functions 🟢 1178/1283 (91.8%)
Branches 🟡 6699/8610 (77.8%)

@beta-devin-ai-integration beta-devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review (Beta)

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