Skip to content

feat: 표 및 그래프 그리기 구현 및 LLM 파이프라인 수정#1

Merged
AndyH0ng merged 12 commits intomainfrom
feat/table-and-graph
Mar 16, 2026
Merged

feat: 표 및 그래프 그리기 구현 및 LLM 파이프라인 수정#1
AndyH0ng merged 12 commits intomainfrom
feat/table-and-graph

Conversation

@AndyH0ng
Copy link
Owner

@AndyH0ng AndyH0ng commented Mar 16, 2026

변경 사항

PDF 전처리

  • testmagick preprocess 명령 추가 — LLM 파이프라인 연동을 위한 PDF 전처리
  • 처리 방식: auto(자동감지) / text(텍스트 추출) / images(이미지 압축) / mixed(페이지별 수식 감지) / markdown(marker-pdf)
  • 선택적 의존성으로 분리 (pyproject.toml: preprocess, markdown 그룹)

문제지/답지 디자인 개선

표(Table)

  • 표 첫 번째 행 자동 스타일 적용: #set table(fill: (x, y) => ...) 로 헤더 행 회색 배경 + 볼드 자동 처리
  • Answer Summary 표가 문제 수가 많을 때 잘리는 문제 수정

소문제 레이아웃

  • 소문제 ID((a), (b) 등)와 문제 내용이 같은 행에 인라인으로 표시되도록 변경 (#grid(columns: (auto, 1fr)))
  • 답지에서도 동일하게 ID · 해설 · 정답 레이블이 한 행에 표시

간격 조정

  • 대문제 → 소문제 간격 확대: 10pt16pt
  • 소문제 사이 간격 확대: 10pt16pt
  • 선택지와 소문제 문항 사이 간격 축소: 7pt4pt
  • 선택지 항목 간격 축소: 7pt5pt

수식 크기

  • 인라인 수식 크기 확대: #show math.equation.where(block: false): it => text(size: 12pt, it)

선택지 레이블

  • A, B, C… → ①②③… (원 안의 숫자)로 변경
  • 괄호 제거: (A)

@AndyH0ng AndyH0ng requested a review from Copilot March 16, 2026 01:16
@AndyH0ng AndyH0ng self-assigned this Mar 16, 2026
@AndyH0ng AndyH0ng changed the title feat: 표 및 그래프 그리기 구현 feat: 표 및 그래프 그리기 구현 및 LLM 파이프라인 수정 Mar 16, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds “advanced content” support to TestMagick by extending the YAML schema and Typst rendering pipeline to handle structured question blocks (tables/formulas/requirements/graphs) and multi-part (subproblem) questions.

Changes:

  • Extend the Pydantic schema with discriminated question_blocks and subproblems models (plus graph/table support).
  • Update renderer payload generation and Typst templates to render blocks and subproblems in exam/answer outputs.
  • Add new documentation and a sample YAML demonstrating advanced features; add uv.lock for dependency locking.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
uv.lock Adds a uv lockfile capturing resolved Python dependencies.
src/testmagick/templates/exam.typ.j2 Renders question_blocks and nested subproblems on the exam paper.
src/testmagick/templates/answer.typ.j2 Renders subproblem answers; adjusts answer header behavior.
src/testmagick/templates/_blocks.typ.j2 New macro to render structured blocks (table/formula/requirements/graph/etc.).
src/testmagick/schema.py Adds block/subproblem/graph/table schema models and validation logic.
src/testmagick/renderer.py Builds payloads for blocks and subproblems; adds graph bend control point calculation.
data/sample_advanced.yaml New sample input demonstrating tables, formulas, graphs, and subproblems.
CLAUDE.md New authoring guide documenting the advanced YAML features and usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

AndyH0ng and others added 6 commits March 16, 2026 12:15
함수 시그니처가 100자를 초과하는 3개 함수를 줄바꿈으로 분리.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- TableBlock: 빈 테이블 방지(headers/rows 최소 1개 필요) 및
  행마다 열 수 일치 검증 추가
- GraphNode: id에 min_length=1 및 공백 strip 검증 추가
- GraphEdge: from/to에 min_length=1 및 공백 strip 검증 추가
- Problem/SubProblem: MCQ 타입에서도 answer_typst 허용
  (선택지 번호는 유지하면서 해설을 Typst로 작성 가능)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- _blocks.typ.j2: edge label 필드를 실제 렌더링하도록 구현
  (직선은 from/to 중점, 곡선은 제어점 중점에 흰 배경 텍스트로 표시)
- answer.typ.j2: 사용하지 않는 render_blocks import 제거

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- test_schema.py: TableBlock(빈/열 불일치), GraphNode/GraphEdge(빈 id),
  GraphBlock(유효/유효하지 않은 edge 참조), MCQ+answer_typst 허용 검증
- test_renderer.py: question_blocks(formula/requirements/table),
  subproblems, graph edge 레이블 렌더링 검증 테스트 추가
- test_renderer.py: "Answer:" → "정답:" 변경에 맞게 기존 단언문 수정

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- preprocess 서브커맨드 사용법 및 의존성 설치 안내 추가
- 객관식 answer_typst 허용으로 변경된 내용 반영 (해설 작성 예시 포함)
- TableBlock 유효성 검사 제약 조건 문서화
- GraphNode id 제약(빈 문자열 불가) 안내 추가
- 그래프 edge label 렌더링 지원 명시

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Schema/renderer/template 확장을 통해 문제 본문에 구조화된 블록(수식/표/그래프 등)과 소문제(subproblems)를 지원하고, PDF를 LLM 입력용으로 전처리하는 preprocess CLI 서브커맨드를 추가합니다.

Changes:

  • question_blocks(formula/requirements/table/graph/typst/text) 및 subproblems를 스키마/렌더러/Typst 템플릿 전반에 추가
  • 정답지 템플릿을 소문제 출력 및 요약 테이블 레이아웃(10개 단위 배치)에 맞게 조정, 선택지 라벨을 ①②…로 변경
  • PDF 전처리 모듈(preprocess.py) + CLI 서브커맨드 + optional dependencies(extras) 추가, 고급 샘플/가이드 문서 추가

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/test_schema.py Table/Graph 제약 및 MCQ answer_typst 허용, 소문제 관련 스키마 테스트 추가
tests/test_renderer.py 블록/소문제/그래프 렌더링 및 정답지 문구 변경에 대한 테스트 추가/수정
src/testmagick/schema.py Content blocks + subproblems를 포함하도록 Pydantic 스키마 대폭 확장
src/testmagick/renderer.py 블록/그래프/소문제 payload 생성 및 MCQ 해설(answer_typst) 렌더링 지원
src/testmagick/templates/exam.typ.j2 question_blocks 렌더링 및 subproblems 출력 추가
src/testmagick/templates/answer.typ.j2 소문제 정답 출력, 답안 요약 테이블 10개 단위 배치 등 출력 형식 변경
src/testmagick/templates/_blocks.typ.j2 (신규) formula/requirements/table/graph 등 블록별 Typst 렌더링 매크로
src/testmagick/preprocess.py (신규) PDF 텍스트/이미지/마크다운 전처리 로직 및 스키마/프롬프트 출력 추가
src/testmagick/cli.py preprocess 서브커맨드 및 출력 포맷 추가
pyproject.toml optional-dependencies에 preprocess/markdown extras 추가
data/sample_advanced.yaml (신규) table/graph/subproblems 등 고급 기능 샘플 YAML 추가
CLAUDE.md (신규) LLM 작업 가이드/스키마 사용법 문서 추가

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


@dataclass
class PreprocessResult:
method: Literal["text", "images", "mixed"]
Copy link
Owner Author

Choose a reason for hiding this comment

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

✅ Fixed in commit e142f41

Comment on lines +438 to +441
auto : 텍스트 레이어 있으면 mixed, 없으면 images (기본값)
mixed : 페이지마다 수식 감지 → 수식 페이지는 이미지, 나머지는 텍스트
text : 모든 페이지 텍스트 추출 (강제)
images : 모든 페이지 이미지 압축 (강제)
Copy link
Owner Author

Choose a reason for hiding this comment

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

✅ Fixed in commit e142f41

Comment on lines +427 to +434
def preprocess_pdf(
pdf_path: Path,
out_dir: Path,
*,
method: Literal["auto", "mixed", "text", "images", "markdown"] = "auto",
dpi: int = 150,
quality: int = 72,
) -> PreprocessResult:
Copy link
Owner Author

Choose a reason for hiding this comment

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

preprocess 모듈은 실제 PDF 파일과 pymupdf/fitz 의존성이 필요해 순수 단위 테스트 구성이 까다롭습니다. 현재는 schema·renderer 레이어에 pytest 테스트를 집중하고, preprocess 경로는 실제 PDF 샘플을 사용하는 통합 테스트로 별도 추가하는 방향을 검토 중입니다. 우선순위가 낮아 이번 PR 범위에서는 제외하고 별도 이슈로 트래킹하겠습니다.

AndyH0ng and others added 4 commits March 16, 2026 12:33
LLM이 생성한 YAML의 누락 여부를 즉시 확인할 수 있도록
validate 결과에 문제 목록 테이블을 출력한다.
각 행에 문제 번호, ID, 배점, 소문제 수 및 소문제 ID 목록을 표시하며
하단에 총 문제 수·소문제 수·배점 합계를 요약한다.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
--expect "1:5,7:8" 형식으로 기대 소문제 수를 지정하면:
- 실제 소문제 수와 비교하여 누락 항목을 표시
- 현재 YAML 전문을 포함한 LLM 교정 프롬프트를 자동 생성
- 누락이 있으면 exit code 1 반환 (CI/스크립트 연동 가능)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- schema_ref.md에 question vs question_typst 선택 기준 섹션 추가
  (문장 중간 수식은 반드시 $...$로 감싸도록 ❌/✅ 예시 포함)
- 요청 프롬프트 규칙 강화: 인라인 수식 규칙 및 choices/answer 동일 적용
- Typst 수식 표에 eq.not 추가

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- PreprocessResult.method Literal에 "markdown" 추가
- preprocess_pdf docstring에 markdown 모드 설명 추가
- _render_page가 (w, h)를 반환하도록 변경 → _run_images/_run_mixed의
  이중 get_pixmap 호출 제거 (_pixel_dims 함수 삭제)
- _blocks.typ.j2: 그래프 노드/엣지 ID를 typst_string 필터로 이스케이프
- exam/answer.typ.j2: sub.id를 typst_string 필터로 이스케이프
- CLAUDE.md: graph pos 주석의 y축 방향 모순 수정 (위가 양수)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@AndyH0ng AndyH0ng merged commit 9860aae into main Mar 16, 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.

2 participants