- 암 시공법(ripping/blasting)을 갈래 비율 칸 아래에 붙임. 갈래 이름만으로는 품셈 공종(암절취 FP-09-04 / 발파암 FP-09-05)을 못 고르던 자리. 기본은 「안 정함」이고, 안 정하면 인계에서 사유와 함께 드러남. 비율 미입력 상태의 「암」 한 줄에도 칸을 냄. - 관급/사급은 표 안에서 줄마다 고름. 관급 줄에만 설치주체가 열리고 사급으로 되돌리면 잠기며 비워짐. 만진 줄은 표시가 남음. - 산출 요약(최소·중앙·최대)을 원단위·자재총괄·인계에 붙임. 단위별로 갈라 냄 — 값이 있기만 하면 시험이 못 잡는 자릿수 어긋남을 사람이 훑게 하는 장치. 화면에서 걸려 고친 것 둘 - 관급을 골라도 설치주체 칸이 잠긴 채 남던 것. 고른 즉시 열고 닫게 함. - 한 번 고른 시공법을 되돌릴 길이 없던 것. 설정 저장이 병합이라 빈 값을 보내도 옛 값이 남았음. `save_section(replace_keys=…)` 로 되돌릴 수 있어야 하는 칸만 통째로 갈아 끼움. 나머지는 그대로 병합. 앞 커밋에서 온 타입 오류 2건도 고침 (`slopeColumnCount` 미사용, `variant: "outlined"` 는 없는 값). 앞선 확인에서 npx 가 엉뚱한 패키지를 실행해 「오류 없음」으로 잘못 봤음 — tsc 는 config/node_modules 것으로 부를 것. 검증 — 새 시험 5건 + 인계 28건 통과, 전체 509 passed. tsc 오류 0. 화면 실조작으로 시공법 저장·되돌리기, 관급/설치주체 저장·되돌리기 확인 후 검증으로 바꾼 값은 원래대로 복원. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
198 lines
8.9 KiB
Python
198 lines
8.9 KiB
Python
"""B08 토적표 조회 라우터 (일감 2 · PLAN 8-4b).
|
|
|
|
값은 어디서 오나
|
|
측점별 단면적은 **B06 이 이미 낸 정본**이다(`cross_sections.data.design` 의
|
|
`cut_soil_area_m2`·`cut_rock_area_m2`·`fill_area_m2`·`ditch_area_m2`).
|
|
B08 은 그것을 다시 재지 않고 **평균단면적법으로 체적화만** 한다.
|
|
|
|
계산 자리 (CLAUDE.md 5장)
|
|
초기값은 서버가 한 번 계산해 영구저장한다. 여기서는 저장된 단면적을 읽어 표를 만든다 —
|
|
새 수량을 낳지 않으므로 캐시·조작 경로가 따로 필요 없다.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import logging
|
|
from typing import Any
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter
|
|
from fastapi.responses import JSONResponse
|
|
from pydantic import BaseModel
|
|
|
|
from B03_FileInput.B03_FileInput_Repository import get_project_storage_relative_path
|
|
from B06_Section.B06_Section_Repository import (
|
|
get_cross_section_designs,
|
|
get_longitudinal_section,
|
|
get_workflow_route_context,
|
|
)
|
|
from B08_Quantity.B08_Quantity_Engine_EarthworkSummary import SummaryInput
|
|
from B08_Quantity.B08_Quantity_Engine_EarthworkSummary import build_table as build_summary_table
|
|
from B08_Quantity.B08_Quantity_Engine_EarthworkTable import StationArea, build_table
|
|
from B08_Quantity.B08_Quantity_Engine_HaulSummary import build_table as build_haul_table
|
|
from B08_Quantity.B08_Quantity_Engine_HaulSummary import summary_input_rows
|
|
from B08_Quantity.B08_Quantity_Engine_SlopeArea import build_table as build_slope_table
|
|
from B08_Quantity.B08_Quantity_Engine_SlopeLength import station_slopes
|
|
from common_util.common_util_project_settings import (
|
|
ROCK_METHODS,
|
|
application_ratio,
|
|
quantity_settings,
|
|
rock_classes,
|
|
save_section,
|
|
)
|
|
from common_util.common_util_storage import resolve_stored_project_path
|
|
from config.config_db import run_with_connection
|
|
|
|
logger = logging.getLogger(__name__)
|
|
router = APIRouter(prefix="/api/projects", tags=["B08 Quantity"])
|
|
|
|
|
|
def _stations(designs: list[dict[str, Any]]) -> list[StationArea]:
|
|
return [
|
|
StationArea.from_design(item["chainage_m"], item.get("design") or {}) for item in designs
|
|
]
|
|
|
|
|
|
@router.get("/{project_id}/quantity/{route_id}/earthwork-table")
|
|
async def get_earthwork_table(project_id: UUID, route_id: int) -> JSONResponse:
|
|
"""토적표 — 토공(체적)과 사면 4계열(면적)을 **한 응답**으로 낸다.
|
|
|
|
실무 토적표가 한 장이라 화면도 한 장이다. 나눠 부르면 두 번 왕복하고, 같은 측점 목록을
|
|
두 벌로 들게 된다.
|
|
"""
|
|
try:
|
|
designs = await run_with_connection(get_cross_section_designs, route_id)
|
|
except Exception:
|
|
logger.exception("B08 토적표 조회 실패: project_id=%s route_id=%s", project_id, route_id)
|
|
return JSONResponse(
|
|
status_code=500,
|
|
content={"status": "error", "message": "토적표를 만들지 못했습니다."},
|
|
)
|
|
table = build_table(_stations(designs))
|
|
# 사면 계열은 저장된 설계선에서 유도한다.
|
|
slope = build_slope_table(station_slopes(designs))
|
|
table["slope"] = slope
|
|
|
|
settings, project_root = await _project_settings(project_id)
|
|
plan = await _stored_haul_plan(project_id, route_id)
|
|
haul = build_haul_table(plan)
|
|
table["haul"] = haul
|
|
# 운반계획은 [저장]·[확정]에서 정본에 남는 값이다 — 아직 없으면 빈 표가 정직하다.
|
|
table["haul_available"] = bool(plan)
|
|
|
|
table["summary"] = build_summary_table(
|
|
SummaryInput(
|
|
earthwork_totals=table.get("totals") or {},
|
|
slope_totals=slope.get("totals") or {},
|
|
haul_rows=summary_input_rows(haul),
|
|
rock_classes=rock_classes(settings),
|
|
rock_ratios_pct=settings.get("rock_ratios_pct") or {},
|
|
application_ratios={
|
|
key: application_ratio(settings, key)
|
|
for key in (settings.get("application_ratios_pct") or {})
|
|
},
|
|
)
|
|
)
|
|
table["settings"] = settings
|
|
table["project_root_known"] = project_root is not None
|
|
table["route_id"] = route_id
|
|
return JSONResponse(content=table)
|
|
|
|
|
|
async def _project_settings(project_id: UUID) -> tuple[dict[str, Any], str | None]:
|
|
"""프로젝트 설정을 읽는다. 경로를 못 찾아도 기본값으로 화면은 선다."""
|
|
try:
|
|
stored_path = await run_with_connection(get_project_storage_relative_path, project_id)
|
|
root = resolve_stored_project_path(stored_path)
|
|
except Exception:
|
|
logger.warning("B08 프로젝트 경로를 못 찾음: project_id=%s", project_id)
|
|
from common_util.common_util_project_settings import default_settings
|
|
|
|
return default_settings()["quantity"], None
|
|
return quantity_settings(root), root
|
|
|
|
|
|
async def _stored_haul_plan(project_id: UUID, route_id: int) -> dict[str, Any] | None:
|
|
"""정본에 남은 운반계획. [확정]을 아직 안 돌렸으면 없다."""
|
|
try:
|
|
row = await run_with_connection(get_longitudinal_section, project_id, route_id)
|
|
except Exception:
|
|
logger.exception("B08 운반계획 조회 실패: route_id=%s", route_id)
|
|
return None
|
|
data = (row or {}).get("data") or {}
|
|
plan = data.get("mass_haul") if isinstance(data, dict) else None
|
|
return plan if isinstance(plan, dict) and plan else None
|
|
|
|
|
|
class QuantitySettingsBody(BaseModel):
|
|
"""[저장]이 보내는 산출 조건. 보내지 않은 칸은 저장분을 그대로 둔다."""
|
|
|
|
rock_class_set: str | None = None
|
|
rock_classes: list[str] | None = None
|
|
rock_ratios_pct: dict[str, float] | None = None
|
|
# 갈래별 시공법 — 값은 "ripping"·"blasting". 안 정한 갈래는 보내지 않는다.
|
|
rock_methods: dict[str, str] | None = None
|
|
application_ratios_pct: dict[str, float] | None = None
|
|
# 자재별 관급/사급 — `{자재명: {"supply": …, "install_by": …}}`.
|
|
# 표 안에서 줄마다 고른 값이 여기로 온다(2026-09-07 확정).
|
|
material_supply: dict[str, Any] | None = None
|
|
|
|
|
|
@router.put("/{project_id}/quantity/settings")
|
|
async def save_quantity_settings(project_id: UUID, body: QuantitySettingsBody) -> JSONResponse:
|
|
"""산출 조건을 정본에 남긴다 — [저장]이 부르는 자리.
|
|
|
|
⚠ 자동저장이 아니다(CLAUDE.md 5장). 조작은 캐시에 쌓이고 여기서만 작업본으로 넘어간다.
|
|
⚠ `quantity` 구획만 쓴다 — `estimation` 은 B09 것이라 손대지 않는다(모듈이 막고 있다).
|
|
"""
|
|
try:
|
|
stored_path = await run_with_connection(get_project_storage_relative_path, project_id)
|
|
root = resolve_stored_project_path(stored_path)
|
|
except Exception:
|
|
logger.exception("B08 설정 저장 실패(경로): project_id=%s", project_id)
|
|
return JSONResponse(
|
|
status_code=404,
|
|
content={"status": "error", "message": "프로젝트 저장 폴더를 찾지 못했습니다."},
|
|
)
|
|
values = {key: value for key, value in body.model_dump().items() if value is not None}
|
|
if "rock_methods" in values:
|
|
# 「안 정함」(빈 값)은 저장하지 않는다 — 정한 것과 구별이 안 된다. 통째로 갈아 끼우므로
|
|
# 여기서 버리면 그 갈래는 미지정으로 돌아간다.
|
|
values["rock_methods"] = {
|
|
name: method
|
|
for name, method in values["rock_methods"].items()
|
|
if method in ROCK_METHODS
|
|
}
|
|
try:
|
|
# ⚠ 고른 값을 **되돌릴 수 있어야** 하는 칸은 통째로 갈아 끼운다 — 병합이면
|
|
# 「안 정함」으로 되돌아가지 않는다(2026-09-07 화면에서 걸린 자리).
|
|
saved = await asyncio.to_thread(
|
|
_save_quantity, root, values, ("rock_methods", "material_supply")
|
|
)
|
|
except Exception:
|
|
logger.exception("B08 설정 저장 실패(쓰기): project_id=%s", project_id)
|
|
return JSONResponse(
|
|
status_code=500,
|
|
content={"status": "error", "message": "산출 조건을 저장하지 못했습니다."},
|
|
)
|
|
return JSONResponse(content={"status": "success", "quantity": saved.get("quantity") or {}})
|
|
|
|
|
|
def _save_quantity(
|
|
root: str, values: dict[str, Any], replace_keys: tuple[str, ...]
|
|
) -> dict[str, Any]:
|
|
return save_section(root, "quantity", values, replace_keys=replace_keys)
|
|
|
|
|
|
@router.get("/{project_id}/quantity/earthwork-table")
|
|
async def get_earthwork_table_for_current_route(project_id: UUID) -> JSONResponse:
|
|
"""경로를 안 주면 워크플로가 보고 있는 경로로 낸다 — 화면이 route_id 를 모를 때 쓴다."""
|
|
context = await run_with_connection(get_workflow_route_context, project_id)
|
|
if not context or not context.get("route_id"):
|
|
return JSONResponse(
|
|
status_code=404,
|
|
content={"status": "error", "message": "이 프로젝트에 확정된 노선이 없습니다."},
|
|
)
|
|
return await get_earthwork_table(project_id, int(context["route_id"]))
|