Files
Pier_v1/RAG/design-model-box-sample_2/tools/generate_quantity_review.py
T
ahnyongjooandClaude Sonnet 5.5 964a841de1 chore(rebar): Pier_T_rebar 작업 폴더 초기 구성 및 외부 의존 파일 통합
- Code\rebar_pipeline, review_pipeline, pier-program을 정션에서 실제 폴더로 전환
- Code\rhino_mcp 및 CLAUDE_rhino배경.md 추가, .mcp.json은 PYTHONPATH로 새 위치 사용
- pier-program 내부 .git 제거(이력은 backup\pier-program_20261028.bundle에 보관)
- worktree 가이드 반영(CLAUDE.local.md, HANDOFF.md)
- D:\Rhino-MCP 경로 참조를 새 위치로 치환

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 11:20:18 +09:00

79 lines
5.0 KiB
Python

"""Generate and validate explicitly authorized current-source quantity rows."""
import argparse
import copy
import json
import os
from pathlib import Path
import subprocess
import sys
import tempfile
import time
root=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(root/'src/backend' if (root/'src/backend').is_dir() else root))
def run(args):
import server
from cad_rebar_recipe import load_sources
from authorized_quantity_generation import seeds, generate_seed
server.require_modeling_rules()
target=args.job.resolve();raw=target.read_bytes();job=json.loads(raw);plan=job['result']
from haunch_contact_surface import bind as bind_haunch_contact
bind_haunch_contact(plan['concrete_components'],server.component_surface_z_at_xy)
if job.get('status')=='running':raise ValueError('job is active')
if not args.confirm_quantity_distribution:raise ValueError('explicit confirmation required')
sources=load_sources(server.rehydrate_drawing_set_analysis(job['sourceContext']['analysis']))
authorization={'explicit_request':True,'source_sha256':sorted(sources),'marks':args.marks,
'scope':'source N on actual contact positions; not literal drawing station reconstruction'}
if args.rhythm:
repeat,alternate=args.rhythm
if not 0<alternate<repeat:raise ValueError('invalid repeat/alternate cycle rule')
authorization['cycle_rhythm']={'explicit_request':True,'authority':'user_confirmed_cycle_rhythm',
'repeat_cycle_steps':repeat,'alternate_cycle_steps':alternate,'scope':'rhythm only; current source dimensions and cycle stations'}
failures=[];groups=[]
source_seeds=seeds(plan,sources,authorization,failures=failures)
if args.seed_output:
with args.seed_output.open('x') as stream:json.dump({'authorization':authorization,'seeds':source_seeds},stream,ensure_ascii=False)
for seed in source_seeds:
if args.block and seed['rebar_block']!=args.block:continue
report={'block':seed['rebar_block'],'mark':seed['mark'],'count':seed['schedule_count']}
try:
g=generate_seed(plan,seed,node=args.node)
report['target']=g['quantity_distribution'].get('target_kind','longitudinal')
groups.append(g);report['pass']=True
except (ValueError,subprocess.CalledProcessError) as error:
report.update(error=str(error),pass_=False);failures.append(report)
print(json.dumps(report,ensure_ascii=False),flush=True)
print(json.dumps({'generated_groups':len(groups),'failures':failures},ensure_ascii=False),flush=True)
result=copy.deepcopy(plan);ids={g['id'] for g in groups}
result['rebar_groups']=[g for g in result['rebar_groups'] if g.get('id') not in ids]+groups
result['drawingEvidence']['quantity_distribution_authorization']=authorization
result['drawingEvidence'].setdefault('preview_geometry',{})['rebar_groups']=copy.deepcopy(result['rebar_groups'])
result['quantityDistributionReview']={'failures':failures,'group_ids':sorted(ids),'engineering_approved':False}
result['ready_for_geometry']=False;result['workflowStage']='rebar'
output={'result':result,'failures':failures,'authorization':authorization}
if args.output:
with args.output.open('x') as stream:json.dump(output,stream,ensure_ascii=False,allow_nan=False)
if args.apply:
if target.read_bytes()!=raw:raise ValueError('concurrent job update')
backup=target.with_name(target.stem+f'.before-authorized-quantity-{time.time_ns()}.json')
with backup.open('xb') as stream:stream.write(raw)
job.update(result=result,partialResult={'progressivePlan':copy.deepcopy(result),'drawingEvidence':copy.deepcopy(result['drawingEvidence'])},
geometryRevision=time.time_ns(),status='awaiting_feedback',stage='수량 기준 분배 검토 · 전체 검증 미완료')
with tempfile.NamedTemporaryFile(mode='w',dir=target.parent,delete=False) as stream:
json.dump(job,stream,ensure_ascii=False,allow_nan=False);temporary=stream.name
if target.read_bytes()!=raw:raise ValueError('concurrent update before publish')
os.replace(temporary,target)
print(json.dumps({'saved':True,'groups':len(result['rebar_groups']),'backup':str(backup)}),flush=True)
if __name__=='__main__':
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('job',type=Path);parser.add_argument('--marks',nargs='+',required=True)
parser.add_argument('--node',required=True);parser.add_argument('--confirm-quantity-distribution',action='store_true')
parser.add_argument('--output',type=Path);parser.add_argument('--apply',action='store_true')
parser.add_argument('--block',help='Optional physical block scope, e.g. BLOCK1')
parser.add_argument('--seed-output',type=Path,help='Write current-CAD seed evidence for reproducible diagnostics')
parser.add_argument('--rhythm',nargs=2,type=int,metavar=('REPEAT','ALTERNATE'),help='Explicitly authorized cycle-step rhythm')
run(parser.parse_args())