# -*- coding: utf-8 -*- """시험 도움 — 예정노선 설계 내용(파일 꼴 · PLAN 590-1)을 메모리로 꽂음.""" from __future__ import annotations from pathlib import Path from typing import Any from D03_PlanAnalysis import D03_PlanAnalysis_Network as network from D03_PlanAnalysis import D03_PlanAnalysis_Store as store def plan_of(lines: list, marks: list, pieces: list, epsg: int = 5186, points=()) -> dict: return { **store.empty_plan(epsg), "points": list(points), "lines": lines, "marks": marks, "pieces": pieces, } def use_plan(monkeypatch: Any, plan: dict, confirmed: dict | None = None) -> dict: """`store.load_plan` · `store.year_status` 를 갈아 끼움 — `confirmed` = {연도: 확정 시각} (지문은 파일과 같게) · 돌려준 dict 의 plan · confirmed 를 고치면 다음 읽기에 반영.""" state = {"plan": plan, "confirmed": dict(confirmed or {})} async def load(_pid): return Path("."), state["plan"] async def status(_pid): years = network.year_rows(store.plan_units(state["plan"])) return { y: {"fingerprint": years[y]["fingerprint"], "confirmed_at": at} for y, at in state["confirmed"].items() if y in years } monkeypatch.setattr(store, "load_plan", load) monkeypatch.setattr(store, "year_status", status) return state def year_line_plan(parts: dict[int, list]) -> dict: """본선 하나 = 연도 꺾은선 이음(앞 끝 = 뒤 시작) · 연도 경계 마크 · 조각 `p26` · `p27` …""" vertices: list = [] pieces = [] for year, points in sorted(parts.items()): start = network.draw.line_length(vertices) vertices += [list(p) for p in (points[1:] if vertices else points)] end = network.draw.line_length(vertices) pieces.append( {"id": f"p{year % 100}", "line": "main", "from_m": start, "to_m": end, "year": year} ) marks = [{"line": "main", "at_m": p["to_m"]} for p in pieces[:-1]] return plan_of([{"id": "main", "vertices": vertices, "branch": None}], marks, pieces)